]> git.plutz.net Git - serve0/blob - helpers/genthumb.sh
work in a tmp directory to allow multiple instances
[serve0] / helpers / genthumb.sh
1 #!/bin/zsh
2
3 video="$1"
4 thumb="$2"
5 exec >/dev/null 2>/dev/null
6
7 mplayer -really-quiet -identify -frames 0 -nosound -vo null "$video" \
8 | sed -rn 's:ID_VIDEO_WIDTH=(.*):\1:p;
9            s:ID_VIDEO_HEIGHT=(.*):\1:p;
10            s:ID_LENGTH=(.*)(\..*)$:\1:p;' \
11 | tr '\n' ' ' \
12 | read width height length
13
14 [ -z "$length" -o -z "$width" -o -z "$height" ] && exit 0
15
16 [ "$(($height*1000/$width))" -gt "750" ] && width="$((75*$width/$height))" \
17                                          || width=100
18 [ -z $width ] && width=100
19 chunk="$(($length / 5))"
20
21 tmp="$(mktemp -d)"
22
23 for cnt in 1 2 3 4; do
24   mplayer -nosound -vo jpeg:outdir="$tmp" -frames 1 -benchmark -vf framestep=I,scale="$width":-2 -ss "$(($cnt*$chunk))" "$video" &
25   mpid="$!"; for watch in {1..10}; do
26     ps -p "$mpid" && sleep 1
27   done
28   ps -p "$mpid" && kill -9 "$mpid"
29   mv "$tmp/00000001.jpg" "${tmp}/${thumb}-${cnt}.jpg"
30 done
31 montage "${tmp}/${thumb}"-[1234].jpg -tile 2x2+0+0 -geometry 100x75+3+3 -background '#000000' "${thumb}"
32 rm -r "${tmp}"
33