Last active
March 26, 2016 17:19
-
-
Save kevinchappell/40ccb8b2a1b87f4d067c to your computer and use it in GitHub Desktop.
Convert any video to GIF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is how I make animated GIF
