mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 09:45:22 +03:00
Use hardware accelerated scaling when hwaccel preset is set
This commit is contained in:
parent
e3ec292528
commit
fedbe58e70
@ -27,7 +27,8 @@ from frigate.util import (
|
|||||||
load_labels,
|
load_labels,
|
||||||
)
|
)
|
||||||
from frigate.ffmpeg_presets import (
|
from frigate.ffmpeg_presets import (
|
||||||
parse_preset_hardware_acceleration,
|
parse_preset_hardware_acceleration_decode,
|
||||||
|
parse_preset_hardware_acceleration_scale,
|
||||||
parse_preset_input,
|
parse_preset_input,
|
||||||
parse_preset_output_record,
|
parse_preset_output_record,
|
||||||
parse_preset_output_rtmp,
|
parse_preset_output_rtmp,
|
||||||
@ -626,14 +627,10 @@ class CameraConfig(FrigateBaseModel):
|
|||||||
ffmpeg_output_args = []
|
ffmpeg_output_args = []
|
||||||
if "detect" in ffmpeg_input.roles:
|
if "detect" in ffmpeg_input.roles:
|
||||||
detect_args = get_ffmpeg_arg_list(self.ffmpeg.output_args.detect)
|
detect_args = get_ffmpeg_arg_list(self.ffmpeg.output_args.detect)
|
||||||
|
scale_args = parse_preset_hardware_acceleration_scale(ffmpeg_input.hwaccel_args, self.detect.fps, self.detect.width, self.detect.height)
|
||||||
|
|
||||||
ffmpeg_output_args = (
|
ffmpeg_output_args = (
|
||||||
[
|
scale_args
|
||||||
"-r",
|
|
||||||
str(self.detect.fps),
|
|
||||||
"-s",
|
|
||||||
f"{self.detect.width}x{self.detect.height}",
|
|
||||||
]
|
|
||||||
+ detect_args
|
+ detect_args
|
||||||
+ ffmpeg_output_args
|
+ ffmpeg_output_args
|
||||||
+ ["pipe:"]
|
+ ["pipe:"]
|
||||||
@ -667,12 +664,14 @@ class CameraConfig(FrigateBaseModel):
|
|||||||
ffmpeg_input.global_args or self.ffmpeg.global_args
|
ffmpeg_input.global_args or self.ffmpeg.global_args
|
||||||
)
|
)
|
||||||
hwaccel_args = get_ffmpeg_arg_list(
|
hwaccel_args = get_ffmpeg_arg_list(
|
||||||
ffmpeg_input.hwaccel_args
|
parse_preset_hardware_acceleration_decode(ffmpeg_input.hwaccel_args)
|
||||||
or parse_preset_hardware_acceleration(self.ffmpeg.hwaccel_args)
|
or ffmpeg_input.hwaccel_args
|
||||||
|
or parse_preset_hardware_acceleration_decode(self.ffmpeg.hwaccel_args)
|
||||||
or self.ffmpeg.hwaccel_args
|
or self.ffmpeg.hwaccel_args
|
||||||
)
|
)
|
||||||
input_args = get_ffmpeg_arg_list(
|
input_args = get_ffmpeg_arg_list(
|
||||||
ffmpeg_input.input_args
|
parse_preset_input(ffmpeg_input.input_args, self.detect.fps)
|
||||||
|
or ffmpeg_input.input_args
|
||||||
or parse_preset_input(self.ffmpeg.input_args, self.detect.fps)
|
or parse_preset_input(self.ffmpeg.input_args, self.detect.fps)
|
||||||
or self.ffmpeg.input_args
|
or self.ffmpeg.input_args
|
||||||
)
|
)
|
||||||
|
|||||||
@ -9,7 +9,7 @@ _user_agent_args = [
|
|||||||
f"FFmpeg Frigate/{VERSION}",
|
f"FFmpeg Frigate/{VERSION}",
|
||||||
]
|
]
|
||||||
|
|
||||||
PRESETS_HW_ACCEL = {
|
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-intel-vaapi": [
|
||||||
@ -35,13 +35,76 @@ PRESETS_HW_ACCEL = {
|
|||||||
"preset-nvidia-mjpeg": ["-c:v", "mjpeg_cuvid"],
|
"preset-nvidia-mjpeg": ["-c:v", "mjpeg_cuvid"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRESETS_HW_ACCEL_SCALE = {
|
||||||
|
"preset-intel-vaapi": [
|
||||||
|
"-vf",
|
||||||
|
"fps={},deinterlace_vaapi=rate=field:auto=1,scale_vaapi=w={}:h={},hwdownload,format=yuv420p",
|
||||||
|
"-f",
|
||||||
|
"rawvideo",
|
||||||
|
],
|
||||||
|
"preset-intel-qsv-h264": [
|
||||||
|
"-vf",
|
||||||
|
"vpp_qsv=framerate={}:scale_mode=1:w={}:h={}:detail=50:denoise=100:deinterlace=2:format=nv12,hwdownload,format=nv12,format=yuv420p",
|
||||||
|
"-f",
|
||||||
|
"rawvideo",
|
||||||
|
],
|
||||||
|
"preset-intel-qsv-h265": [
|
||||||
|
"-vf",
|
||||||
|
"vpp_qsv=framerate={}:scale_mode=1:w={}:h={}:detail=50:denoise=100:deinterlace=2:format=nv12,hwdownload,format=nv12,format=yuv420p",
|
||||||
|
"-f",
|
||||||
|
"rawvideo",
|
||||||
|
],
|
||||||
|
"preset-amd-vaapi": [
|
||||||
|
"-vf",
|
||||||
|
"fps={},deinterlace_vaapi=rate=field:auto=1,scale_vaapi=w={}:h={},hwdownload,format=yuv420p",
|
||||||
|
"-f",
|
||||||
|
"rawvideo",
|
||||||
|
],
|
||||||
|
"preset-nvidia-h264": [
|
||||||
|
"-vf",
|
||||||
|
"fps={},scale_cuda=w={}:h={}:format=nv12,hwdownload,format=nv12,format=yuv420p",
|
||||||
|
"-f",
|
||||||
|
"rawvideo",
|
||||||
|
],
|
||||||
|
"preset-nvidia-h265": [
|
||||||
|
"-vf",
|
||||||
|
"fps={},scale_cuda=w={}:h={}:format=nv12,hwdownload,format=nv12,format=yuv420p",
|
||||||
|
"-f",
|
||||||
|
"rawvideo",
|
||||||
|
],
|
||||||
|
"default": [
|
||||||
|
"-r",
|
||||||
|
"{}",
|
||||||
|
"-s",
|
||||||
|
"{}",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
def parse_preset_hardware_acceleration(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."""
|
||||||
if not isinstance(arg, str):
|
if not isinstance(arg, str):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return PRESETS_HW_ACCEL.get(arg, None)
|
return PRESETS_HW_ACCEL_DECODE.get(arg, None)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_preset_hardware_acceleration_scale(
|
||||||
|
arg: Any,
|
||||||
|
fps: int,
|
||||||
|
width: int,
|
||||||
|
height: int,
|
||||||
|
) -> list[str]:
|
||||||
|
"""Return the correct scaling preset or default preset if none is set."""
|
||||||
|
if not isinstance(arg, str):
|
||||||
|
scale = PRESETS_HW_ACCEL_SCALE["default"]
|
||||||
|
scale[1] = str(fps)
|
||||||
|
scale[3] = f"{width}x{height}"
|
||||||
|
return scale
|
||||||
|
|
||||||
|
scale = PRESETS_HW_ACCEL_SCALE.get(arg, PRESETS_HW_ACCEL_SCALE["default"])
|
||||||
|
scale[1] = scale[1].format(fps, height, width)
|
||||||
|
return scale
|
||||||
|
|
||||||
|
|
||||||
PRESETS_INPUT = {
|
PRESETS_INPUT = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user