]> git.plutz.net Git - serve0/blob - thumbnail.sh
quicker thumbnail generation using ffmpeg
[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
8
9   if [ "${file%.part}" = "${file}" -a ! -s "$thumb" -a -s "$file" ] && mkdir "$tmp"; then
10     length="$(
11       ffprobe -show_entries stream=duration "$file" 2>&- \
12       | sed -nE 's;duration=([0-9\.]+)\r?$;\1;p;'
13     )"
14   
15     ffmpeg -nostdin -y -i "$file" -vf scale=320:-2,fps=10/$length "$tmp/thumb_%02d.jpg" 2>&-
16     montage "$tmp/thumb_0"[1-9].jpg "$tmp/thumb_10.jpg" \
17             -tile 10x1 -geometry 320x180+0+0 \
18             -interlace line -quality 85 "$thumb"
19     rm -r -- "${tmp}"
20   fi
21 }