Created
August 2, 2018 18:01
-
-
Save flackend/efac7230fa53511e0a6cec16a8d0a943 to your computer and use it in GitHub Desktop.
This file contains 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/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