Move encoding to string with inputs and outputs

This commit is contained in:
Nick Mowen 2023-01-04 07:57:23 -07:00
parent de57e883d5
commit b9a72e3f52
3 changed files with 12 additions and 90 deletions

View File

@ -25,7 +25,7 @@ ffmpeg:
```yaml
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).
@ -42,7 +42,7 @@ ffmpeg:
```yaml
ffmpeg:
hwaccel_args: preset-amd-vaapi
hwaccel_args: preset-vaapi
```
### NVIDIA GPU

View File

@ -114,90 +114,12 @@ PRESETS_HW_ACCEL_SCALE = {
}
PRESETS_HW_ACCEL_ENCODE = {
"preset-vaapi": [
"-c:v",
"h264_vaapi",
"-g",
"50",
"-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-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",
],
"preset-vaapi": "ffmpeg -hide_banner -vaapi_device /dev/dri/renderD128 {} -vf 'format=yuv420p,hwupload' -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 {}",
"preset-intel-qsv-h264": "ffmepg -hide_banner {} -c:v h264_qsv -g 50 -bf 0 -profile:v high -level:v 4.1 -async_depth:v 1 {}",
"preset-intel-qsv-h265": "ffmepg -hide_banner {} -c:v h264_qsv -g 50 -bf 0 -profile:v high -level:v 4.1 -async_depth:v 1 {}",
"preset-nvidia-h264": "ffmepg -hide_banner {} -c:v h264_nvenc -g 50 -profile:v high -level:v auto -preset:v p2 -tune:v ll {}",
"preset-nvidia-h265": "ffmepg -hide_banner {} -c:v h264_nvenc -g 50 -profile:v high -level:v auto -preset:v p2 -tune:v ll {}",
"default": "ffmepg -hide_banner {} -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency {}",
}
@ -229,12 +151,12 @@ def parse_preset_hardware_acceleration_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."""
if not isinstance(arg, str):
return PRESETS_HW_ACCEL_ENCODE["default"]
return PRESETS_HW_ACCEL_ENCODE["default"] % (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"]) % (input, output)
PRESETS_INPUT = {

View File

@ -47,7 +47,7 @@ class RestreamApi:
if self.config.restream.birdseye:
self.relays[
"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():
params = {"src": path, "name": name}