]> git.plutz.net Git - serve0/commitdiff
omit unnessecary decoding in ffmpeg thumbnail generation
authorPaul Hänsch <paul@plutz.net>
Sat, 2 Oct 2021 19:37:14 +0000 (21:37 +0200)
committerPaul Hänsch <paul@plutz.net>
Sat, 2 Oct 2021 19:37:14 +0000 (21:37 +0200)
thumbnail.sh

index 0940a5e0cbd5a58f37dc3a200cc07514cfcfec75..4a6f828b846f7a213830ff8361afafb79dac0707 100644 (file)
@@ -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}"