alpha
Login
or
Join now
yemou.pink
/
scripts
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
This repository has no description
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
vidcompress: add new script
author
yemou
date
1 week ago
(Jun 13, 2026, 8:51 PM -0400)
commit
c2c96d83
c2c96d83c7888c9c12c2e5405447dfc997707549
parent
644e2637
644e2637ccb7e02ff5590d7784970cf1f37bf959
+96
-3
4 changed files
Expand all
Collapse all
Unified
Split
flake.lock
flake.nix
nix
vidcompress.nix
scritps
vidcompress
+3
-3
flake.lock
Reviewed
···
2
2
"nodes": {
3
3
"nixpkgs": {
4
4
"locked": {
5
5
-
"lastModified": 1771369470,
6
6
-
"narHash": "sha256-0NBlEBKkN3lufyvFegY4TYv5mCNHbi5OmBDrzihbBMQ=",
5
5
+
"lastModified": 1781074563,
6
6
+
"narHash": "sha256-md8WlXOlfnIeHeOScMTTHFyf2d6iaTwPl2apR5EQ3P4=",
7
7
"owner": "NixOS",
8
8
"repo": "nixpkgs",
9
9
-
"rev": "0182a361324364ae3f436a63005877674cf45efb",
9
9
+
"rev": "9ae611a455b90cf061d8f332b977e387bda8e1ca",
10
10
"type": "github"
11
11
},
12
12
"original": {
+3
flake.nix
Reviewed
···
31
31
scr = final.callPackage ./nix/scr.nix { };
32
32
thm = final.callPackage ./nix/thm.nix { };
33
33
vid2gif = final.callPackage ./nix/vid2gif.nix { };
34
34
+
vidcompress = final.callPackage ./nix/vidcompress.nix { };
34
35
yemou-scripts = final.symlinkJoin {
35
36
name = "yemou-scripts";
36
37
paths = [
···
39
40
scr
40
41
thm
41
42
vid2gif
43
43
+
vidcompress
42
44
];
43
45
};
44
46
};
···
50
52
scr = pkgs.scr;
51
53
thm = pkgs.thm;
52
54
vid2gif = pkgs.vid2gif;
55
55
+
vidcompress = pkgs.vidcompress;
53
56
yemou-scripts = pkgs.yemou-scripts;
54
57
});
55
58
};
+26
nix/vidcompress.nix
Reviewed
···
1
1
+
{
2
2
+
writeScriptBin,
3
3
+
bash,
4
4
+
coreutils,
5
5
+
ffmpeg,
6
6
+
...
7
7
+
}:
8
8
+
9
9
+
writeScriptBin "vidcompress" (
10
10
+
builtins.replaceStrings
11
11
+
[
12
12
+
"#!/bin/sh"
13
13
+
"ffmpeg "
14
14
+
"ffprobe "
15
15
+
"printf "
16
16
+
"rm "
17
17
+
]
18
18
+
[
19
19
+
"#!${bash}/bin/sh"
20
20
+
"${ffmpeg}/bin/ffmpeg "
21
21
+
"${ffmpeg}/bin/ffprobe "
22
22
+
"${coreutils}/bin/printf "
23
23
+
"${coreutils}/bin/rm "
24
24
+
]
25
25
+
(builtins.readFile ../scritps/vidcompress)
26
26
+
)
+64
scritps/vidcompress
Reviewed
···
1
1
+
#!/bin/sh
2
2
+
usage() {
3
3
+
printf '%b\n' "${0##*/} -i <input_file> [OPTIONS]" \
4
4
+
"\noptions:" \
5
5
+
"\t-c CODEC - video codec to use (default: libx264)" \
6
6
+
"\t-h - display this message" \
7
7
+
"\t-o FILE - output file (default: out.ext)" \
8
8
+
"\t-p PRESET - ffmpeg encoding preset to use (default: veryslow)" \
9
9
+
"\t-t FILE_SIZE - file size to target in MiB (default: 50)"
10
10
+
}
11
11
+
12
12
+
while [ "$*" ]
13
13
+
do
14
14
+
case $1 in
15
15
+
- ) shift; continue ;;
16
16
+
-- ) shift; break ;;
17
17
+
-* ) flag=${1#-}; shift ;;
18
18
+
* ) shift; continue ;;
19
19
+
esac
20
20
+
21
21
+
while [ "$flag" ]
22
22
+
do
23
23
+
arg=${flag%"${flag#?}"}
24
24
+
25
25
+
case $arg in
26
26
+
c ) VIDCOMP_CODEC=$1; shift ;;
27
27
+
h ) usage; exit 0 ;;
28
28
+
i ) VIDCOMP_INPUT_FILE=$1; shift ;;
29
29
+
o ) VIDCOMP_OUTPUT_FILE=$1; shift ;;
30
30
+
t ) VIDCOMP_TARGET_SIZE=$1; shift ;;
31
31
+
* ) printf '%s\n' "${0##*/}: -$arg: invalid argument" 1>&2
32
32
+
usage 1>&2; exit 1 ;;
33
33
+
esac
34
34
+
35
35
+
flag=${flag#?}
36
36
+
done
37
37
+
done
38
38
+
39
39
+
[ -z "$VIDCOMP_INPUT_FILE" ] && {
40
40
+
printf '%s\n' "${0##*/}: missing input video" 1>&2
41
41
+
usage 1>&2; exit 1
42
42
+
}
43
43
+
44
44
+
ext="${VIDCOMP_INPUT_FILE##.*}"
45
45
+
: "${VIDCOMP_OUTPUT_FILE:=out.${ext}}"
46
46
+
47
47
+
: "${VIDCOMP_CODEC:=libx264}"
48
48
+
: "${VIDCOMP_TARGET_SIZE:=50}"
49
49
+
: "${VIDCOMP_PRESET:=veryslow}"
50
50
+
51
51
+
a_bitrate="$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 \
52
52
+
"${VIDCOMP_INPUT_FILE}")"
53
53
+
secs="$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${VIDCOMP_INPUT_FILE}")"
54
54
+
bitrate="$(fend floor \("${VIDCOMP_TARGET_SIZE} * 8388.608 / ${secs}" - \("${a_bitrate}" / 1000\)\))"
55
55
+
56
56
+
ffmpeg -hide_banner -loglevel warning \
57
57
+
-i "${VIDCOMP_INPUT_FILE}" -c:v "${VIDCOMP_CODEC}" -b:v "${bitrate}k" -preset "${VIDCOMP_PRESET}" -pass 1 \
58
58
+
-an -f null -y /dev/null && \
59
59
+
ffmpeg -hide_banner -loglevel warning \
60
60
+
-i "${VIDCOMP_INPUT_FILE}" -c:v "${VIDCOMP_CODEC}" -b:v "${bitrate}k" -preset "${VIDCOMP_PRESET}" -pass 2 \
61
61
+
-c:a copy "${VIDCOMP_OUTPUT_FILE}"
62
62
+
63
63
+
rm ffmpeg2pass*.log
64
64
+
rm ffmpeg2pass*.log.mbtree