forked from Github/frigate
Set User Agent for FFmpeg calls (#4555)
* Set User Agent for FFmpeg calls * Allow to use shell-like string args * Add test for arg as string with space
This commit is contained in:
@@ -32,6 +32,7 @@ from frigate.ffmpeg_presets import (
|
||||
parse_preset_output_record,
|
||||
parse_preset_output_rtmp,
|
||||
)
|
||||
from frigate.version import VERSION
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -357,7 +358,13 @@ class BirdseyeCameraConfig(BaseModel):
|
||||
)
|
||||
|
||||
|
||||
FFMPEG_GLOBAL_ARGS_DEFAULT = ["-hide_banner", "-loglevel", "warning"]
|
||||
FFMPEG_GLOBAL_ARGS_DEFAULT = [
|
||||
"-hide_banner",
|
||||
"-loglevel",
|
||||
"warning",
|
||||
"-user_agent",
|
||||
f"FFmpeg Frigate/{VERSION}",
|
||||
]
|
||||
FFMPEG_INPUT_ARGS_DEFAULT = [
|
||||
"-avoid_negative_ts",
|
||||
"make_zero",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import unittest
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.config import FFMPEG_INPUT_ARGS_DEFAULT, FrigateConfig
|
||||
from frigate.ffmpeg_presets import parse_preset_input
|
||||
|
||||
|
||||
@@ -93,6 +93,16 @@ class TestFfmpegPresets(unittest.TestCase):
|
||||
" ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"])
|
||||
)
|
||||
|
||||
def test_ffmpeg_input_args_as_string(self):
|
||||
argsString = " ".join(FFMPEG_INPUT_ARGS_DEFAULT) + ' -some "arg with space"'
|
||||
argsList = FFMPEG_INPUT_ARGS_DEFAULT + ["-some", "arg with space"]
|
||||
self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["input_args"] = argsString
|
||||
frigate_config = FrigateConfig(**self.default_ffmpeg)
|
||||
frigate_config.cameras["back"].create_ffmpeg_cmds()
|
||||
assert set(argsList).issubset(
|
||||
frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]
|
||||
)
|
||||
|
||||
def test_ffmpeg_input_not_preset(self):
|
||||
self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["input_args"] = "-some inputs"
|
||||
frigate_config = FrigateConfig(**self.default_ffmpeg)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import copy
|
||||
import datetime
|
||||
import logging
|
||||
import shlex
|
||||
import subprocess as sp
|
||||
import json
|
||||
import re
|
||||
@@ -888,7 +889,7 @@ def vainfo_hwaccel() -> sp.CompletedProcess:
|
||||
|
||||
def get_ffmpeg_arg_list(arg: Any) -> list:
|
||||
"""Use arg if list or convert to list format."""
|
||||
return arg if isinstance(arg, list) else arg.split(" ")
|
||||
return arg if isinstance(arg, list) else shlex.split(arg)
|
||||
|
||||
|
||||
class FrameManager(ABC):
|
||||
|
||||
Reference in New Issue
Block a user