Move presets from string to list to avoid manually separating into a list

This commit is contained in:
Nick Mowen 2022-09-15 09:50:31 -06:00
parent 37f4875c05
commit e2a4395dba
2 changed files with 227 additions and 29 deletions

View File

@ -4,18 +4,32 @@ from typing import Any
PRESETS_HW_ACCEL = { PRESETS_HW_ACCEL = {
"preset-rpi-32-h264": "-c:v h264_v4l2m2m", "preset-rpi-32-h264": ["-c:v", "h264_v4l2m2m"],
"preset-rpi-64-h264": "-c:v h264_v4l2m2m", "preset-rpi-64-h264": ["-c:v", "h264_v4l2m2m"],
"preset-intel-vaapi": "-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format yuv420p", "preset-intel-vaapi": [
"preset-intel-qsv-h264": "-c:v h264_qsv", "-hwaccel",
"preset-intel-qsv-h265": "-c:v hevc_qsv", "vaapi",
"preset-amd-vaapi": "-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format yuv420p", "-hwaccel_device",
"preset-nvidia-h264": "-c:v h264_cuvid", "/dev/dri/renderD128",
"preset-nvidia-h265": "-c:v hevc_cuvid", "-hwaccel_output_format",
"yuv420p",
],
"preset-intel-qsv-h264": ["-c:v", "h264_qsv"],
"preset-intel-qsv-h265": ["-c:v", "hevc_qsv"],
"preset-amd-vaapi": [
"-hwaccel",
"vaapi",
"-hwaccel_device",
"/dev/dri/renderD128",
"-hwaccel_output_format",
"yuv420p",
],
"preset-nvidia-h264": ["-c:v", "h264_cuvid"],
"preset-nvidia-h265": ["-c:v", "hevc_cuvid"],
} }
def parse_preset_hardware_acceleration(arg: Any) -> str: def parse_preset_hardware_acceleration(arg: Any) -> list[str]:
"""Return the correct preset if in preset format otherwise return raw input.""" """Return the correct preset if in preset format otherwise return raw input."""
if not isinstance(arg, str): if not isinstance(arg, str):
return None return None
@ -24,17 +38,118 @@ def parse_preset_hardware_acceleration(arg: Any) -> str:
PRESETS_INPUT = { PRESETS_INPUT = {
"preset-http-jpeg-generic": "-r {} -stream_loop -1 -f image2 -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1", "preset-http-jpeg-generic": [
"preset-http-mjpeg-generic": "-avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1", "-r",
"preset-http-reolink": "-avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -flags low_delay -strict experimental -analyzeduration 1000M -probesize 1000M -rw_timeout 5000000", "{}",
"preset-rtmp-generic": "-avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -rw_timeout 5000000 -use_wallclock_as_timestamps 1 -f live_flv", "-stream_loop",
"preset-rtsp-generic": "-avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -rtsp_transport tcp -timeout 5000000 -use_wallclock_as_timestamps 1", "-1",
"preset-rtsp-udp": "-avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -rtsp_transport udp -timeout 5000000 -use_wallclock_as_timestamps 1", "-f",
"preset-rtsp-blue-iris": "-avoid_negative_ts make_zero -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -rtsp_transport tcp -timeout 5000000 -use_wallclock_as_timestamps 1", "image2",
"-avoid_negative_ts",
"make_zero",
"-fflags",
"nobuffer",
"-flags",
"low_delay",
"-strict",
"experimental",
"-fflags",
"+genpts+discardcorrupt",
"-use_wallclock_as_timestamps",
"1",
],
"preset-http-mjpeg-generic": [
"-avoid_negative_ts",
"make_zero",
"-fflags",
"nobuffer",
"-flags",
"low_delay",
"-strict",
"experimental",
"-fflags",
"+genpts+discardcorrupt",
"-use_wallclock_as_timestamps",
"1",
],
"preset-http-reolink": [
"-avoid_negative_ts",
"make_zero",
"-fflags",
"+genpts+discardcorrupt",
"-flags",
"low_delay",
"-strict",
"experimental",
"-analyzeduration",
"1000M",
"-probesize",
"1000M",
"-rw_timeout",
"5000000",
],
"preset-rtmp-generic": [
"-avoid_negative_ts",
"make_zero",
"-fflags",
"nobuffer",
"-flags",
"low_delay",
"-strict",
"experimental",
"-fflags",
"+genpts+discardcorrupt",
"-rw_timeout",
"5000000",
"-use_wallclock_as_timestamps",
"1",
"-f",
"live_flv",
],
"preset-rtsp-generic": [
"-avoid_negative_ts",
"make_zero",
"-fflags",
"+genpts+discardcorrupt",
"-rtsp_transport",
"tcp",
"-timeout",
"5000000",
"-use_wallclock_as_timestamps",
"1",
],
"preset-rtsp-udp": [
"-avoid_negative_ts",
"make_zero",
"-fflags",
"+genpts+discardcorrupt",
"-rtsp_transport",
"udp",
"-timeout",
"5000000",
"-use_wallclock_as_timestamps",
"1",
],
"preset-rtsp-blue-iris": [
"-avoid_negative_ts",
"make_zero",
"-flags",
"low_delay",
"-strict",
"experimental",
"-fflags",
"+genpts+discardcorrupt",
"-rtsp_transport",
"tcp",
"-timeout",
"5000000",
"-use_wallclock_as_timestamps",
"1",
],
} }
def parse_preset_input(arg: Any, detect_fps: int) -> str: def parse_preset_input(arg: Any, detect_fps: int) -> list[str]:
"""Return the correct preset if in preset format otherwise return raw input.""" """Return the correct preset if in preset format otherwise return raw input."""
if not isinstance(arg, str): if not isinstance(arg, str):
return None return None
@ -46,15 +161,89 @@ def parse_preset_input(arg: Any, detect_fps: int) -> str:
PRESETS_RECORD_OUTPUT = { PRESETS_RECORD_OUTPUT = {
"preset-record-generic": "-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c copy -an", "preset-record-generic": [
"preset-record-generic-audio": "-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v copy -c:a aac", "-f",
"preset-record-mjpeg": "-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v libx264 -an", "segment",
"preset-record-jpeg": "-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v libx264 -an", "-segment_time",
"preset-record-ubiquiti": "-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v copy -ar 44100 -c:a aac", "10",
"-segment_format",
"mp4",
"-reset_timestamps",
"1",
"-strftime",
"1",
"-c",
"copy",
"-an",
],
"preset-record-generic-audio": [
"-f",
"segment",
"-segment_time",
"10",
"-segment_format",
"mp4",
"-reset_timestamps",
"1",
"-strftime",
"1",
"-c:v",
"copy",
"-c:a",
"aac",
],
"preset-record-mjpeg": [
"-f",
"segment",
"-segment_time",
"10",
"-segment_format",
"mp4",
"-reset_timestamps",
"1",
"-strftime",
"1",
"-c:v",
"libx264",
"-an",
],
"preset-record-jpeg": [
"-f",
"segment",
"-segment_time",
"10",
"-segment_format",
"mp4",
"-reset_timestamps",
"1",
"-strftime",
"1",
"-c:v",
"libx264",
"-an",
],
"preset-record-ubiquiti": [
"-f",
"segment",
"-segment_time",
"10",
"-segment_format",
"mp4",
"-reset_timestamps",
"1",
"-strftime",
"1",
"-c:v",
"copy",
"-ar",
"44100",
"-c:a",
"aac",
],
} }
def parse_preset_output_record(arg: Any) -> str: def parse_preset_output_record(arg: Any) -> list[str]:
"""Return the correct preset if in preset format otherwise return raw input.""" """Return the correct preset if in preset format otherwise return raw input."""
if not isinstance(arg, str): if not isinstance(arg, str):
return None return None
@ -63,14 +252,23 @@ def parse_preset_output_record(arg: Any) -> str:
PRESETS_RTMP_OUTPUT = { PRESETS_RTMP_OUTPUT = {
"preset-rtmp-generic": "-c copy -f flv", "preset-rtmp-generic": ["-c", "copy", "-f", "flv"],
"preset-rtmp-mjpeg": "-c:v libx264 -an -f flv", "preset-rtmp-mjpeg": ["-c:v", "libx264", "-an", "-f", "flv"],
"preset-rtmp-jpeg": "-c:v libx264 -an -f flv", "preset-rtmp-jpeg": ["-c:v", "libx264", "-an", "-f", "flv"],
"preset-rtmp-ubiquiti": "-c:v copy -f flv -ar 44100 -c:a aac", "preset-rtmp-ubiquiti": [
"-c:v",
"copy",
"-f",
"flv",
"-ar",
"44100",
"-c:a",
"aac",
],
} }
def parse_preset_output_rtmp(arg: Any) -> str: def parse_preset_output_rtmp(arg: Any) -> list[str]:
"""Return the correct preset if in preset format otherwise return raw input.""" """Return the correct preset if in preset format otherwise return raw input."""
if not isinstance(arg, str): if not isinstance(arg, str):
return None return None

View File

@ -89,7 +89,7 @@ class TestFfmpegPresets(unittest.TestCase):
assert "preset-rtmp-generic" not in ( assert "preset-rtmp-generic" not in (
" ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]) " ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"])
) )
assert parse_preset_input("preset-rtmp-generic", 5) in ( assert (" ".join(parse_preset_input("preset-rtmp-generic", 5))) in (
" ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]) " ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"])
) )