From: Calin Crisan Date: Sun, 27 Aug 2017 14:06:40 +0000 (+0300) Subject: add support for RPi OMX hw accel codec X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=1744cfaffc7ef9800226f5ee86270cd7ee31277d;p=motioneye-debian add support for RPi OMX hw accel codec --- diff --git a/motioneye/config.py b/motioneye/config.py index b87fe8d..acdd637 100644 --- a/motioneye/config.py +++ b/motioneye/config.py @@ -1999,7 +1999,12 @@ def _set_default_motion_camera(camera_id, data): data.setdefault('max_movie_time', 0) data.setdefault('ffmpeg_output_movies', False) if motionctl.has_new_movie_format_support(): - data.setdefault('ffmpeg_video_codec', 'mp4') # will use h264 codec + if motionctl.has_h264_omx_support(): + data.setdefault('ffmpeg_video_codec', 'mp4:h264_omx') # will use h264 codec + + else: + data.setdefault('ffmpeg_video_codec', 'mp4') # will use h264 codec + if motionctl.needs_ffvb_quirks(): data.setdefault('ffmpeg_variable_bitrate', _MAX_FFMPEG_VARIABLE_BITRATE / 4) # 75% diff --git a/motioneye/handlers.py b/motioneye/handlers.py index c25a2ff..ff91c31 100644 --- a/motioneye/handlers.py +++ b/motioneye/handlers.py @@ -246,6 +246,7 @@ class MainHandler(BaseHandler): admin_username=config.get_main().get('@admin_username'), has_streaming_auth=motionctl.has_streaming_auth(), has_new_movie_format_support=motionctl.has_new_movie_format_support(), + has_h264_omx_support=motionctl.has_h264_omx_support(), has_motion=bool(motionctl.find_motion()[0]), mask_width=utils.MASK_WIDTH) diff --git a/motioneye/mediafiles.py b/motioneye/mediafiles.py index 29e27a4..274fb5c 100644 --- a/motioneye/mediafiles.py +++ b/motioneye/mediafiles.py @@ -51,6 +51,8 @@ FFMPEG_CODEC_MAPPING = { 'mov': 'mpeg4', 'mp4': 'h264', 'mkv': 'h264', + 'mp4:h264_omx': 'h264_omx', + 'mkv:h264_omx': 'h264_omx', 'hevc': 'h265' } @@ -82,6 +84,8 @@ _prepared_files = {} _timelapse_process = None _timelapse_data = None +_ffmpeg_binary_cache = None + def findfiles(path): files = [] @@ -190,11 +194,45 @@ def _remove_older_files(directory, moment, exts): def find_ffmpeg(): + global _ffmpeg_binary_cache + if _ffmpeg_binary_cache: + return _ffmpeg_binary_cache + + # binary try: - return subprocess.check_output(['which', 'ffmpeg'], stderr=utils.DEV_NULL).strip() + binary = subprocess.check_output(['which', 'ffmpeg'], stderr=utils.DEV_NULL).strip() except subprocess.CalledProcessError: # not found - return None + return None, None, None + + # version + try: + output = subprocess.check_output(binary + ' -version', shell=True) + + except subprocess.CalledProcessError as e: + logging.error('ffmpeg: could find version: %s' % e) + return None, None, None + + result = re.findall('ffmpeg version (.+?) ', output, re.IGNORECASE) + version = result and result[0] or '' + + # codecs + try: + output = subprocess.check_output(binary + ' -codecs -hide_banner', shell=True) + + except subprocess.CalledProcessError as e: + logging.error('ffmpeg: could not list supported codecs: %s' % e) + return None, None, None + + lines = output.split('\n') + matches = [re.match('^ [DEVILSA.]{6} ([\w+_]+) ', l) for l in lines] + codecs = set([m.group(1) for m in matches if m]) + + logging.debug('using ffmpeg version %s' % version) + + _ffmpeg_binary_cache = (binary, version, codecs) + + return _ffmpeg_binary_cache def cleanup_media(media_type): diff --git a/motioneye/motionctl.py b/motioneye/motionctl.py index a34e0e5..351b887 100644 --- a/motioneye/motionctl.py +++ b/motioneye/motionctl.py @@ -25,6 +25,7 @@ import time from tornado.ioloop import IOLoop +import mediafiles import powerctl import settings import update @@ -99,7 +100,7 @@ def start(deferred=False): program, version = program # @UnusedVariable - logging.debug('using motion binary "%s"' % program) + logging.debug('starting motion binary "%s"' % program) motion_config_path = os.path.join(settings.CONF_PATH, 'motion.conf') motion_log_path = os.path.join(settings.LOG_PATH, 'motion.log') @@ -380,6 +381,16 @@ def has_new_movie_format_support(): return version.lower().count('git') or update.compare_versions(version, '3.4') >= 0 +def has_h264_omx_support(): + binary, version, codecs = mediafiles.find_ffmpeg() + if not binary: + return False + + # TODO also check for motion codec parameter support + + return 'h264_omx' in codecs + + def get_rtsp_support(): binary, version = find_motion() if not binary: diff --git a/motioneye/templates/main.html b/motioneye/templates/main.html index 55dc700..b41b8d1 100644 --- a/motioneye/templates/main.html +++ b/motioneye/templates/main.html @@ -761,8 +761,14 @@ {% if has_new_movie_format_support %} + {% if has_h264_omx_support %} + + {% endif %} + {% if has_h264_omx_support %} + + {% endif %} {% endif %}