Created
July 29, 2020 16:14
-
-
Save alskipp/f2acd3987cf758d38510a55c537dfa9a to your computer and use it in GitHub Desktop.
Mangle your .mp4 files into .gif
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
#! /usr/bin/env nix-shell | |
#! nix-shell -i bash -p ffmpeg gifsicle | |
scale="${3:-320}" | |
fps="${4:-15}" | |
palette="/tmp/palette.png" | |
filters="fps=$fps,scale=$scale:-1:flags=lanczos" | |
ffmpeg -v warning -i "$1" -vf "$filters,palettegen=stats_mode=diff" -y $palette | |
ffmpeg -i "$1" -i $palette -lavfi "$filters,paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" -y -f gif - \ | |
| gifsicle --optimize=3 --delay=3 > "$2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use Nix, then dependencies will be automatically installed, otherwise ensure you have ffmpeg and gifsicle installed.
Basic usage (with default pixel width 320 & fps 15):
Specifying pixel width and frames per second:
Cobbled together from:
https://cassidy.codes/blog/2017/04/25/ffmpeg-frames-to-gif-optimization/
https://dev.to/piczmar_0/quickly-make-a-gif-from-a-video-553m