Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bjou
Created October 1, 2013 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjou/6783648 to your computer and use it in GitHub Desktop.
Save bjou/6783648 to your computer and use it in GitHub Desktop.
Script to sample frames and convert frames to gif using ffmpeg.
#!/bin/sh
# check arg inputs
verbose=false
while getopts "hi:o:s:d:p:v" opt; do
case $opt in
h)
echo ""
exit 1
;;
i)
inFile=$OPTARG
;;
o)
outDir=$OPTARG
;;
s)
startTime=$OPTARG
;;
d)
duration=$OPTARG
;;
p)
storyPrefix=$OPTARG
;;
v)
verbose=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
if $verbose ; then
echo "ffmpeg -i ""$inFile"" -vf scale=iw/2:-1 -r 2 -ss $startTime -t $duration ""$outDir""/frames%3d.png"
fi
ffmpeg -i "$inFile" -vf scale=iw/2:-1 -r 2 -ss $startTime -t $duration "$outDir"/frames%3d.png
if $verbose ; then
echo "convert -delay 7 -loop 0 ""$outDir""/frames*.png ""$outDir""/""$storyPrefix""_animation.gif"
fi
convert -delay 7 -loop 0 "$outDir"/frames*.png "$outDir"/"$storyPrefix"_animation.gif
if $verbose ; then
echo "rm ""$outDir""/frames*.png"
fi
rm "$outDir"/frames*.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment