]> git.plutz.net Git - serve0/blob - helpers/genthumb.sh
mplayer command line compatibility with older versions
[serve0] / helpers / genthumb.sh
1 #!/bin/zsh
2
3 video="$1"
4 thumb="$2"
5
6 if [ -e "$video" -a \! -e "$thumb" ]; then
7   echo '' |mplayer -input nodefault-bindings -nosound -vo null -frames 0 -identify "$video" \
8   | sort \
9   | sed -rn 's:^.*ID_LENGTH=(.*)(\..*)$:\1:p;
10              s:^.*ID_VIDEO_HEIGHT=(.*)$:\1:p;
11              s:^.*ID_VIDEO_WIDTH=(.*)$:\1:p;' \
12   | tr '\n' ' ' \
13   | read length height width 2>/dev/null
14   
15   [ "$(($height * 1000 / $width))" -gt "750" ] && width="$((75 * $width / $height))" \
16                                            || width=100
17   [ -z $width ] && width=100
18   chunk="$((${length:-0} / 5))"
19   
20   tmp="$(mktemp -d)"
21   for cnt in 1 2 3 4; do
22     echo '' |mplayer -input nodefault-bindings -nosound -vo jpeg:outdir="$tmp" -frames 1 \
23              -benchmark -vf framestep=I,scale="$width":-2 -ss "$(($cnt*$chunk))" "$video" >/dev/null 2>/dev/null
24     mv "$tmp/00000001.jpg" "${tmp}/_${cnt}.jpg"
25   done
26   montage "${tmp}"/_[1234].jpg -tile 2x2+0+0 -geometry 100x75+3+3 -background '#000000' "${thumb}"
27   rm -r "${tmp}"
28 fi