]> git.plutz.net Git - serve0/blobdiff - helpers/genthumb.sh
tagging engine
[serve0] / helpers / genthumb.sh
diff --git a/helpers/genthumb.sh b/helpers/genthumb.sh
new file mode 100755 (executable)
index 0000000..625b729
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/zsh
+
+video="$1"
+thumb="$2"
+
+eval $(mplayer -really-quiet -identify -frames 0 -ao null -vo null "$video" 2>/dev/null |sed -rn 's:ID_VIDEO_WIDTH=(.*):width=\1:p;s:ID_VIDEO_HEIGHT=(.*):height=\1:p;s:ID_LENGTH=(.*)(\..*)$:length=\1:p;')
+
+[ -z "$length" -o -z "$width" -o -z "$height" ] && exit 0
+
+if [ "$(($height*1000/$width))" -gt "750" ]; then
+  width="$((75*$width/$height))"
+  height=75
+else
+  height="$((100*$height/$width))"
+  width=100
+fi
+[ -z $width ] && width=100
+[ -z $height ] && height=100
+chunk="$(($length / 5))"
+
+for cnt in 1 2 3 4; do
+  debug mplayer -nosound -vo jpeg -frames 10 -vf "scale=$width:$height" -ss "$(($cnt*$chunk))" "$video"
+  mplayer -nosound -vo jpeg -frames 10 -vf "scale=$width:$height" -ss "$(($cnt*$chunk))" "$video" >/dev/null 2>/dev/null &
+  mpid="$!"; watch=0
+  while (ps -p "$mpid" >/dev/null 2>/dev/null); do
+      [ "$watch" -gt 10 ] && kill -9 "$mpid" || sleep 1
+      watch="$(($watch+1))"
+  done
+  cp -f 00000009.jpg "${thumb}-${cnt}.jpg" 2>/dev/null
+done
+montage "${thumb}-"[1234]".jpg" -tile 2x2+0+0 -geometry 100x75+3+3 -background "#000000" "${thumb}" 2>/dev/null
+rm 000000[01][0-9].jpg "${thumb}-"[1234]".jpg" 2>/dev/null
+