mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 18:55:23 +03:00
Add separate ffmpeg preset for timelapse
This commit is contained in:
parent
355c9df59b
commit
6c2621799c
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from enum import Enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from frigate.const import BTBN_PATH
|
from frigate.const import BTBN_PATH
|
||||||
@ -116,7 +118,7 @@ PRESETS_HW_ACCEL_SCALE = {
|
|||||||
"default": "-r {0} -s {1}x{2}",
|
"default": "-r {0} -s {1}x{2}",
|
||||||
}
|
}
|
||||||
|
|
||||||
PRESETS_HW_ACCEL_ENCODE = {
|
PRESETS_HW_ACCEL_ENCODE_BIRDSEYE = {
|
||||||
"preset-rpi-32-h264": "ffmpeg -hide_banner {0} -c:v h264_v4l2m2m {1}",
|
"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-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 -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload {1}",
|
"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}",
|
||||||
@ -127,6 +129,17 @@ PRESETS_HW_ACCEL_ENCODE = {
|
|||||||
"default": "ffmpeg -hide_banner {0} -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency {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}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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}",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def parse_preset_hardware_acceleration_decode(arg: Any) -> list[str]:
|
def parse_preset_hardware_acceleration_decode(arg: Any) -> list[str]:
|
||||||
"""Return the correct preset if in preset format otherwise return None."""
|
"""Return the correct preset if in preset format otherwise return None."""
|
||||||
@ -161,12 +174,24 @@ def parse_preset_hardware_acceleration_scale(
|
|||||||
return scale
|
return scale
|
||||||
|
|
||||||
|
|
||||||
def parse_preset_hardware_acceleration_encode(arg: Any, input: str, output: str) -> str:
|
class EncodeTypeEnum(str, Enum):
|
||||||
"""Return the correct scaling preset or default preset if none is set."""
|
birdseye = "birdseye"
|
||||||
if not isinstance(arg, str):
|
timelapse = "timelapse"
|
||||||
return PRESETS_HW_ACCEL_ENCODE["default"].format(input, output)
|
|
||||||
|
|
||||||
return PRESETS_HW_ACCEL_ENCODE.get(arg, PRESETS_HW_ACCEL_ENCODE["default"]).format(
|
|
||||||
|
def parse_preset_hardware_acceleration_encode(
|
||||||
|
arg: Any, input: str, output: str, type: EncodeTypeEnum = EncodeTypeEnum.birdseye
|
||||||
|
) -> str:
|
||||||
|
"""Return the correct scaling preset or default preset if none is set."""
|
||||||
|
if type == EncodeTypeEnum.birdseye:
|
||||||
|
arg_map = PRESETS_HW_ACCEL_ENCODE_BIRDSEYE
|
||||||
|
elif type == EncodeTypeEnum.timelapse:
|
||||||
|
arg_map = PRESETS_HW_ACCEL_ENCODE_TIMELAPSE
|
||||||
|
|
||||||
|
if not isinstance(arg, str):
|
||||||
|
return arg_map["default"].format(input, output)
|
||||||
|
|
||||||
|
return arg_map.get(arg, arg_map["default"]).format(
|
||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
_gpu_selector.get_selected_gpu(),
|
_gpu_selector.get_selected_gpu(),
|
||||||
|
|||||||
@ -10,7 +10,10 @@ import subprocess as sp
|
|||||||
|
|
||||||
from frigate.config import FrigateConfig
|
from frigate.config import FrigateConfig
|
||||||
from frigate.const import EXPORT_DIR, MAX_PLAYLIST_SECONDS
|
from frigate.const import EXPORT_DIR, MAX_PLAYLIST_SECONDS
|
||||||
from frigate.ffmpeg_presets import parse_preset_hardware_acceleration_encode
|
from frigate.ffmpeg_presets import (
|
||||||
|
EncodeTypeEnum,
|
||||||
|
parse_preset_hardware_acceleration_encode,
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -76,6 +79,7 @@ class RecordingExporter(threading.Thread):
|
|||||||
self.config.ffmpeg.hwaccel_args,
|
self.config.ffmpeg.hwaccel_args,
|
||||||
ffmpeg_input,
|
ffmpeg_input,
|
||||||
f"-vf setpts=0.04*PTS -r 30 -an {file_name}",
|
f"-vf setpts=0.04*PTS -r 30 -an {file_name}",
|
||||||
|
EncodeTypeEnum.timelapse,
|
||||||
)
|
)
|
||||||
).split(" ")
|
).split(" ")
|
||||||
|
|
||||||
@ -87,7 +91,9 @@ class RecordingExporter(threading.Thread):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
logger.error(f"Failed to export recording for command {' '.join(ffmpeg_cmd)}")
|
logger.error(
|
||||||
|
f"Failed to export recording for command {' '.join(ffmpeg_cmd)}"
|
||||||
|
)
|
||||||
logger.error(p.stderr)
|
logger.error(p.stderr)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user