From 06af2f639193f9e2de0bae67125b66665c327e8f Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 7 Aug 2015 23:01:47 +0000 Subject: [PATCH] enable background thumb generation svn path=/trunk/; revision=80 --- helpers/genall.sh | 1 - helpers/genmeta.sh | 9 +++++---- helpers/genthumb.sh | 49 ++++++++++++++++++++------------------------- pages/common.sh | 20 ++++++++++++------ 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/helpers/genall.sh b/helpers/genall.sh index 6aab046..eb6d6f3 100755 --- a/helpers/genall.sh +++ b/helpers/genall.sh @@ -7,7 +7,6 @@ genthumb="$dir/genthumb.sh" addtag(){ meta="$1" - info="$(basename "$1" |sed -r 's:^(.+)\.meta$:\1:')" tag="$2" length=0; width=0; height=0; diff --git a/helpers/genmeta.sh b/helpers/genmeta.sh index c41c491..4fa28e4 100755 --- a/helpers/genmeta.sh +++ b/helpers/genmeta.sh @@ -8,12 +8,13 @@ if [ -r "$meta" ]; then description="$(sed -n '3,$p' "$meta")" fi -mplayer -really-quiet -identify -frames 0 -nosound -vo null "$video" \ -| sed -rn 's:ID_VIDEO_WIDTH=(.*):\1:p; +mplayer --input=nodefault-bindings:conf=/dev/null -nosound -vo null -identify -frames 0 "$video" \ +| sort \ +| sed -rn 's:ID_LENGTH=(.*)(\..*)$:\1:p; s:ID_VIDEO_HEIGHT=(.*):\1:p; - s:ID_LENGTH=(.*)(\..*)$:\1:p;' \ + s:ID_VIDEO_WIDTH=(.*):\1:p;' \ | tr '\n' ' ' \ -| read width height length +| read length height width cat <"$meta" ${length:-0} ${width:-0} ${height:-0} ${video##*/} 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 diff --git a/pages/common.sh b/pages/common.sh index 6257aad..cf05491 100755 --- a/pages/common.sh +++ b/pages/common.sh @@ -39,6 +39,14 @@ taglist=$( done |sort -u |grep -xv '' |tee ${_DATA}/cache/taglist ) +genthumb(){ + videofile="$(printf %s "$1" |sed -r "s;';'\\'';g")" + thumb="$(printf %s "$2" |sed -r "s;';'\\'';g")" + + printf '%s\n' "${_EXEC}/helpers/genthumb.sh '$videofile' '$thumb' >/dev/null 2>/dev/null" \ + | batch +} + _printVideo(){ info="$1" cache="${_DATA}/cache/$info.cache" @@ -48,9 +56,9 @@ _printVideo(){ cat "$cache" else videofile="${_DATA}/videos/$info" - thumb="${_DATA}/thumbs/$info.jpg" - [ -r "$meta" ] || ${_EXEC}/helpers/genmeta.sh "$videofile" "$meta" >/dev/null - [ -r "$thumb" ] || ${_EXEC}/helpers/genthumb.sh "$videofile" "$thumb" >/dev/null + thumb="${_DATA}/thumbs/${info}.jpg" + [ -r "$thumb" ] || genthumb "$videofile" "$thumb" + [ -r "$meta" ] || "${_EXEC}/helpers/genmeta.sh" "$videofile" "$meta" >/dev/null head -n1 "$meta" |read length width height filename [ -z "$length" ] && length=0 @@ -84,9 +92,9 @@ VIDEOend genlist(){ case "$order" in - Date) ls -c ${_DATA}/videos/ |egrep -i "$file_pattern";; - Length) sed -sn 1p "${_DATA}/meta/"*.meta |sort -n |sed -r 's;^[0-9\t]+\t;;';; - Name) printf '%s\n' "${_DATA}/meta/"*meta |sed -r 's;^.*/;;;s;\.meta$;;';; + Date) ls -c "${_DATA}"/videos/ |egrep -i "$file_pattern";; + Length) sed -sn 1p "${_DATA}"/meta/*.meta |sort -n |sed -r 's;^[0-9\t]+\t;;';; + Name) printf '%s\n' "${_DATA}"/videos/* |sed -r 's;^.*/;;;';; esac } -- 2.39.2