Skip to content

Instantly share code, notes, and snippets.

@kevinchappell
Last active March 26, 2016 17: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 kevinchappell/40ccb8b2a1b87f4d067c to your computer and use it in GitHub Desktop.
Save kevinchappell/40ccb8b2a1b87f4d067c to your computer and use it in GitHub Desktop.
Convert any video to GIF
#!/bin/sh
# vid2gif - converts videos to gifs
# Usage: Add vid2gif.sh to your PATH then call like:
# $ vid2gif video.mp4 video.gif
#
# To add to context menu, create command that calls:
# $ vid2gif %F %d/%W.gif
# Get custom width and framerate from user input
read -p 'Width (default 540): ' G_WIDTH
read -p 'FPS (default 10): ' G_FPS
# Use custom width and framerate or fallback on default
G_WIDTH=${G_WIDTH:-540}
G_FPS=${G_FPS:-10}
# Define temporary image to use as color pallette
PALETTE="/tmp/palette.png"
# Define filters
FILTERS="fps=$G_FPS,scale=$G_WIDTH:-1:flags=lanczos"
# Generate color palette from video stream so final GIF will have good filesize to quality ratio
ffmpeg -v warning -i $1 -vf "$FILTERS,palettegen" -y $PALETTE
# Generate GIF using our color palette and filters
ffmpeg -v warning -i $1 -i $PALETTE -lavfi "$FILTERS [x]; [x][1:v] paletteuse" -y $2
# Remove temporary palette image
rm -f $PALETTE
@kevinchappell
Copy link
Author

This is how I make animated GIF
animated-gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment