]> www.vanbest.org Git - motioneye-debian/commitdiff
properly implemented movie quality through ffmpeg_bps
authorCalin Crisan <ccrisan@gmail.com>
Sat, 19 Oct 2013 11:01:09 +0000 (14:01 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 19 Oct 2013 11:02:13 +0000 (14:02 +0300)
doc/motion-options.txt
doc/todo.txt
motioneye.py
src/config.py
src/handlers.py

index 666f91a32924099952974187769b5cbce1ff6cda..ace3d830ba7ce973e233f137e36b9c9302b47f16 100644 (file)
@@ -45,6 +45,7 @@ Motion Movies
 ffmpeg_cap_new              boolean
 movie_filename              string
 ffmpeg_variable_bitrate     0, 2..31
+ffmpeg_bps                  0 - 9999999
 ffmpeg_video_codec          mpeg4, msmpeg4, swf, flv, ffv1, mov
 
 Motion Detection
index 13f1dc4e8ea31e2d5fe33e9538a2860f2f715e99..79244325691223fa6b242dc07c41b93fb28313bf 100644 (file)
@@ -1,6 +1,5 @@
--> gunoiul de ffmpeg_variable_bitrate nu merge decat in motion.conf
+-> add/remove camera: apply button still there
 
--> brightness/contrast/hue/sat on picam1 issue when applying
 -> http clients don't die: max_clients limit reached, request queued. 10 active, 217 queued requests. 
 -> remote adding ui could be improved (cleanup fields on ok/on load, no error message until everything is ok)
 
@@ -17,6 +16,7 @@
 -> add a previewer for snapshots
 -> add a motioneye.svg icon
 
+-> implement working schedule (add another combo deciding what to do during working schedule)
 -> add other options applicable only to special devices (rpi): wifi settings, notifications
 -> group @config rules to top
 
index 381d124a7207946b8ee6583ad96004dfb8188b1f..f9577d557bf3515ef1f179b6602412f7c6257a59 100755 (executable)
@@ -142,12 +142,17 @@ def _start_motion():
     # add a motion running checker
     def checker():
         ioloop = tornado.ioloop.IOLoop.instance()
-        if not ioloop.running(): # just stopped
+        if ioloop._stopped:
             return
-        
+            
         if not motionctl.running() and config.has_enabled_cameras():
-            motionctl.start()
-            logging.info('motion started')
+            try:
+                motionctl.start()
+                logging.info('motion started')
+            
+            except Exception as e:
+                logging.error('failed to start motion: %(msg)s' % {
+                        'msg': unicode(e)})
 
         ioloop.add_timeout(datetime.timedelta(seconds=settings.MOTION_CHECK_INTERVAL), checker)
     
@@ -159,9 +164,9 @@ def _start_cleanup():
 
     def do_cleanup():
         ioloop = tornado.ioloop.IOLoop.instance()
-        if not ioloop.running(): # just stopped
+        if ioloop._stopped:
             return
-
+        
         try:
             cleanup.cleanup_images()
             cleanup.cleanup_movies()
index 48bbd3e96afe450a8910b684f114fb3677e2b335..9d7b45b65122e2f543ae9c81efc025fa0f1bbf7b 100644 (file)
@@ -308,8 +308,9 @@ def add_camera(device_details):
         if 'width' in device_details:
             data['width'] = device_details['width']
             data['height'] = device_details['height']
+            data['ffmpeg_bps'] = device_details['ffmpeg_bps']
         
-    else:
+    else: # remote
         data['@host'] = device_details['host']
         data['@port'] = device_details['port']
         data['@username'] = device_details['username']
@@ -573,7 +574,8 @@ def _set_default_motion_camera(data):
     data.setdefault('quality', 75)
     data.setdefault('@preserve_images', 0)
     
-    data.setdefault('ffmpeg_variable_bitrate', 14)
+    data.setdefault('ffmpeg_variable_bitrate', 0)
+    data.setdefault('ffmpeg_bps', 400000)
     data.setdefault('movie_filename', '%Y-%m-%d-%H-%M-%S')
     data.setdefault('ffmpeg_cap_new', False)
     data.setdefault('@preserve_movies', 0)
index 41ef735e07c68bec5adb4d3104deb5f98f878009..501cf98c3d749914d2792bfa1d53a80ba69b6e7b 100644 (file)
@@ -420,6 +420,13 @@ class ConfigHandler(BaseHandler):
                 if w > 300:
                     device_details['width'] = w
                     device_details['height'] = h
+                    # compute the ffmpeg bps
+                    
+                    max_val = w * h * 2 / 3
+                    max_val = min(max_val, 9999999)
+                    val = max_val * 75 / 100
+                    device_details['ffmpeg_bps'] = val
+
                     break
 
         camera_id, camera_config = config.add_camera(device_details)
@@ -533,7 +540,6 @@ class ConfigHandler(BaseHandler):
             '@preserve_images': int(ui.get('preserve_images', 0)),
             
             # movies
-            'ffmpeg_variable_bitrate': 2 + int((100 - int(ui.get('movie_quality', 75))) * 0.29),
             'ffmpeg_cap_new': ui.get('motion_movies', False),
             'movie_filename': ui.get('movie_file_name', '%Y-%m-%d-%H-%M-%S-%q'),
             '@preserve_movies': int(ui.get('preserve_movies', 0)),
@@ -627,7 +633,13 @@ class ConfigHandler(BaseHandler):
                 data['jpeg_filename'] = ui.get('image_file_name', '%Y-%m-%d-%H-%M-%S')
                 
             data['quality'] = max(1, int(ui.get('image_quality', 75)))
+        
+        if ui.get('motion_movies'):
+            max_val = data['width'] * data['height'] * data['framerate'] / 3
+            max_val = min(max_val, 9999999)
             
+            data['ffmpeg_bps'] = int(ui.get('movie_quality', 75)) * max_val / 100
+
         if ui.get('working_schedule', False):
             data['@working_schedule'] = (
                     ui.get('monday_from', '') + '-' + ui.get('monday_to') + '|' + 
@@ -697,7 +709,6 @@ class ConfigHandler(BaseHandler):
             
             # motion movies
             'motion_movies': data.get('ffmpeg_cap_new'),
-            'movie_quality': int((max(2, data.get('ffmpeg_variable_bitrate')) - 2) / 0.29),
             'movie_file_name': data.get('movie_filename'),
             'preserve_movies': data['@preserve_movies'],
 
@@ -821,6 +832,13 @@ class ConfigHandler(BaseHandler):
                 ui['image_file_name'] = jpeg_filename  
                 
             ui['image_quality'] = ui.get('quality', 75)
+
+        ffmpeg_bps = data.get('ffmpeg_bps')
+        if ffmpeg_bps is not None: 
+            max_val = data['width'] * data['height'] * data['framerate'] / 3
+            max_val = min(max_val, 9999999)
+            
+            ui['movie_quality'] = min(100, int(round(ffmpeg_bps * 100.0 / max_val))) 
         
         working_schedule = data.get('@working_schedule')
         if working_schedule: