Created
February 13, 2018 19:42
-
-
Save pzillmann/d113bb0f340764f34a9d25731a6f001e to your computer and use it in GitHub Desktop.
d.tube Sprite Generation Script. License: CC0 / Public Domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 2 ]; then | |
echo | |
echo call: $0 input_file.mp4 output_file.jpg | |
exit 1 | |
fi | |
if [ "$(command -v ffmpeg)" = "" ]; then | |
echo | |
echo Error: FFmpeg not found | |
exit 1 | |
fi | |
if [ "$(command -v montage)" = "" ]; then | |
echo | |
echo Error: ImageMagick not found | |
exit 1 | |
fi | |
if [ ! -e $1 ]; then | |
echo | |
echo Error: Input File not found | |
exit 1 | |
fi | |
TEMPDIR=$(mktemp -d) | |
RUNTIME=$(ffprobe -hide_banner -loglevel error -select_streams v:0 -show_streams $1 2>/dev/null | grep duration= | sed -e 's/duration=//') | |
RUNTIME=${RUNTIME%.*} | |
if [ $RUNTIME -lt 100 ]; then | |
MAX=$RUNTIME | |
STEPS=1 | |
else | |
MAX=100 | |
STEPS=$(bc <<< "scale=2; $RUNTIME/100") | |
fi | |
printf "Extracting frames from source video " | |
for i in `seq 0 $((MAX - 1))` ; do | |
lz="" | |
if [ $i -lt 10 ]; then lz=0; fi | |
ffmpeg -hide_banner -loglevel error -accurate_seek -ss $(bc <<< $i*$STEPS) -i $1 -s 210x118 -frames:v 1 $TEMPDIR/sprite_$lz$i.bmp | |
if [ "$((i%(MAX/4)))" = 0 ]; then printf "$((i/(MAX/4)*25))%% "; fi | |
done | |
printf "100%%\nCreating sprite image\n" | |
montage $TEMPDIR/sprite_*.bmp -mode Concatenate -tile 1x$MAX $2 | |
echo Done. | |
echo Video duration: $RUNTIME seconds | |
rm -rf $TEMPDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment