2022-11-29 04:48:11 +01:00
|
|
|
"""Handles inserting and maintaining ffmpeg presets."""
|
|
|
|
|
2023-02-11 15:00:58 +01:00
|
|
|
import logging
|
2023-01-08 14:04:58 +01:00
|
|
|
import os
|
2023-06-08 13:32:35 +02:00
|
|
|
from enum import Enum
|
2022-11-29 04:48:11 +01:00
|
|
|
from typing import Any
|
|
|
|
|
2023-01-08 14:04:58 +01:00
|
|
|
from frigate.const import BTBN_PATH
|
2023-02-11 15:00:58 +01:00
|
|
|
from frigate.util import vainfo_hwaccel
|
2023-05-29 12:31:17 +02:00
|
|
|
from frigate.version import VERSION
|
2023-02-11 15:00:58 +01:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class LibvaGpuSelector:
|
|
|
|
"Automatically selects the correct libva GPU."
|
|
|
|
|
|
|
|
_selected_gpu = None
|
|
|
|
|
|
|
|
def get_selected_gpu(self) -> str:
|
|
|
|
"""Get selected libva GPU."""
|
|
|
|
if not os.path.exists("/dev/dri"):
|
|
|
|
return ""
|
|
|
|
|
|
|
|
if self._selected_gpu:
|
|
|
|
return self._selected_gpu
|
|
|
|
|
|
|
|
devices = list(filter(lambda d: d.startswith("render"), os.listdir("/dev/dri")))
|
|
|
|
|
|
|
|
if len(devices) < 2:
|
|
|
|
self._selected_gpu = "/dev/dri/renderD128"
|
|
|
|
return self._selected_gpu
|
|
|
|
|
|
|
|
for device in devices:
|
|
|
|
check = vainfo_hwaccel(device_name=device)
|
|
|
|
|
|
|
|
logger.debug(f"{device} return vainfo status code: {check.returncode}")
|
|
|
|
|
|
|
|
if check.returncode == 0:
|
|
|
|
self._selected_gpu = f"/dev/dri/{device}"
|
|
|
|
return self._selected_gpu
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
2023-01-08 14:04:58 +01:00
|
|
|
|
|
|
|
TIMEOUT_PARAM = "-timeout" if os.path.exists(BTBN_PATH) else "-stimeout"
|
2022-12-04 16:46:03 +01:00
|
|
|
|
2023-02-11 15:00:58 +01:00
|
|
|
_gpu_selector = LibvaGpuSelector()
|
2022-12-04 16:46:03 +01:00
|
|
|
_user_agent_args = [
|
|
|
|
"-user_agent",
|
|
|
|
f"FFmpeg Frigate/{VERSION}",
|
|
|
|
]
|
2022-11-29 04:48:11 +01:00
|
|
|
|
2022-12-30 17:56:52 +01:00
|
|
|
PRESETS_HW_ACCEL_DECODE = {
|
2023-05-05 00:55:44 +02:00
|
|
|
"preset-rpi-32-h264": ["-c:v:1", "h264_v4l2m2m"],
|
|
|
|
"preset-rpi-64-h264": ["-c:v:1", "h264_v4l2m2m"],
|
2023-01-05 01:16:11 +01:00
|
|
|
"preset-vaapi": [
|
2022-12-30 17:56:52 +01:00
|
|
|
"-hwaccel_flags",
|
|
|
|
"allow_profile_mismatch",
|
2022-11-29 04:48:11 +01:00
|
|
|
"-hwaccel",
|
|
|
|
"vaapi",
|
|
|
|
"-hwaccel_device",
|
2023-02-11 15:00:58 +01:00
|
|
|
_gpu_selector.get_selected_gpu(),
|
2022-11-29 04:48:11 +01:00
|
|
|
"-hwaccel_output_format",
|
2022-12-30 17:56:52 +01:00
|
|
|
"vaapi",
|
|
|
|
],
|
|
|
|
"preset-intel-qsv-h264": [
|
|
|
|
"-hwaccel",
|
|
|
|
"qsv",
|
|
|
|
"-qsv_device",
|
2023-02-11 15:00:58 +01:00
|
|
|
_gpu_selector.get_selected_gpu(),
|
2022-12-30 17:56:52 +01:00
|
|
|
"-hwaccel_output_format",
|
|
|
|
"qsv",
|
|
|
|
"-c:v",
|
|
|
|
"h264_qsv",
|
|
|
|
],
|
|
|
|
"preset-intel-qsv-h265": [
|
2023-01-15 16:41:13 +01:00
|
|
|
"-load_plugin",
|
|
|
|
"hevc_hw",
|
2022-12-30 17:56:52 +01:00
|
|
|
"-hwaccel",
|
|
|
|
"qsv",
|
|
|
|
"-qsv_device",
|
2023-02-11 15:00:58 +01:00
|
|
|
_gpu_selector.get_selected_gpu(),
|
2022-12-30 17:56:52 +01:00
|
|
|
"-hwaccel_output_format",
|
|
|
|
"qsv",
|
|
|
|
"-c:v",
|
|
|
|
"hevc_qsv",
|
2022-11-29 04:48:11 +01:00
|
|
|
],
|
2022-12-30 17:56:52 +01:00
|
|
|
"preset-nvidia-h264": [
|
|
|
|
"-hwaccel",
|
|
|
|
"cuda",
|
|
|
|
"-hwaccel_output_format",
|
|
|
|
"cuda",
|
|
|
|
],
|
|
|
|
"preset-nvidia-h265": [
|
|
|
|
"-hwaccel",
|
|
|
|
"cuda",
|
|
|
|
"-hwaccel_output_format",
|
|
|
|
"cuda",
|
|
|
|
],
|
|
|
|
"preset-nvidia-mjpeg": [
|
|
|
|
"-hwaccel",
|
|
|
|
"cuda",
|
|
|
|
"-hwaccel_output_format",
|
|
|
|
"cuda",
|
2022-11-29 04:48:11 +01:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2022-12-30 17:56:52 +01:00
|
|
|
PRESETS_HW_ACCEL_SCALE = {
|
2023-02-12 15:02:40 +01:00
|
|
|
"preset-rpi-32-h264": "-r {0} -s {1}x{2}",
|
|
|
|
"preset-rpi-64-h264": "-r {0} -s {1}x{2}",
|
|
|
|
"preset-vaapi": "-r {0} -vf fps={0},scale_vaapi=w={1}:h={2},hwdownload,format=yuv420p",
|
|
|
|
"preset-intel-qsv-h264": "-r {0} -vf vpp_qsv=framerate={0}:w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p",
|
|
|
|
"preset-intel-qsv-h265": "-r {0} -vf vpp_qsv=framerate={0}:w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p",
|
|
|
|
"preset-nvidia-h264": "-r {0} -vf fps={0},scale_cuda=w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p",
|
|
|
|
"preset-nvidia-h265": "-r {0} -vf fps={0},scale_cuda=w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p",
|
2023-01-24 14:27:07 +01:00
|
|
|
"default": "-r {0} -s {1}x{2}",
|
2022-12-30 17:56:52 +01:00
|
|
|
}
|
2022-11-29 04:48:11 +01:00
|
|
|
|
2023-06-08 13:32:35 +02:00
|
|
|
PRESETS_HW_ACCEL_ENCODE_BIRDSEYE = {
|
2023-02-17 01:38:32 +01:00
|
|
|
"preset-rpi-32-h264": "ffmpeg -hide_banner {0} -c:v h264_v4l2m2m {1}",
|
|
|
|
"preset-rpi-64-h264": "ffmpeg -hide_banner {0} -c:v h264_v4l2m2m {1}",
|
2023-02-11 15:00:58 +01:00
|
|
|
"preset-vaapi": "ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device {2} {0} -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload {1}",
|
2023-01-05 01:16:11 +01:00
|
|
|
"preset-intel-qsv-h264": "ffmpeg -hide_banner {0} -c:v h264_qsv -g 50 -bf 0 -profile:v high -level:v 4.1 -async_depth:v 1 {1}",
|
|
|
|
"preset-intel-qsv-h265": "ffmpeg -hide_banner {0} -c:v h264_qsv -g 50 -bf 0 -profile:v high -level:v 4.1 -async_depth:v 1 {1}",
|
|
|
|
"preset-nvidia-h264": "ffmpeg -hide_banner {0} -c:v h264_nvenc -g 50 -profile:v high -level:v auto -preset:v p2 -tune:v ll {1}",
|
|
|
|
"preset-nvidia-h265": "ffmpeg -hide_banner {0} -c:v h264_nvenc -g 50 -profile:v high -level:v auto -preset:v p2 -tune:v ll {1}",
|
|
|
|
"default": "ffmpeg -hide_banner {0} -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency {1}",
|
2022-12-31 15:54:10 +01:00
|
|
|
}
|
|
|
|
|
2023-06-08 13:32:35 +02:00
|
|
|
PRESETS_HW_ACCEL_ENCODE_TIMELAPSE = {
|
|
|
|
"preset-rpi-32-h264": "ffmpeg -hide_banner {0} -c:v h264_v4l2m2m {1}",
|
|
|
|
"preset-rpi-64-h264": "ffmpeg -hide_banner {0} -c:v h264_v4l2m2m {1}",
|
|
|
|
"preset-vaapi": "ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device {2} {0} -c:v h264_vaapi {1}",
|
|
|
|
"preset-intel-qsv-h264": "ffmpeg -hide_banner {0} -c:v h264_qsv -g 50 -bf 0 -profile:v high -level:v 4.1 -async_depth:v 1 {1}",
|
|
|
|
"preset-intel-qsv-h265": "ffmpeg -hide_banner {0} -c:v hevc_qsv -g 50 -bf 0 -profile:v high -level:v 4.1 -async_depth:v 1 {1}",
|
|
|
|
"preset-nvidia-h264": "ffmpeg -hide_banner -hwaccel cuda -hwaccel_output_format cuda -extra_hw_frames 8 {0} -c:v h264_nvenc {1}",
|
|
|
|
"preset-nvidia-h265": "ffmpeg -hide_banner -hwaccel cuda -hwaccel_output_format cuda -extra_hw_frames 8 {0} -c:v hevc_nvenc {1}",
|
|
|
|
"default": "ffmpeg -hide_banner {0} -c:v libx264 -preset:v ultrafast -tune:v zerolatency {1}",
|
|
|
|
}
|
|
|
|
|
2022-12-30 17:56:52 +01:00
|
|
|
|
|
|
|
def parse_preset_hardware_acceleration_decode(arg: Any) -> list[str]:
|
2022-11-29 04:48:11 +01:00
|
|
|
"""Return the correct preset if in preset format otherwise return None."""
|
|
|
|
if not isinstance(arg, str):
|
|
|
|
return None
|
|
|
|
|
2022-12-30 17:56:52 +01:00
|
|
|
return PRESETS_HW_ACCEL_DECODE.get(arg, None)
|
|
|
|
|
|
|
|
|
|
|
|
def parse_preset_hardware_acceleration_scale(
|
|
|
|
arg: Any,
|
|
|
|
detect_args: list[str],
|
|
|
|
fps: int,
|
|
|
|
width: int,
|
|
|
|
height: int,
|
|
|
|
) -> list[str]:
|
|
|
|
"""Return the correct scaling preset or default preset if none is set."""
|
2023-01-03 01:32:12 +01:00
|
|
|
if not isinstance(arg, str) or " " in arg:
|
2023-01-13 14:22:19 +01:00
|
|
|
scale = PRESETS_HW_ACCEL_SCALE["default"].format(fps, width, height).split(" ")
|
2022-12-30 17:56:52 +01:00
|
|
|
scale.extend(detect_args)
|
|
|
|
return scale
|
|
|
|
|
2023-01-13 14:22:19 +01:00
|
|
|
scale = PRESETS_HW_ACCEL_SCALE.get(arg, "")
|
|
|
|
|
|
|
|
if scale:
|
2023-02-12 15:02:40 +01:00
|
|
|
scale = scale.format(fps, width, height).split(" ")
|
|
|
|
scale.extend(detect_args)
|
|
|
|
return scale
|
2023-01-13 14:22:19 +01:00
|
|
|
else:
|
|
|
|
scale = scale.format(fps, width, height).split(" ")
|
|
|
|
scale.extend(detect_args)
|
|
|
|
return scale
|
2022-11-29 04:48:11 +01:00
|
|
|
|
|
|
|
|
2023-06-08 13:32:35 +02:00
|
|
|
class EncodeTypeEnum(str, Enum):
|
|
|
|
birdseye = "birdseye"
|
|
|
|
timelapse = "timelapse"
|
|
|
|
|
|
|
|
|
|
|
|
def parse_preset_hardware_acceleration_encode(
|
|
|
|
arg: Any, input: str, output: str, type: EncodeTypeEnum = EncodeTypeEnum.birdseye
|
|
|
|
) -> str:
|
2022-12-31 15:54:10 +01:00
|
|
|
"""Return the correct scaling preset or default preset if none is set."""
|
2023-06-08 13:32:35 +02:00
|
|
|
if type == EncodeTypeEnum.birdseye:
|
|
|
|
arg_map = PRESETS_HW_ACCEL_ENCODE_BIRDSEYE
|
|
|
|
elif type == EncodeTypeEnum.timelapse:
|
|
|
|
arg_map = PRESETS_HW_ACCEL_ENCODE_TIMELAPSE
|
|
|
|
|
2022-12-31 15:54:10 +01:00
|
|
|
if not isinstance(arg, str):
|
2023-06-08 13:32:35 +02:00
|
|
|
return arg_map["default"].format(input, output)
|
2022-12-31 15:54:10 +01:00
|
|
|
|
2023-06-08 13:32:35 +02:00
|
|
|
return arg_map.get(arg, arg_map["default"]).format(
|
2023-01-05 01:16:11 +01:00
|
|
|
input,
|
|
|
|
output,
|
2023-02-11 15:00:58 +01:00
|
|
|
_gpu_selector.get_selected_gpu(),
|
2023-01-05 01:16:11 +01:00
|
|
|
)
|
2022-12-31 15:54:10 +01:00
|
|
|
|
|
|
|
|
2022-11-29 04:48:11 +01:00
|
|
|
PRESETS_INPUT = {
|
2022-12-04 16:46:03 +01:00
|
|
|
"preset-http-jpeg-generic": _user_agent_args
|
|
|
|
+ [
|
2022-11-29 04:48:11 +01:00
|
|
|
"-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",
|
|
|
|
],
|
2022-12-04 16:46:03 +01:00
|
|
|
"preset-http-mjpeg-generic": _user_agent_args
|
|
|
|
+ [
|
2022-11-29 04:48:11 +01:00
|
|
|
"-avoid_negative_ts",
|
|
|
|
"make_zero",
|
|
|
|
"-fflags",
|
|
|
|
"nobuffer",
|
|
|
|
"-flags",
|
|
|
|
"low_delay",
|
|
|
|
"-strict",
|
|
|
|
"experimental",
|
|
|
|
"-fflags",
|
|
|
|
"+genpts+discardcorrupt",
|
|
|
|
"-use_wallclock_as_timestamps",
|
|
|
|
"1",
|
|
|
|
],
|
2022-12-04 16:46:03 +01:00
|
|
|
"preset-http-reolink": _user_agent_args
|
|
|
|
+ [
|
2022-11-29 04:48:11 +01:00
|
|
|
"-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",
|
|
|
|
],
|
2022-12-04 16:46:03 +01:00
|
|
|
"preset-rtsp-generic": _user_agent_args
|
|
|
|
+ [
|
2022-11-29 04:48:11 +01:00
|
|
|
"-avoid_negative_ts",
|
|
|
|
"make_zero",
|
|
|
|
"-fflags",
|
|
|
|
"+genpts+discardcorrupt",
|
|
|
|
"-rtsp_transport",
|
|
|
|
"tcp",
|
2023-01-08 14:04:58 +01:00
|
|
|
TIMEOUT_PARAM,
|
2022-11-29 04:48:11 +01:00
|
|
|
"5000000",
|
|
|
|
"-use_wallclock_as_timestamps",
|
|
|
|
"1",
|
|
|
|
],
|
2023-07-01 15:18:33 +02:00
|
|
|
"preset-rtsp-audio-only": [
|
|
|
|
"-rtsp_transport",
|
|
|
|
"tcp",
|
|
|
|
TIMEOUT_PARAM,
|
|
|
|
"5000000",
|
|
|
|
"-vn",
|
|
|
|
],
|
2023-01-15 16:40:42 +01:00
|
|
|
"preset-rtsp-restream": _user_agent_args
|
2023-02-04 02:33:25 +01:00
|
|
|
+ [
|
|
|
|
"-rtsp_transport",
|
|
|
|
"tcp",
|
|
|
|
TIMEOUT_PARAM,
|
|
|
|
"5000000",
|
|
|
|
],
|
|
|
|
"preset-rtsp-restream-low-latency": _user_agent_args
|
2023-01-15 16:40:42 +01:00
|
|
|
+ [
|
|
|
|
"-rtsp_transport",
|
|
|
|
"tcp",
|
|
|
|
TIMEOUT_PARAM,
|
|
|
|
"5000000",
|
2023-01-26 01:39:35 +01:00
|
|
|
"-fflags",
|
|
|
|
"nobuffer",
|
|
|
|
"-flags",
|
|
|
|
"low_delay",
|
2023-01-15 16:40:42 +01:00
|
|
|
],
|
2022-12-04 16:46:03 +01:00
|
|
|
"preset-rtsp-udp": _user_agent_args
|
|
|
|
+ [
|
2022-11-29 04:48:11 +01:00
|
|
|
"-avoid_negative_ts",
|
|
|
|
"make_zero",
|
|
|
|
"-fflags",
|
|
|
|
"+genpts+discardcorrupt",
|
|
|
|
"-rtsp_transport",
|
|
|
|
"udp",
|
2023-01-08 14:04:58 +01:00
|
|
|
TIMEOUT_PARAM,
|
2022-11-29 04:48:11 +01:00
|
|
|
"5000000",
|
|
|
|
"-use_wallclock_as_timestamps",
|
|
|
|
"1",
|
|
|
|
],
|
2022-12-04 16:46:03 +01:00
|
|
|
"preset-rtsp-blue-iris": _user_agent_args
|
|
|
|
+ [
|
|
|
|
"-user_agent",
|
|
|
|
f"FFmpeg Frigate/{VERSION}",
|
2022-11-29 04:48:11 +01:00
|
|
|
"-avoid_negative_ts",
|
|
|
|
"make_zero",
|
|
|
|
"-flags",
|
|
|
|
"low_delay",
|
|
|
|
"-strict",
|
|
|
|
"experimental",
|
|
|
|
"-fflags",
|
|
|
|
"+genpts+discardcorrupt",
|
|
|
|
"-rtsp_transport",
|
|
|
|
"tcp",
|
2023-01-08 14:04:58 +01:00
|
|
|
TIMEOUT_PARAM,
|
2022-11-29 04:48:11 +01:00
|
|
|
"5000000",
|
|
|
|
"-use_wallclock_as_timestamps",
|
|
|
|
"1",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def parse_preset_input(arg: Any, detect_fps: int) -> list[str]:
|
|
|
|
"""Return the correct preset if in preset format otherwise return None."""
|
|
|
|
if not isinstance(arg, str):
|
|
|
|
return None
|
|
|
|
|
2023-01-07 14:21:18 +01:00
|
|
|
if arg == "preset-http-jpeg-generic":
|
2022-12-30 17:56:52 +01:00
|
|
|
input = PRESETS_INPUT[arg].copy()
|
2023-04-28 14:11:01 +02:00
|
|
|
input[len(_user_agent_args) + 1] = str(detect_fps)
|
2022-12-30 17:56:52 +01:00
|
|
|
return input
|
2022-11-29 04:48:11 +01:00
|
|
|
|
|
|
|
return PRESETS_INPUT.get(arg, None)
|
|
|
|
|
|
|
|
|
|
|
|
PRESETS_RECORD_OUTPUT = {
|
|
|
|
"preset-record-generic": [
|
|
|
|
"-f",
|
|
|
|
"segment",
|
|
|
|
"-segment_time",
|
|
|
|
"10",
|
|
|
|
"-segment_format",
|
|
|
|
"mp4",
|
|
|
|
"-reset_timestamps",
|
|
|
|
"1",
|
|
|
|
"-strftime",
|
|
|
|
"1",
|
|
|
|
"-c",
|
|
|
|
"copy",
|
|
|
|
"-an",
|
|
|
|
],
|
2023-01-15 16:40:42 +01:00
|
|
|
"preset-record-generic-audio-aac": [
|
2022-11-29 04:48:11 +01:00
|
|
|
"-f",
|
|
|
|
"segment",
|
|
|
|
"-segment_time",
|
|
|
|
"10",
|
|
|
|
"-segment_format",
|
|
|
|
"mp4",
|
|
|
|
"-reset_timestamps",
|
|
|
|
"1",
|
|
|
|
"-strftime",
|
|
|
|
"1",
|
|
|
|
"-c:v",
|
|
|
|
"copy",
|
|
|
|
"-c:a",
|
|
|
|
"aac",
|
|
|
|
],
|
2023-01-15 16:40:42 +01:00
|
|
|
"preset-record-generic-audio-copy": [
|
|
|
|
"-f",
|
|
|
|
"segment",
|
|
|
|
"-segment_time",
|
|
|
|
"10",
|
|
|
|
"-segment_format",
|
|
|
|
"mp4",
|
|
|
|
"-reset_timestamps",
|
|
|
|
"1",
|
|
|
|
"-strftime",
|
|
|
|
"1",
|
|
|
|
"-c",
|
|
|
|
"copy",
|
|
|
|
],
|
2022-11-29 04:48:11 +01:00
|
|
|
"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) -> list[str]:
|
|
|
|
"""Return the correct preset if in preset format otherwise return None."""
|
|
|
|
if not isinstance(arg, str):
|
|
|
|
return None
|
|
|
|
|
|
|
|
return PRESETS_RECORD_OUTPUT.get(arg, None)
|
|
|
|
|
|
|
|
|
|
|
|
PRESETS_RTMP_OUTPUT = {
|
|
|
|
"preset-rtmp-generic": ["-c", "copy", "-f", "flv"],
|
|
|
|
"preset-rtmp-mjpeg": ["-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",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def parse_preset_output_rtmp(arg: Any) -> list[str]:
|
|
|
|
"""Return the correct preset if in preset format otherwise return None."""
|
|
|
|
if not isinstance(arg, str):
|
|
|
|
return None
|
|
|
|
|
|
|
|
return PRESETS_RTMP_OUTPUT.get(arg, None)
|