]> www.vanbest.org Git - motioneye-debian/commitdiff
added automatic background movie thumbnailer mechanism
authorCalin Crisan <ccrisan@gmail.com>
Sat, 16 Nov 2013 17:33:56 +0000 (19:33 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 16 Nov 2013 17:33:56 +0000 (19:33 +0200)
motioneye.py
src/mediafiles.py

index 9a89434d4cd144b4e3f20df449c947f49bd6b4b2..45f9f77ca0025e4aece39cb8a6dabfdebd3c75b0 100755 (executable)
@@ -198,6 +198,26 @@ def _start_cleanup():
     do_cleanup()
 
 
+def _start_movie_thumbnailer():
+    import mediafiles
+
+    def do_next_movie_thumbail():
+        ioloop = tornado.ioloop.IOLoop.instance()
+        if ioloop._stopped:
+            return
+        
+        try:
+            mediafiles.make_next_movie_preview()
+            
+        except Exception as e:
+            logging.error('failed to make movie thumbnail: %(msg)s' % {
+                    'msg': unicode(e)})
+
+        ioloop.add_timeout(datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), do_next_movie_thumbail)
+
+    do_next_movie_thumbail()
+
+
 if __name__ == '__main__':
     _configure_settings()
     _configure_signals()
@@ -205,4 +225,5 @@ if __name__ == '__main__':
     
     _start_motion()
     _start_cleanup()
+    _start_movie_thumbnailer()
     _start_server()
index 518637025651bc4efd280e485fee085bb2a9bfe9..111916586ecbbdd2491e7880ea8c066eb7550cd4 100644 (file)
@@ -95,7 +95,7 @@ def make_movie_preview(camera_config, full_path):
             'path': full_path, 'offs': offs}
     
     try:
-        subprocess.check_call(cmd, shell=True)
+        subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
     
     except subprocess.CalledProcessError as e:
         logging.error('failed to create movie preview for %(path)s: %(msg)s' % {
@@ -106,6 +106,33 @@ def make_movie_preview(camera_config, full_path):
     return full_path + '.thumb'
 
 
+def make_next_movie_preview():
+    logging.debug('making preview for the next movie...')
+    
+    for camera_id in config.get_camera_ids():
+        camera_config = config.get_camera(camera_id)
+        if camera_config.get('@proto') != 'v4l2':
+            continue
+        
+        target_dir = camera_config['target_dir']
+        
+        for full_path in _list_media_files(target_dir, _MOVIE_EXTS):
+            # TODO files listed here may not belong to the given camera
+        
+            if os.path.exists(full_path + '.thumb'):
+                continue
+            
+            logging.debug('found a movie without preview: %(path)s' % {
+                    'path': full_path})
+                
+            make_movie_preview(camera_config, full_path)
+            
+            break
+        
+        else:
+            logging.debug('all movies have preview')
+            
+
 def list_media(camera_config, media_type):
     target_dir = camera_config.get('target_dir')