Skip to content

Commit 6c4b180

Browse files
committed
frigate: centralize the ffmpeg flavor selection in the module
In 0.16.0 frigate added a config option to pass an ffmpeg build for the ffmpeg and ffprobe executables. Previously we unconditionally patched in ffmpeg-headless, which has now been changed to use the `ffmpeg.path` provided build, so that we don't bloat the closure with multiple ffmpegs or don't require overriding the package to select another version. In contrast to the upstream configuration we only accept packages and not the "default" string, because that would have complicated the logic needlessly.
1 parent 283a718 commit 6c4b180

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

nixos/modules/services/video/frigate.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ in
231231
};
232232
};
233233

234+
ffmpeg = {
235+
path = mkOption {
236+
type = coercedTo package toString str;
237+
default = pkgs.ffmpeg-headless;
238+
example = literalExpression "pkgs.ffmpeg-full";
239+
description = ''
240+
Package providing the ffmpeg and ffprobe executables below the bin/ directory.
241+
'';
242+
};
243+
};
244+
234245
mqtt = {
235246
enabled = mkEnableOption "MQTT support";
236247

pkgs/by-name/fr/frigate/ffmpeg.patch

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,47 @@
11
diff --git a/frigate/config/camera/ffmpeg.py b/frigate/config/camera/ffmpeg.py
2-
index 04bbfac7..4390a571 100644
2+
index 04bbfac7..396bcc4b 100644
33
--- a/frigate/config/camera/ffmpeg.py
44
+++ b/frigate/config/camera/ffmpeg.py
5-
@@ -70,18 +70,14 @@ class FfmpegConfig(FrigateBaseModel):
5+
@@ -1,4 +1,5 @@
6+
from enum import Enum
7+
+from os.path import join
8+
from typing import Union
9+
10+
from pydantic import Field, field_validator
11+
@@ -69,21 +70,11 @@ class FfmpegConfig(FrigateBaseModel):
12+
613
@property
714
def ffmpeg_path(self) -> str:
8-
if self.path == "default":
15+
- if self.path == "default":
916
- return f"/usr/lib/ffmpeg/{DEFAULT_FFMPEG_VERSION}/bin/ffmpeg"
1017
- elif self.path in INCLUDED_FFMPEG_VERSIONS:
1118
- return f"/usr/lib/ffmpeg/{self.path}/bin/ffmpeg"
12-
+ return "@ffmpeg@"
13-
else:
14-
return f"{self.path}/bin/ffmpeg"
19+
- else:
20+
- return f"{self.path}/bin/ffmpeg"
21+
+ return join(self.path, "bin/ffmpeg")
1522

1623
@property
1724
def ffprobe_path(self) -> str:
18-
if self.path == "default":
25+
- if self.path == "default":
1926
- return f"/usr/lib/ffmpeg/{DEFAULT_FFMPEG_VERSION}/bin/ffprobe"
2027
- elif self.path in INCLUDED_FFMPEG_VERSIONS:
2128
- return f"/usr/lib/ffmpeg/{self.path}/bin/ffprobe"
22-
+ return "@ffprobe@"
23-
else:
24-
return f"{self.path}/bin/ffprobe"
29+
- else:
30+
- return f"{self.path}/bin/ffprobe"
31+
+ return join(self.path, "bin/ffprobe")
32+
2533

34+
class CameraRoleEnum(str, Enum):
2635
diff --git a/frigate/record/export.py b/frigate/record/export.py
27-
index 0d3f96da..09cadbcd 100644
36+
index 0d3f96da..463bcff4 100644
2837
--- a/frigate/record/export.py
2938
+++ b/frigate/record/export.py
3039
@@ -126,7 +126,7 @@ class RecordingExporter(threading.Thread):
3140
minutes = int(diff / 60)
3241
seconds = int(diff % 60)
3342
ffmpeg_cmd = [
3443
- "/usr/lib/ffmpeg/7.0/bin/ffmpeg", # hardcode path for exports thumbnail due to missing libwebp support
35-
+ "@ffmpeg@", # hardcode path for exports thumbnail due to missing libwebp support
44+
+ FfmpegConfig.ffmpeg_path, # hardcode path for exports thumbnail due to missing libwebp support
3645
"-hide_banner",
3746
"-loglevel",
3847
"warning",
39-
~

pkgs/by-name/fr/frigate/package.nix

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
lib,
33
stdenv,
44
callPackage,
5-
replaceVars,
65
python312Packages,
76
fetchFromGitHub,
87
fetchurl,
@@ -78,11 +77,7 @@ python3Packages.buildPythonApplication rec {
7877

7978
patches = [
8079
./constants.patch
81-
82-
(replaceVars ./ffmpeg.patch {
83-
ffmpeg = lib.getExe ffmpeg-headless;
84-
ffprobe = lib.getExe' ffmpeg-headless "ffprobe";
85-
})
80+
./ffmpeg.patch
8681
];
8782

8883
postPatch = ''
@@ -205,6 +200,7 @@ python3Packages.buildPythonApplication rec {
205200
'';
206201

207202
nativeCheckInputs = with python3Packages; [
203+
ffmpeg-headless
208204
pytestCheckHook
209205
];
210206

0 commit comments

Comments
 (0)