From 5036b2f8f3df0521959cbbf97071d84e051bcdc7 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 16 Nov 2013 19:33:56 +0200 Subject: [PATCH] added automatic background movie thumbnailer mechanism --- motioneye.py | 21 +++++++++++++++++++++ src/mediafiles.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/motioneye.py b/motioneye.py index 9a89434..45f9f77 100755 --- a/motioneye.py +++ b/motioneye.py @@ -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() diff --git a/src/mediafiles.py b/src/mediafiles.py index 5186370..1119165 100644 --- a/src/mediafiles.py +++ b/src/mediafiles.py @@ -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') -- 2.39.5