From a239b304b2c9c58b9efc1990033fae701785c023 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 7 Aug 2015 00:02:27 +0000 Subject: [PATCH] work in a tmp directory to allow multiple instances svn path=/trunk/; revision=78 --- helpers/genthumb.sh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/helpers/genthumb.sh b/helpers/genthumb.sh index 625b729..30179b6 100755 --- a/helpers/genthumb.sh +++ b/helpers/genthumb.sh @@ -2,32 +2,32 @@ video="$1" thumb="$2" +exec >/dev/null 2>/dev/null -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;') +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 -if [ "$(($height*1000/$width))" -gt "750" ]; then - width="$((75*$width/$height))" - height=75 -else - height="$((100*$height/$width))" - width=100 -fi +[ "$(($height*1000/$width))" -gt "750" ] && width="$((75*$width/$height))" \ + || width=100 [ -z $width ] && width=100 -[ -z $height ] && height=100 chunk="$(($length / 5))" +tmp="$(mktemp -d)" + for cnt in 1 2 3 4; do - debug mplayer -nosound -vo jpeg -frames 10 -vf "scale=$width:$height" -ss "$(($cnt*$chunk))" "$video" - mplayer -nosound -vo jpeg -frames 10 -vf "scale=$width:$height" -ss "$(($cnt*$chunk))" "$video" >/dev/null 2>/dev/null & - mpid="$!"; watch=0 - while (ps -p "$mpid" >/dev/null 2>/dev/null); do - [ "$watch" -gt 10 ] && kill -9 "$mpid" || sleep 1 - watch="$(($watch+1))" + 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 done - cp -f 00000009.jpg "${thumb}-${cnt}.jpg" 2>/dev/null + ps -p "$mpid" && kill -9 "$mpid" + mv "$tmp/00000001.jpg" "${tmp}/${thumb}-${cnt}.jpg" done -montage "${thumb}-"[1234]".jpg" -tile 2x2+0+0 -geometry 100x75+3+3 -background "#000000" "${thumb}" 2>/dev/null -rm 000000[01][0-9].jpg "${thumb}-"[1234]".jpg" 2>/dev/null +montage "${tmp}/${thumb}"-[1234].jpg -tile 2x2+0+0 -geometry 100x75+3+3 -background '#000000' "${thumb}" +rm -r "${tmp}" -- 2.39.2