]> www.vanbest.org Git - motioneye-debian/commitdiff
added a management command to recreate thumbnails
authorCalin Crisan <ccrisan@gmail.com>
Sun, 17 Nov 2013 12:19:49 +0000 (14:19 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 17 Nov 2013 12:19:49 +0000 (14:19 +0200)
doc/todo.txt
motioneye.py
src/mediafiles.py

index 9049bfdc9e450da31b6adf7d3cf64a5a1e3aa406..7abc86df2bccb013008ad4edfa0416bfad418461 100644 (file)
@@ -1,4 +1,3 @@
--> add a mgmt command for generating thumbnails
 -> make camera frames positions configurable
 -> add a view log functionality
 
index ab54ab5b74683d687c2bc6399350ab0df9c17890..ad5eb9bd112fa32d1d2bd5b66a3ba22016b15f30 100755 (executable)
@@ -110,9 +110,7 @@ def _configure_settings():
             setattr(settings, name, next_arg)
         
         else:
-            print('unknown command line option: ' + arg)
-            _print_help()
-            sys.exit(-1)
+            return arg[2:]
     
     try:
         os.makedirs(settings.CONF_PATH)
@@ -131,7 +129,10 @@ def _print_help():
     print('Usage: ' + sys.argv[0] + ' [option1 value1] ...')
     print('available options: ')
     
-    for (name, value) in sorted(inspect.getmembers(settings)):  # @UnusedVariable
+    options = list(inspect.getmembers(settings))
+    options.append(('THUMBNAILS', None))
+    
+    for (name, value) in sorted(options):
         if name.upper() != name:
             continue
         
@@ -139,10 +140,38 @@ def _print_help():
             continue
         
         name = '--' + name.lower().replace('_', '-')
-        print('    ' + name)
+        if value is not None:
+            value = type(value).__name__
+        
+        line = '    ' + name
+        if value:
+            line += ' <' + value + '>'
+        print(line)
     
     print('')
+
+
+def _do_thumbnails():
+    import config
+    import mediafiles
+    
+    logging.info('recreating thumbnails for all video files...')
+    
+    for camera_id in config.get_camera_ids():
+        camera_config = config.get_camera(camera_id)
+        if camera_config.get('@proto') != 'v4l2':
+            continue
+        
+        logging.info('listing movie files for camera %(name)s' % {
+                'name': camera_config['@name']})
+        
+        target_dir = camera_config['target_dir']
+        
+        for full_path in mediafiles._list_media_files(target_dir, mediafiles._MOVIE_EXTS):
+            mediafiles.make_movie_preview(camera_config, full_path)
     
+    logging.info('done.')
+
 
 def _start_server():
     import server
@@ -221,10 +250,20 @@ def _start_movie_thumbnailer():
 
 
 if __name__ == '__main__':
-    _configure_settings()
+    cmd = _configure_settings()
     _configure_signals()
     _configure_logging()
     
+    if cmd:
+        if cmd == 'thumbnails':
+            _do_thumbnails()
+        
+        else:
+            print('unknown command line option: ' + cmd)
+            sys.exit(-1)
+        
+        sys.exit(0)
+    
     _start_motion()
     _start_cleanup()
     _start_movie_thumbnailer()
index cb6a7ed974723eca9b6b1e8481c9d33be4a81092..d5d73ffc14937b7f0d47297c74963bd0a49e6474 100644 (file)
@@ -109,13 +109,13 @@ def cleanup_media(media_type):
 
 
 def make_movie_preview(camera_config, full_path):
-    logging.debug('creating movie preview for %(path)s...' % {'path': full_path})
-    
     framerate = camera_config['framerate']
     pre_capture = camera_config['pre_capture']
     offs = pre_capture / framerate
-    offs = min(4, offs * 2)
+    offs = max(4, offs * 2)
     
+    logging.debug('creating movie preview for %(path)s with an offset of %(offs)s seconds ...' % {
+            'path': full_path, 'offs': offs})
 
     cmd = 'ffmpeg -i "%(path)s" -f mjpeg -vframes 1 -ss %(offs)s -y %(path)s.thumb' % {
             'path': full_path, 'offs': offs}