]> git.plutz.net Git - serve0/commitdiff
quicker thumbnail generation using ffmpeg
authorPaul Hänsch <paul@plutz.net>
Sat, 2 Oct 2021 14:19:01 +0000 (16:19 +0200)
committerPaul Hänsch <paul@plutz.net>
Sat, 2 Oct 2021 14:19:01 +0000 (16:19 +0200)
thumbnail.sh

index 8698627f37a538efd72e728100fad5a307ed4031..0940a5e0cbd5a58f37dc3a200cc07514cfcfec75 100644 (file)
@@ -4,37 +4,18 @@
 include_thumbnails="$0"
 
 gen_thumb(){
-  file="$1"; thumb="$2";
+  local file="$1" thumb="$2" tmp="${TMPDIR:-/tmp}/serve0tmp_$$/" lenght
 
-  if [ "${file%.part}" = "${file}" ] && [ ! -s "$thumb" ] && [ -s "$file" ]; then
-    l="$(
-      printf '' \
-      | mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$file" 2>&- \
-      | sed -rn 's:ID_LENGTH=(.*)(\..*)$:\1:p;' \
+  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;'
     )"
   
-    chunk="$((${l:-10} / 11))"
-    
-    tmp="$(mktemp -d)"
-    for cnt in 1 2 3 4 5 6 7 8 9 10; do
-      printf '' \
-      | mplayer -input nodefault-bindings -nosound -benchmark \
-                -noconfig all -really-quiet \
-                -frames 1 -ss "$((cnt * chunk))" \
-                -vf framestep=I \
-                -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 expand=:::::16/9,scale=320:-2,tile=10:1:10:0:0 \
-              -vo jpeg:quality=100:outdir="${tmp}"\
-              "mf://$tmp/_*.jpg" 2>&-
-  
-    #mv "${tmp}/00000001.jpg" "$thumb"
-    convert "${tmp}/00000001.jpg" -interlace line -quality 85 "$thumb"
-    rm -r "${tmp}"
+    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
 }