Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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
Owner

kevinchappell commented Mar 26, 2016

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