]> git.plutz.net Git - serve0/blob - thumbnail.sh
Merge commit '46cfaab0ad63961e6d918ae5df596814fb344b4e'
[serve0] / thumbnail.sh
1 #!/bin/sh
2
3 [ -n "$include_thumbnails" ] && return 0
4 include_thumbnails="$0"
5
6 gen_thumb(){
7   local file="$1" thumb="$2" tmp="${TMPDIR:-/tmp}/serve0tmp_$$/" lenght n
8
9   if [ "${file%.part}" = "${file}" -a ! -s "$thumb" -a -s "$file" ] && mkdir "$tmp"; then
10     length="$( ffprobe -show_entries stream=duration "$file" 2>&- )"
11     length="${length#*duration=}" length="${length%%${BR}*}" length="${length%.*}"
12   
13     # ffmpeg -nostdin -y -i "$file" -vf fps=11/$length,scale=320:-2 -frames 10 "$tmp/thumb_%02d.jpg" 2>&-
14
15     for n in 1 2 3 4 5 6 7 8 9 10; do
16       ffmpeg -nostdin -y -ss "$((n * length / 11))" -i "$file" -frames 1 "$tmp/thumb_$((n - 1)).jpg" 2>&-
17     done
18
19     montage "$tmp"/thumb_[0-9].jpg \
20             -tile 10x1 -geometry 320x180+0+0 \
21             -interlace line -quality 85 "$thumb"
22     rm -r -- "${tmp}"
23   fi
24 }