X-Git-Url: http://git.plutz.net/?p=serve0;a=blobdiff_plain;f=thumbnail.sh;h=143077640c049f1c35dbfbc0584607855cf6986a;hp=4e3fd3fb6298c4fcecef63f362d8edd7290a2ba2;hb=HEAD;hpb=6505a2726aa04b8b0b37af689535bde67f99238a diff --git a/thumbnail.sh b/thumbnail.sh old mode 100644 new mode 100755 index 4e3fd3f..09f5ab0 --- a/thumbnail.sh +++ b/thumbnail.sh @@ -1,44 +1,26 @@ #!/bin/sh -# Use: $index $thumb $file_pattern +[ -n "$include_thumbnails" ] && return 0 +include_thumbnails="$0" -if [ \! -e "$thumb" ] && { printf %s "$file" |grep -qE "$file_pattern"; }; then - read l h w <<__EOF - $(printf '' \ - | mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$file" 2>&- \ - | sort | sed -rn ' - s:ID_LENGTH=(.*)(\..*)$:\1:p; - s:ID_VIDEO_HEIGHT=(.*):\1:p; - s:ID_VIDEO_WIDTH=(.*):\1:p;' \ - | tr '\n' ' ' - ) -__EOF +gen_thumb(){ + local file="$1" thumb="$2" bgcolor="${3:-#000000}" + local tmp="${TMPDIR:-/tmp}/serve0tmp_$$/" lenght n - [ "$((h * 1000 / w))" -gt "750" ] \ - && w="$((75 * w / h))" || w=100 - chunk="$((${l:-10} / 5))" + if [ "${file%.part}" = "${file}" -a ! -s "$thumb" -a -s "$file" ] && mkdir "$tmp"; then + length="$( ffprobe -show_entries format=duration "$file" 2>&- )" + length="${length#*duration=}" length="${length%%${BR}*}" length="${length%.*}" - tmp="$(mktemp -d)" - for cnt in 1 2 3 4; do - printf '' \ - | mplayer -input nodefault-bindings -nosound -benchmark \ - -noconfig all -really-quiet \ - -frames 1 -ss "$((cnt * chunk))" \ - -vf "framestep=I,scale=${w}:-2" \ - -vo "jpeg:quality=100:outdir=${tmp}" \ - "$file" 2>&- - mv "${tmp}/00000001.jpg" "${tmp}/_${cnt}.jpg" - done - printf '' \ - | mplayer -input nodefault-bindings -nosound -benchmark \ - -noconfig all -really-quiet \ - -vf scale=159:-2,tile=2:2:4:0:2 \ - -vo "jpeg:quality=96:outdir=${tmp}"\ - "mf://$tmp/_*.jpg" 2>&- + # ffmpeg -nostdin -y -i "$file" -vf fps=11/$length,scale=320:-2 -frames 10 "$tmp/thumb_%02d.jpg" 2>&- - mv "${tmp}/00000001.jpg" "$thumb" - rm -r "${tmp}" + for n in 1 2 3 4 5 6 7 8 9 10; do + ffmpeg -nostdin -y -ss "$((n * length / 11))" -i "$file" -frames 1 "$tmp/thumb_$((n - 1)).jpg" 2>&- + done -elif [ \! -e "$thumb" ]; then - touch "$thumb" -fi + montage "$tmp"/thumb_[0-9].jpg \ + -background "$bgcolor" \ + -tile 10x1 -geometry 320x180+0+0 \ + -interlace line -quality 85 "$thumb" + rm -r -- "${tmp}" + fi +}