summaryrefslogtreecommitdiff
path: root/video/slideshow
blob: 0d46038559de7df7f9010f2269548e3d6e9b7945 (plain)
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
#!/bin/sh
# settings
ms_per_frame=5000
resolution=1920x1080
output=output.mkv

# dependency check
! command -v ffmpeg > /dev/null && echo "Missing dependency: ffmpeg" && exit 1
! command -v magick > /dev/null && echo "Missing dependency: magick" && exit 1

# calc runtime (for fun)
intdiv() { echo $(($1 / $2)).$((($1 % $2) * 1000 / $2)); }  # calc decimal using integer arithmetic
hms_from_ms() { printf '%02d:%02d:%02d' $(($1 / 3600000)) $((($1 % 3600000) / 60000)) $((($1 % 60000) / 1000)); }
ctime() { t=$(date +%s) && echo $(( t * 1000 )); }
framerate=$(intdiv 1000 $ms_per_frame)
runtime=$(hms_from_ms $((ms_per_frame * $#)))

echo "Creating a slideshow ($output) consisting of $# images at $(intdiv $ms_per_frame 1000) seconds per frame for a total runtime of approximately $runtime"
count=0
stime=$(ctime)

# slideshow
for img in "$@"; do
	count=$((count + 1))
	etime=$(ctime)
	elapsed=$(hms_from_ms $(( etime - stime )))
	printf '[%0*d/%d] (elapsed %s) %s\n' ${##} $count $# $elapsed "$img" >&2

	magick "$img" \
		-auto-orient \
		-resize $resolution \
		-background black \
		-gravity center \
		-extent $resolution \
		-depth 8 \
		rgb:-
done | ffmpeg -y -v error \
	-f rawvideo \
	-video_size $resolution \
	-pixel_format rgb24 \
	-framerate $framerate \
	-probesize 32 \
	-analyzeduration 0 \
	-i - \
	-vf "fps=1,framerate=30:interp_start=0:interp_end=255:scene=100" \
	-c:v libx264 \
	-crf 22 \
	-preset ultrafast \
	-tune stillimage \
	$output