#!/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" tmp="${TMPDIR:-/tmp}/serve0tmp_$$/" lenght
- [ "$((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 stream=duration "$file" 2>&- \
+ | sed -nE 's;duration=([0-9\.]+)\r?$;\1;p;'
+ )"
- 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: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=127:-2,tile=2:2:4:0:2 \
- -vo "jpeg:quality=60:outdir=${tmp}"\
- "mf://$tmp/_*.jpg" 2>&-
-
- mv "${tmp}/00000001.jpg" "$thumb"
- rm -r "${tmp}"
-
-elif [ \! -e "$thumb" ]; then
- touch "$thumb"
-fi
+ ffmpeg -nostdin -y -i "$file" -vf scale=320:-2,fps=10/$length "$tmp/thumb_%02d.jpg" 2>&-
+ montage "$tmp/thumb_0"[1-9].jpg "$tmp/thumb_10.jpg" \
+ -tile 10x1 -geometry 320x180+0+0 \
+ -interlace line -quality 85 "$thumb"
+ rm -r -- "${tmp}"
+ fi
+}