-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathffmpeg-stabilize
executable file
·66 lines (52 loc) · 1.13 KB
/
ffmpeg-stabilize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
set -euo pipefail
run() {
echo >&2 "+ $*"
"$@"
}
cleanup() {
echo >&2 ERROR
if [ -n "${vectors-}" ]; then
rm -fv "$vectors"
fi
}
usage() {
cat >&2 <<EOM
usage: $(basename "$0") INPUT OUTPUT
Stabilize given input video using ffmpeg and vid.stab.
EOM
}
colorecho() {
# shellcheck disable=SC2230
if which colorecho >/dev/null 2>&1; then
command colorecho "$@"
else
shift
echo "$@"
fi
}
if [ $# -ne 2 ]; then
usage
exit 1
fi
input="$1"
output="$2"
TMPDIR="${TMPDIR-/tmp}"
vectors="$(mktemp "$TMPDIR/ffmpeg-stabilize.XXXXXXXX.trf")"
trap cleanup EXIT
echo >&2
colorecho >&2 cyan "Generating transform vectors..."
echo >&2
run ffmpeg -i "$input" \
-vf "vidstabdetect=stepsize=32:shakiness=10:accuracy=10:result=$vectors" \
-f null -
echo >&2
colorecho >&2 cyan "Generating output video..."
echo >&2
run ffmpeg -i "$input" \
-vf "vidstabtransform=input=$vectors:zoom=0:smoothing=10,unsharp=5:5:0.8:3:3:0.4" \
-vcodec libx264 -tune film -preset slow -acodec copy "$output"
rm -fv "$vectors"
trap - EXIT
echo >&2
colorecho >&2 cyan "All done!"