-
Notifications
You must be signed in to change notification settings - Fork 4
/
ffmpeg-timelapse
executable file
·59 lines (43 loc) · 1.21 KB
/
ffmpeg-timelapse
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
#!/bin/bash
set -eu
run() {
echo >&2 "+ $*"
"$@"
}
usage() {
cat >&2 <<EOM
usage: $(basename "$0") INPUT_GLOB OUTPUT.MP4
NB: be sure to quote the INPUT_GLOB
Example:
$(basename "$0") 'photos/*.jpg' timelapse.mp4
EOM
}
if [ $# -ne 2 ]; then
usage
exit 1
fi
input_glob="$1"
output="$2"
OUTPUT_RESOLUTION="${OUTPUT_RESOLUTION-}"
IN_FRAME_RATE="${IN_FRAME_RATE-15}"
WATERMARK="${WATERMARK-}"
QUIET="${QUIET-}"
opts=()
if [ -n "$OUTPUT_RESOLUTION" ]; then
opts+=(-s:v "$OUTPUT_RESOLUTION")
fi
if [ -n "$WATERMARK" ]; then
FONTFILE="${FONTFILE-/usr/share/fonts/truetype/roboto/Roboto-Regular.ttf}"
if [ -n "$OUTPUT_RESOLUTION" ]; then
# HACK: assume input appropriate for 2592x1944
opts+=(-vf "drawtext=fontfile=$FONTFILE: text='$WATERMARK': fontcolor=white@0.8: fontsize=96: x=(w-text_w-20): y=20: borderw=2")
else
# HACK: assume 640x480
opts+=(-vf "drawtext=fontfile=$FONTFILE: text='$WATERMARK': fontcolor=white@0.8: fontsize=24: x=(w-text_w-8): y=8: borderw=1")
fi
fi
if [ -n "$QUIET" ]; then
opts+=(-nostats)
fi
run ffmpeg -f image2 -framerate "$IN_FRAME_RATE" -pattern_type glob \
-i "$input_glob" -r 30 "${opts[@]}" -vcodec libx264 "$output"