Skip to content

Instantly share code, notes, and snippets.

@flackend
Created August 2, 2018 18:01
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 flackend/efac7230fa53511e0a6cec16a8d0a943 to your computer and use it in GitHub Desktop.
Save flackend/efac7230fa53511e0a6cec16a8d0a943 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# _/_/_/ _/_/_/ _/_/_/_/
# _/ _/ _/
# _/ _/_/ _/ _/_/_/
# _/ _/ _/ _/
# _/_/_/ _/_/_/ _/
#
# Uses ffmpeg to generate
# animated gifs from mov
# files.
# TODO
# + delay/speed
# + choose dither
# Get the speed from the user (or default)
read -p "Enter fps[10]: " FPS
FPS=${FPS:-10}
read -p "Enter max colors[255]: " MAX_COLORS
MAX_COLORS=${MAX_COLORS:-255}
# Get the video size
GIF_ORIGINAL_SIZE=$(php -r '
$json = `/usr/local/bin/ffprobe -v quiet -print_format json -show_streams ~/Desktop/in.mov`;
$info = json_decode($json);
foreach($info->streams as $stream) {
if (isset($stream->width)) {
break;
}
}
$width = $stream->width;
$height = $stream->height;
echo "$width:$height";')
# Get the size from the user (or match the original)
read -p "Enter size[$GIF_ORIGINAL_SIZE]: " GIF_SIZE
GIF_SIZE=${GIF_SIZE:-$GIF_ORIGINAL_SIZE}
ffmpeg -y -i ~/Desktop/in.mov -vf fps=$FPS,scale=$GIF_SIZE:flags=lanczos,palettegen=max_colors=$MAX_COLORS /tmp/palette.png
ffmpeg -i ~/Desktop/in.mov -i /tmp/palette.png -filter_complex "fps=$FPS,scale=$GIF_SIZE:flags=lanczos[x];[x][1:v]paletteuse=dither=none" ~/Desktop/out.gif
rm /tmp/palette.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment