Skip to content

Instantly share code, notes, and snippets.

Created March 25, 2016 15:53
Show Gist options
  • Save anonymous/1375e90fabde4b3a6288 to your computer and use it in GitHub Desktop.
Save anonymous/1375e90fabde4b3a6288 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -ex
# Settings.
preview_background=\#ececec
font_size=12
out_path=preview.png
num_rows=10
num_cols=5
frame_width=192
video_stream=0:v:0
in_path="$1"
[[ -f "${in_path}" ]] || exit 1
entries="format=filename,size,duration:stream=width,height"
eval "$(ffprobe -v quiet \
-of default=nw=1 -show_entries "${entries}" \
-select_streams "${video_stream}" \
"${in_path}"
)"
duration=${duration%.*}
num_frames=$((num_rows * num_cols))
interval=$((duration / num_frames))
ffmpeg -v warning -i "${in_path}" -map "${video_stream}" -vf "
fps=1/${interval},
scale=${frame_width}:-1,
tile=${num_cols}x${num_rows}:padding=8:color=${preview_background},
pad=iw+18:ih+90:(ow-iw)/2:oh-ih-10:color=${preview_background},
drawtext=text='Имя файла\: ${filename}':x=9:y=12:fontsize=${font_size},
drawtext=text='Размер файла\: ${size} байт':x=9:y=28:fontsize=${font_size},
drawtext=text='Разрешение\: ${width}x${height}':x=9:y=44:fontsize=${font_size},
drawtext=text='Длительность\: ${duration}':x=9:y=60:fontsize=${font_size}
" -frames:v 1 -y "${out_path}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment