]> git.plutz.net Git - serve0/blob - thumbnail.sh
improved tag caching, removed obsolete HTML unescaping
[serve0] / thumbnail.sh
1 #!/bin/sh
2
3 [ -n "$include_thumbnails" ] && return 0
4 include_thumbnails="$0"
5
6 gen_thumb(){
7   file="$1"; thumb="$2";
8
9   if [ ! -e "$thumb" ] && [ -f "$file" ]; then
10     l="$(
11       printf '' \
12       | mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$file" 2>&- \
13       | sed -rn 's:ID_LENGTH=(.*)(\..*)$:\1:p;' \
14     )"
15   
16     chunk="$((${l:-10} / 5))"
17     
18     tmp="$(mktemp -d)"
19     for cnt in 1 2 3 4; do
20       printf '' \
21       | mplayer -input nodefault-bindings -nosound -benchmark \
22                 -noconfig all -really-quiet \
23                 -frames 1 -ss "$((cnt * chunk))" \
24                 -vf framestep=I \
25                 -vo jpeg:quality=100:outdir="${tmp}" \
26                 "$file" 2>&-
27       mv "${tmp}/00000001.jpg" "${tmp}/_${cnt}.jpg"
28     done
29     printf '' \
30     | mplayer -input nodefault-bindings -nosound -benchmark \
31               -noconfig all -really-quiet \
32               -vf scale=159:-2,tile=2:2:4:0:2 \
33               -vo jpeg:quality=96:outdir="${tmp}"\
34               "mf://$tmp/_*.jpg" 2>&-
35   
36     mv "${tmp}/00000001.jpg" "$thumb"
37     rm -r "${tmp}"
38   
39   elif [ ! -e "$thumb" ]; then
40     touch "$thumb"
41   fi
42 }