X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=helpers%2Fgenthumb.sh;h=2119d85dabf247885e468900012084b67322ac0b;hb=036ced19c16e5fe9cdab244b40f8b14b31a32fe8;hp=625b7292abfbded12ae842bce94e0dff9105380e;hpb=c7e6e63b567cd68f0a9c1f12dd92b175d2f6a2a0;p=serve0 diff --git a/helpers/genthumb.sh b/helpers/genthumb.sh index 625b729..2119d85 100755 --- a/helpers/genthumb.sh +++ b/helpers/genthumb.sh @@ -1,33 +1,44 @@ #!/bin/zsh +# Copyright 2014 - 2017 Paul Hänsch +# +# This file is part of Serve0 +# +# Serve0 is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Serve0 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Serve0 If not, see . video="$1" thumb="$2" -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;') - -[ -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 -[ -z $width ] && width=100 -[ -z $height ] && height=100 -chunk="$(($length / 5))" - -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))" +if [ -e "$video" -a \! -e "$thumb" ]; then + printf '' |mplayer -input nodefault-bindings -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 2>/dev/null + + [ "$(($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 + printf '' |mplayer -input nodefault-bindings -nosound -vo jpeg:outdir="$tmp" -frames 1 \ + -benchmark -vf framestep=I,scale="$width":-2 -ss "$(($cnt*$chunk))" "$video" >/dev/null 2>/dev/null + mv "$tmp/00000001.jpg" "${tmp}/_${cnt}.jpg" done - cp -f 00000009.jpg "${thumb}-${cnt}.jpg" 2>/dev/null -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}"/_[1234].jpg -tile 2x2+0+0 -geometry 100x75+3+3 -background '#000000' -quality 50 "${thumb}" 2>/dev/null + rm -r "${tmp}" +fi