X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=helpers%2Fgenthumb.sh;h=b481bd5d01c01bdfe6a64f356bdd86b258c7a10f;hb=06af2f639193f9e2de0bae67125b66665c327e8f;hp=30179b614afbb9a87d3a165f0fdfe009bc31f138;hpb=b6d914a4ee1b64a318b17207b92d791af5c8d658;p=serve0 diff --git a/helpers/genthumb.sh b/helpers/genthumb.sh index 30179b6..b481bd5 100755 --- a/helpers/genthumb.sh +++ b/helpers/genthumb.sh @@ -2,32 +2,27 @@ video="$1" thumb="$2" -exec >/dev/null 2>/dev/null -mplayer -really-quiet -identify -frames 0 -nosound -vo null "$video" \ -| sed -rn 's:ID_VIDEO_WIDTH=(.*):\1:p; - s:ID_VIDEO_HEIGHT=(.*):\1:p; - s:ID_LENGTH=(.*)(\..*)$:\1:p;' \ -| tr '\n' ' ' \ -| read width height length - -[ -z "$length" -o -z "$width" -o -z "$height" ] && exit 0 - -[ "$(($height*1000/$width))" -gt "750" ] && width="$((75*$width/$height))" \ - || width=100 -[ -z $width ] && width=100 -chunk="$(($length / 5))" - -tmp="$(mktemp -d)" - -for cnt in 1 2 3 4; do - mplayer -nosound -vo jpeg:outdir="$tmp" -frames 1 -benchmark -vf framestep=I,scale="$width":-2 -ss "$(($cnt*$chunk))" "$video" & - mpid="$!"; for watch in {1..10}; do - ps -p "$mpid" && sleep 1 +if [ -e "$video" -a \! -e "$thumb" ]; then + mplayer --input=nodefault-bindings:conf=/dev/null -nosound -vo null -frames 0 -identify "$video" \ + | sort \ + | sed -rn 's:ID_LENGTH=(.*)(\..*)$:\1:p; + s:ID_VIDEO_HEIGHT=(.*):\1:p; + s:ID_VIDEO_WIDTH=(.*):\1:p;' \ + | tr '\n' ' ' \ + | read length height width + + [ "$(($height*1000/$width))" -gt "750" ] && width="$((75*$width/$height))" \ + || width=100 + [ -z $width ] && width=100 + chunk="$((${length:-0} / 5))" + + tmp="$(mktemp -d)" + for cnt in 1 2 3 4; do + mplayer --input=nodefault-bindings:conf=/dev/null -nosound -vo jpeg:outdir="$tmp" -frames 1 \ + --benchmark -vf framestep=I,scale="$width":-2 -ss "$(($cnt*$chunk))" "$video" + mv "$tmp/00000001.jpg" "${tmp}/_${cnt}.jpg" done - ps -p "$mpid" && kill -9 "$mpid" - mv "$tmp/00000001.jpg" "${tmp}/${thumb}-${cnt}.jpg" -done -montage "${tmp}/${thumb}"-[1234].jpg -tile 2x2+0+0 -geometry 100x75+3+3 -background '#000000' "${thumb}" -rm -r "${tmp}" - + montage "${tmp}"/_[1234].jpg -tile 2x2+0+0 -geometry 100x75+3+3 -background '#000000' "${thumb}" + rm -r "${tmp}" +fi