Skip to content

Commit c9a98dd

Browse files
committed
Refactor ffmpeg command into function ♻️
1 parent 18b83cc commit c9a98dd

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

lib/constructors.nix

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33

44
with lib;
55

6-
let generatePalette =
7-
{ image, polarity }:
8-
# TODO: make base16.nix able to load this file directly, rather than importing it here
9-
let palette = pkgs.runCommand "palette.json" { } ''
10-
${palette-generator}/bin/palette-generator ${polarity} ${image} $out
11-
'';
12-
in importJSON palette;
6+
let
7+
generatePalette =
8+
{ image, polarity }:
9+
# TODO: make base16.nix able to load this file directly, rather than importing it here
10+
let palette = pkgs.runCommand "palette.json" { } ''
11+
${palette-generator}/bin/palette-generator ${polarity} ${image} $out
12+
'';
13+
in importJSON palette;
14+
15+
extractFirstFrame =
16+
input:
17+
pkgs.runCommand "first-frame.png" { } ''
18+
${pkgs.ffmpeg}/bin/ffmpeg -i ${input} -vf 'select=eq(n\,0)' -vframes 1 $out
19+
'';
1320

1421
in {
1522
config.lib.stylix = {
@@ -30,29 +37,25 @@ in {
3037

3138
mkAnimation =
3239
{ animation, polarity ? "either" }:
33-
let image = pkgs.runCommand "image.png" { } ''
34-
${pkgs.ffmpeg}/bin/ffmpeg -i ${animation} -vf "select=eq(n\,0)" -q:v 3 -f image2 $out
35-
'';
36-
in {
37-
inherit image animation;
40+
rec {
41+
inherit animation;
42+
image = extractFirstFrame animation;
3843
colors = generatePalette { inherit image polarity; };
3944
};
4045

4146
mkVideo =
4247
{ video, polarity ? "either" }:
43-
let image = pkgs.runCommand "image.png" { } ''
44-
${pkgs.ffmpeg}/bin/ffmpeg -i ${video} -vf "select=eq(n\,0)" -q:v 3 -f image2 $out
45-
'';
46-
in {
47-
inherit image video;
48+
rec {
49+
inherit video;
50+
image = extractFirstFrame video;
4851
colors = generatePalette { inherit image polarity; };
4952
};
5053

5154
mkSlideshow =
5255
{ images, delay ? 300, polarity ? "either" }:
53-
let image = builtins.elemAt images 0;
54-
in {
55-
inherit image images delay;
56+
rec {
57+
inherit images delay;
58+
image = builtins.elemAt images 0;
5659
colors = generatePalette { inherit image polarity; };
5760
};
5861
};

0 commit comments

Comments
 (0)