Rewrite encoding logic and cleanup vaapi presets (#4898)

* Remove duplicated vaapi presets

* Move encoding to string with inputs and outputs

* Formatting

* Fix formatting

* Fix typo

* Remove vaapi encoder
This commit is contained in:
Nicolas Mowen 2023-01-04 17:16:11 -07:00 committed by GitHub
parent ffa98a138b
commit 0a3295aa5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 122 deletions

View File

@ -25,7 +25,7 @@ ffmpeg:
```yaml ```yaml
ffmpeg: ffmpeg:
hwaccel_args: preset-intel-vaapi hwaccel_args: preset-vaapi
``` ```
**NOTICE**: With some of the processors, like the J4125, the default driver `iHD` doesn't seem to work correctly for hardware acceleration. You may need to change the driver to `i965` by adding the following environment variable `LIBVA_DRIVER_NAME=i965` to your docker-compose file or [in the frigate.yml for HA OS users](advanced.md#environment_vars). **NOTICE**: With some of the processors, like the J4125, the default driver `iHD` doesn't seem to work correctly for hardware acceleration. You may need to change the driver to `i965` by adding the following environment variable `LIBVA_DRIVER_NAME=i965` to your docker-compose file or [in the frigate.yml for HA OS users](advanced.md#environment_vars).
@ -42,7 +42,7 @@ ffmpeg:
```yaml ```yaml
ffmpeg: ffmpeg:
hwaccel_args: preset-amd-vaapi hwaccel_args: preset-vaapi
``` ```
### NVIDIA GPU ### NVIDIA GPU

View File

@ -12,7 +12,7 @@ _user_agent_args = [
PRESETS_HW_ACCEL_DECODE = { PRESETS_HW_ACCEL_DECODE = {
"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": [ "preset-vaapi": [
"-hwaccel_flags", "-hwaccel_flags",
"allow_profile_mismatch", "allow_profile_mismatch",
"-hwaccel", "-hwaccel",
@ -42,16 +42,6 @@ PRESETS_HW_ACCEL_DECODE = {
"-c:v", "-c:v",
"hevc_qsv", "hevc_qsv",
], ],
"preset-amd-vaapi": [
"-hwaccel_flags",
"allow_profile_mismatch",
"-hwaccel",
"vaapi",
"-hwaccel_device",
"/dev/dri/renderD128",
"-hwaccel_output_format",
"vaapi",
],
"preset-nvidia-h264": [ "preset-nvidia-h264": [
"-hwaccel", "-hwaccel",
"cuda", "cuda",
@ -85,7 +75,7 @@ PRESETS_HW_ACCEL_DECODE = {
} }
PRESETS_HW_ACCEL_SCALE = { PRESETS_HW_ACCEL_SCALE = {
"preset-intel-vaapi": [ "preset-vaapi": [
"-vf", "-vf",
"fps={},scale_vaapi=w={}:h={},hwdownload,format=yuv420p", "fps={},scale_vaapi=w={}:h={},hwdownload,format=yuv420p",
"-f", "-f",
@ -103,12 +93,6 @@ PRESETS_HW_ACCEL_SCALE = {
"-f", "-f",
"rawvideo", "rawvideo",
], ],
"preset-amd-vaapi": [
"-vf",
"fps={},scale_vaapi=w={}:h={},hwdownload,format=yuv420p",
"-f",
"rawvideo",
],
"preset-nvidia-h264": [ "preset-nvidia-h264": [
"-vf", "-vf",
"fps={},scale_cuda=w={}:h={}:format=nv12,hwdownload,format=nv12,format=yuv420p", "fps={},scale_cuda=w={}:h={}:format=nv12,hwdownload,format=nv12,format=yuv420p",
@ -130,104 +114,11 @@ PRESETS_HW_ACCEL_SCALE = {
} }
PRESETS_HW_ACCEL_ENCODE = { PRESETS_HW_ACCEL_ENCODE = {
"preset-intel-vaapi": [ "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}",
"-c:v", "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}",
"h264_vaapi", "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}",
"-g", "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}",
"50", "default": "ffmpeg -hide_banner {0} -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency {1}",
"-bf",
"0",
"-profile:v",
"high",
"-level:v",
"4.1",
"-sei:v",
"0",
],
"preset-intel-qsv-h264": [
"-c:v",
"h264_qsv",
"-g",
"50",
"-bf",
"0",
"-profile:v",
"high",
"-level:v",
"4.1",
"-async_depth:v",
"1",
],
"preset-intel-qsv-h265": [
"-c:v",
"h264_qsv",
"-g",
"50",
"-bf",
"0",
"-profile:v",
"high",
"-level:v",
"4.1",
"-async_depth:v",
"1",
],
"preset-amd-vaapi": [
"-c:v",
"h264_vaapi",
"-g",
"50",
"-bf",
"0",
"-profile:v",
"high",
"-level:v",
"4.1",
"-sei:v",
"0",
],
"preset-nvidia-h264": [
"-c:v",
"h264_nvenc",
"-g",
"50",
"-profile:v",
"high",
"-level:v",
"auto",
"-preset:v",
"p2",
"-tune:v",
"ll",
],
"preset-nvidia-h265": [
"-c:v",
"h264_nvenc",
"-g",
"50",
"-profile:v",
"high",
"-level:v",
"auto",
"-preset:v",
"p2",
"-tune:v",
"ll",
],
"default": [
"-c:v",
"libx264",
"-g",
"50",
"-profile:v",
"high",
"-level:v",
"4.1",
"-preset:v",
"superfast",
"-tune:v",
"zerolatency",
],
} }
PRESETS_HW_ACCEL_GO2RTC_ENGINE = { PRESETS_HW_ACCEL_GO2RTC_ENGINE = {
@ -268,12 +159,15 @@ def parse_preset_hardware_acceleration_scale(
return scale return scale
def parse_preset_hardware_acceleration_encode(arg: Any) -> list[str]: def parse_preset_hardware_acceleration_encode(arg: Any, input: str, output: str) -> str:
"""Return the correct scaling preset or default preset if none is set.""" """Return the correct scaling preset or default preset if none is set."""
if not isinstance(arg, str): if not isinstance(arg, str):
return PRESETS_HW_ACCEL_ENCODE["default"] return PRESETS_HW_ACCEL_ENCODE["default"].format(input, output)
return PRESETS_HW_ACCEL_ENCODE.get(arg, PRESETS_HW_ACCEL_ENCODE["default"]) return PRESETS_HW_ACCEL_ENCODE.get(arg, PRESETS_HW_ACCEL_ENCODE["default"]).format(
input,
output,
)
def parse_preset_hardware_acceleration_go2rtc_engine(arg: Any) -> list[str]: def parse_preset_hardware_acceleration_go2rtc_engine(arg: Any) -> list[str]:

View File

@ -66,7 +66,7 @@ class RestreamApi:
if self.config.restream.birdseye: if self.config.restream.birdseye:
self.relays[ self.relays[
"birdseye" "birdseye"
] = f"exec:ffmpeg -hide_banner -f rawvideo -pix_fmt yuv420p -video_size {self.config.birdseye.width}x{self.config.birdseye.height} -r 10 -i {BIRDSEYE_PIPE} {' '.join(parse_preset_hardware_acceleration_encode(self.config.ffmpeg.hwaccel_args))} -rtsp_transport tcp -f rtsp {{output}}" ] = f"exec:{parse_preset_hardware_acceleration_encode(self.config.ffmpeg.hwaccel_args, f'-f rawvideo -pix_fmt yuv420p -video_size {self.config.birdseye.width}x{self.config.birdseye.height} -r 10 -i {BIRDSEYE_PIPE}', '-rtsp_transport tcp -f rtsp {output}')}"
for name, path in self.relays.items(): for name, path in self.relays.items():
params = {"src": path, "name": name} params = {"src": path, "name": name}