From: Calin Crisan Date: Sat, 19 Oct 2013 11:01:09 +0000 (+0300) Subject: properly implemented movie quality through ffmpeg_bps X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=6671e171d6008716d4ff4f58e78e2b8532a2586f;p=motioneye-debian properly implemented movie quality through ffmpeg_bps --- diff --git a/doc/motion-options.txt b/doc/motion-options.txt index 666f91a..ace3d83 100644 --- a/doc/motion-options.txt +++ b/doc/motion-options.txt @@ -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 diff --git a/doc/todo.txt b/doc/todo.txt index 13f1dc4..7924432 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -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 diff --git a/motioneye.py b/motioneye.py index 381d124..f9577d5 100755 --- a/motioneye.py +++ b/motioneye.py @@ -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() diff --git a/src/config.py b/src/config.py index 48bbd3e..9d7b45b 100644 --- a/src/config.py +++ b/src/config.py @@ -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) diff --git a/src/handlers.py b/src/handlers.py index 41ef735..501cf98 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -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: