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