Skip to content

Instantly share code, notes, and snippets.

@deanputney
Created August 23, 2012 04:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deanputney/3432459 to your computer and use it in GitHub Desktop.
Save deanputney/3432459 to your computer and use it in GitHub Desktop.
Giffer - Make gifs from any video
#!/bin/bash
# Installation:
#
# Get yourself ffmpeg and imagemagick.
# brew install ffmpeg
# brew install imagemagick
#
# I put this script at ~/script/giffer.sh and aliased it to giffer.sh
# alias giffer=/Users/<your_username>/scripts/giffer.sh
#
# YOU'RE GOOD TO GO! http://deansli.st/archives/6411
# Usage:
#
# ./giffer.sh path/to/video_file.whatever <starting_point> <duration> output_file_name
#
# starting_point and duration are in seconds, can also be in fractions of seconds with leading 0 if less than one.
# output_file_name will have .gif appended to it.
# Currently the file is dropped out to /tmp/gif. Future versions should move it to the current directory.
mkdir /tmp/gif;
if [ -n "$4" ]
then
echo "Saving to "$4".gif";
else
$4 = $1;
fi
cp $1 /tmp/gif/$4;
# echo "cp $1 /tmp/gif/$4";
# cp $1 /tmp/gif/$4;
cd /tmp/gif;
echo "Starting at $2 for a duration of $3 seconds.";
echo "Making images from film...";
ffmpeg -ss $2 -t $3 -i "$1" -r 15 /tmp/gif/image-%04d.png;
echo "Making 1000 pixel wide gif...";
mkdir gif1000;
for image in image-*.png
do
convert $image -resize '1000>' gif1000/$image;
done
mogrify -resample 72x72 -resize '500>' gif1000/*;
convert -delay 1 -loop 0 gif1000/image-*.png -coalesce -fuzz 5% -channel A -threshold 50% -layers OptimizeTransparency +map $4.gif;
# convert -delay 1 -loop 0 gif1000/image-*.png +map $4.gif;
echo "Making 500 pixel wide gif...";
convert $4.gif -resize '500' $4_500.gif;
echo "Cleaning up...";
rm image*;
rm -rf /tmp/gif/gif1000;
# rm -rf /tmp/gif;
echo "Done!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment