]> git.plutz.net Git - serve0/blobdiff - thumbnail.sh
Merge commit 'b931bbd0c30907b9cc956d3707b26b449bf41f76'
[serve0] / thumbnail.sh
old mode 100644 (file)
new mode 100755 (executable)
index 8698627..09f5ab0
@@ -4,37 +4,23 @@
 include_thumbnails="$0"
 
 gen_thumb(){
-  file="$1"; thumb="$2";
+  local file="$1" thumb="$2" bgcolor="${3:-#000000}"
+  local tmp="${TMPDIR:-/tmp}/serve0tmp_$$/" lenght n
 
-  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 format=duration "$file" 2>&- )"
+    length="${length#*duration=}" length="${length%%${BR}*}" length="${length%.*}"
   
-    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"
+    # 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
-    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}"
+
+    montage "$tmp"/thumb_[0-9].jpg \
+            -background "$bgcolor" \
+            -tile 10x1 -geometry 320x180+0+0 \
+            -interlace line -quality 85 "$thumb"
+    rm -r -- "${tmp}"
   fi
 }