]> git.plutz.net Git - serve0/blob - helpers/genthumb.sh
tagging engine
[serve0] / helpers / genthumb.sh
1 #!/bin/zsh
2
3 video="$1"
4 thumb="$2"
5
6 eval $(mplayer -really-quiet -identify -frames 0 -ao null -vo null "$video" 2>/dev/null |sed -rn 's:ID_VIDEO_WIDTH=(.*):width=\1:p;s:ID_VIDEO_HEIGHT=(.*):height=\1:p;s:ID_LENGTH=(.*)(\..*)$:length=\1:p;')
7
8 [ -z "$length" -o -z "$width" -o -z "$height" ] && exit 0
9
10 if [ "$(($height*1000/$width))" -gt "750" ]; then
11   width="$((75*$width/$height))"
12   height=75
13 else
14   height="$((100*$height/$width))"
15   width=100
16 fi
17 [ -z $width ] && width=100
18 [ -z $height ] && height=100
19 chunk="$(($length / 5))"
20
21 for cnt in 1 2 3 4; do
22   debug mplayer -nosound -vo jpeg -frames 10 -vf "scale=$width:$height" -ss "$(($cnt*$chunk))" "$video"
23   mplayer -nosound -vo jpeg -frames 10 -vf "scale=$width:$height" -ss "$(($cnt*$chunk))" "$video" >/dev/null 2>/dev/null &
24   mpid="$!"; watch=0
25   while (ps -p "$mpid" >/dev/null 2>/dev/null); do
26       [ "$watch" -gt 10 ] && kill -9 "$mpid" || sleep 1
27       watch="$(($watch+1))"
28   done
29   cp -f 00000009.jpg "${thumb}-${cnt}.jpg" 2>/dev/null
30 done
31 montage "${thumb}-"[1234]".jpg" -tile 2x2+0+0 -geometry 100x75+3+3 -background "#000000" "${thumb}" 2>/dev/null
32 rm 000000[01][0-9].jpg "${thumb}-"[1234]".jpg" 2>/dev/null
33