Skip to content

Instantly share code, notes, and snippets.

@mariomartinezsz
Forked from rkfg/gifcreate
Created January 5, 2013 21:55
Show Gist options
  • Save mariomartinezsz/4463888 to your computer and use it in GitHub Desktop.
Save mariomartinezsz/4463888 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ -z "$6" ]
then
echo "Usage: `basename $0` [-n] <filename> <start time> <duration> <scale to width> <framestep> <resultname.gif>\n-n — turn off subtitles"
else
OPT=
if [ "$1" = "-n" ]
then
OPT="-nosub -noautosub"
shift
fi
STEP=$5
TEMP=`mktemp -d /tmp/mpgifXXXXXX`
FILENAME=$( readlink -f "$1" )
cd "$TEMP"
FPS=$( mplayer "$FILENAME" $OPT -ss $2 -endpos $3 -vf scale=$4:-2,framestep=$5 -nosound -vo png:z=9 2>&1 | sed -n 's/.* \([0-9]*\)\.[0-9]* fps .*/\1/p' )
DELAY=$(( 100 * STEP / FPS ))
xdg-open "$TEMP"
read -p "Now remove any excessive frames and press Enter to combine them to a nice gif." null
convert -delay $DELAY "$TEMP/*.png" -layers optimize-transparency "$6"
rm -rf "$TEMP"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment