Skip to content

Commit

Permalink
add support for RPi OMX hw accel codec
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrisan committed Aug 27, 2017
1 parent 9d546ec commit 1744cfa
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
7 changes: 6 additions & 1 deletion motioneye/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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%

Expand Down
1 change: 1 addition & 0 deletions motioneye/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def get(self):
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)

Expand Down
42 changes: 40 additions & 2 deletions motioneye/mediafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
'mov': 'mpeg4',
'mp4': 'h264',
'mkv': 'h264',
'mp4:h264_omx': 'h264_omx',
'mkv:h264_omx': 'h264_omx',
'hevc': 'h265'
}

Expand Down Expand Up @@ -82,6 +84,8 @@
_timelapse_process = None
_timelapse_data = None

_ffmpeg_binary_cache = None


def findfiles(path):
files = []
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 12 additions & 1 deletion motioneye/motionctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from tornado.ioloop import IOLoop

import mediafiles
import powerctl
import settings
import update
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions motioneye/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,14 @@
<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>
Expand Down

0 comments on commit 1744cfa

Please sign in to comment.