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)
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
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
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()
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}