From: Paul Hänsch Date: Sat, 2 Oct 2021 19:37:14 +0000 (+0200) Subject: omit unnessecary decoding in ffmpeg thumbnail generation X-Git-Url: http://git.plutz.net/?a=commitdiff_plain;ds=sidebyside;h=fb7c3c5f56bc3e8b7bb6d7023f386a859fa34e97;p=serve0 omit unnessecary decoding in ffmpeg thumbnail generation --- diff --git a/thumbnail.sh b/thumbnail.sh index 0940a5e..4a6f828 100644 --- a/thumbnail.sh +++ b/thumbnail.sh @@ -4,16 +4,19 @@ include_thumbnails="$0" gen_thumb(){ - local file="$1" thumb="$2" tmp="${TMPDIR:-/tmp}/serve0tmp_$$/" lenght + local file="$1" thumb="$2" tmp="${TMPDIR:-/tmp}/serve0tmp_$$/" lenght n 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;' - )" + length="$( ffprobe -show_entries stream=duration "$file" 2>&- )" + length="${length#*duration=}" length="${length%%${BR}*}" length="${length%.*}" - 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" \ + # ffmpeg -nostdin -y -i "$file" -vf fps=11/$length,scale=320:-2 -frames 10 "$tmp/thumb_%02d.jpg" 2>&- + + 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 + + montage "$tmp"/thumb_[0-9].jpg \ -tile 10x1 -geometry 320x180+0+0 \ -interlace line -quality 85 "$thumb" rm -r -- "${tmp}"