]> www.vanbest.org Git - motioneye-debian/commitdiff
add support for RPi OMX hw accel codec
authorCalin Crisan <ccrisan@gmail.com>
Sun, 27 Aug 2017 14:06:40 +0000 (17:06 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 27 Aug 2017 14:06:40 +0000 (17:06 +0300)
motioneye/config.py
motioneye/handlers.py
motioneye/mediafiles.py
motioneye/motionctl.py
motioneye/templates/main.html

index b87fe8d6080c43463bcb1455e29f806e90f4ce89..acdd637ad890bfa513a5b0926ca14b9eed80a8ca 100644 (file)
@@ -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%
 
index c25a2ffb23bf4a6a12ca03376e11d88ae82356f2..ff91c314d186a428cb29749e408f0584123c9d29 100644 (file)
@@ -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)
 
index 29e27a42942ed2c0c11ed080973b1075cac61785..274fb5cfb8e89f0a359f787d41860cca7b7b57d3 100644 (file)
@@ -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):
index a34e0e5d0bc10f9e1d3c9a70f99acae36e677efa..351b8870d0fb00f0ad22ce6293643aa5c7466e99 100644 (file)
@@ -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:
index 55dc7006567666f3203f464ad843c13e48c15f54..b41b8d1327806b4b7d29cf6c51cba6f76660210d 100644 (file)
                                 <option value="mov">QuickTime (.mov)</option>
                                 {% if has_new_movie_format_support %}
                                 <option value="mp4">H.264 (.mp4)</option>
+                                {% if has_h264_omx_support %}
+                                <option value="mp4:h264_omx">H.264/OMX (.mp4)</option>
+                                {% endif %}
                                 <option value="hevc">HEVC (.mp4)</option>
                                 <option value="mkv">Matroska Video (.mkv)</option>
+                                {% if has_h264_omx_support %}
+                                <option value="mkv:h264_omx">Matroska Video/OMX (.mkv)</option>
+                                {% endif %}
                                 {% endif %}
                             </select>
                         </td>