Skip to content

Commit 4523c9b

Browse files
authored
Set User Agent for FFmpeg calls (blakeblackshear#4555)
* Set User Agent for FFmpeg calls * Allow to use shell-like string args * Add test for arg as string with space
1 parent 5ad3919 commit 4523c9b

File tree

8 files changed

+40
-6
lines changed

8 files changed

+40
-6
lines changed

.devcontainer/devcontainer.json

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
"editor.formatOnPaste": false,
6161
"editor.formatOnSave": true,
6262
"editor.formatOnType": true,
63+
"python.testing.pytestEnabled": false,
64+
"python.testing.unittestEnabled": true,
65+
"python.testing.unittestArgs": ["-v", "-s", "./frigate/test"],
6366
"files.trimTrailingWhitespace": true,
6467
"eslint.workingDirectories": ["./web"],
6568
"[json][jsonc]": {

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
*.pyc
33
*.swp
44
debug
5-
.vscode
5+
.vscode/*
6+
!.vscode/launch.json
67
config/config.yml
78
models
89
*.mp4

.vscode/launch.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Python: Launch Frigate",
6+
"type": "python",
7+
"request": "launch",
8+
"module": "frigate",
9+
"justMyCode": true
10+
}
11+
]
12+
}

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ build: version amd64 arm64 armv7
3030
push: build
3131
docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag $(IMAGE_REPO):${GITHUB_REF_NAME}-$(COMMIT_HASH) .
3232

33-
run_tests: frigate
33+
run_tests: local
3434
docker run --rm --entrypoint=python3 frigate:latest -u -m unittest
3535
docker run --rm --entrypoint=python3 frigate:latest -u -m mypy --config-file frigate/mypy.ini frigate
3636

docs/docs/configuration/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ birdseye:
142142
# Optional: ffmpeg configuration
143143
ffmpeg:
144144
# Optional: global ffmpeg args (default: shown below)
145-
global_args: -hide_banner -loglevel warning
145+
global_args: -hide_banner -loglevel warning -user_agent "FFmpeg Frigate"
146146
# Optional: global hwaccel args (default: shown below)
147147
# NOTE: See hardware acceleration docs for your specific device
148148
hwaccel_args: []

frigate/config.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
parse_preset_output_record,
3333
parse_preset_output_rtmp,
3434
)
35+
from frigate.version import VERSION
3536

3637
logger = logging.getLogger(__name__)
3738

@@ -357,7 +358,13 @@ class BirdseyeCameraConfig(BaseModel):
357358
)
358359

359360

360-
FFMPEG_GLOBAL_ARGS_DEFAULT = ["-hide_banner", "-loglevel", "warning"]
361+
FFMPEG_GLOBAL_ARGS_DEFAULT = [
362+
"-hide_banner",
363+
"-loglevel",
364+
"warning",
365+
"-user_agent",
366+
f"FFmpeg Frigate/{VERSION}",
367+
]
361368
FFMPEG_INPUT_ARGS_DEFAULT = [
362369
"-avoid_negative_ts",
363370
"make_zero",

frigate/test/test_ffmpeg_presets.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from frigate.config import FrigateConfig
2+
from frigate.config import FFMPEG_INPUT_ARGS_DEFAULT, FrigateConfig
33
from frigate.ffmpeg_presets import parse_preset_input
44

55

@@ -93,6 +93,16 @@ def test_ffmpeg_input_preset(self):
9393
" ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"])
9494
)
9595

96+
def test_ffmpeg_input_args_as_string(self):
97+
argsString = " ".join(FFMPEG_INPUT_ARGS_DEFAULT) + ' -some "arg with space"'
98+
argsList = FFMPEG_INPUT_ARGS_DEFAULT + ["-some", "arg with space"]
99+
self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["input_args"] = argsString
100+
frigate_config = FrigateConfig(**self.default_ffmpeg)
101+
frigate_config.cameras["back"].create_ffmpeg_cmds()
102+
assert set(argsList).issubset(
103+
frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]
104+
)
105+
96106
def test_ffmpeg_input_not_preset(self):
97107
self.default_ffmpeg["cameras"]["back"]["ffmpeg"]["input_args"] = "-some inputs"
98108
frigate_config = FrigateConfig(**self.default_ffmpeg)

frigate/util.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import copy
22
import datetime
33
import logging
4+
import shlex
45
import subprocess as sp
56
import json
67
import re
@@ -888,7 +889,7 @@ def vainfo_hwaccel() -> sp.CompletedProcess:
888889

889890
def get_ffmpeg_arg_list(arg: Any) -> list:
890891
"""Use arg if list or convert to list format."""
891-
return arg if isinstance(arg, list) else arg.split(" ")
892+
return arg if isinstance(arg, list) else shlex.split(arg)
892893

893894

894895
class FrameManager(ABC):

0 commit comments

Comments
 (0)