Source
TL;DR
copy this code
#!/bin/sh
start_time=00:10
duration=00:08
palette="/tmp/palette.png"
filters="fps=15,scale=320:-1:flags=lanczos"
ffmpeg -v warning -ss $start_time -t $duration -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -ss $start_time -t $duration -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
open a new document on your text editor and paste it there.
Save it (videotogif.sh) and make it executable
chmod +x videotogif.sh
Place this file in the same folder your video is.
BEFORE using it
edit this lillte program to suit your preferences, mainly:
- start_time = minutes:seconds
- duration = minutes:seconds
- fps = frame rate (keep it as it is but you can play with this setting)
- scale = scale video to 320px_horizontal:keep_proportions (with example settings)
palette is a temporary file created on runtime, don't need to change it.
Conversion
execute this script as
./videotogif.sh input_video.mkv output_gif.gif
name files as you wanted.
animated gif, just 320px wide 4.2Mb
Make a video instead
If you don't need a gif that loops endlessly, just make a short video and it's likely it has better image quality and smaller file size (better for websites load).
ffmpeg -ss 00:10 -t 8 -i input.mp4 -vf scale=640x480:flags=lanczos -c:v libx264 -preset faster -an output.mp4
tip: place -ss and -t parameters before input.file; set scale as you needed.
640x480 video, 18 seconds just 2.7Mb
Video Source: Bring a little lovin - Los Bravos
Comments
No comments yet. Be the first to react!