Create higher quality gif from videos

ffgif() { p="fps=10,scale=${4:-320}:-1:flags=lanczos"; ffmpeg -y -ss ${2:-0} -t ${3:-0} -i "$1" -vf ${p},palettegen .p.png && ffmpeg -ss ${2:-0} -t ${3:-0} -i "$1" -i .p.png -filter_complex "${p}[x];[x][1:v]paletteuse" "${1%.*}".gif && rm .p.png; }
I had to compress it a bit to meet the 255 limit. See sample for full command (274) usage: ffgif foo.ext Supports 3 arguments (optional) ffgif filename seek_time time_duration scale ffgif foo 10 5 320 will seek 10 seconds in, convert for 5 seconds at a 320 scale. Default will convert whole video to gif at 320 scale. Inspiration -
Sample Output
ffgif() { ffmpeg -y -ss ${2:-0} -t ${3:-0} -i "$1" -vf fps=10,scale=${4:-320}:-1:flags=lanczos,palettegen .p.png && ffmpeg -ss ${2:-0} -t ${3:-0} -i "$1" -i .p.png -filter_complex "fps=10,scale=${4:-320}:-1:flags=lanczos[x];[x][1:v]paletteuse" "${1%.*}".gif; rm .p.png; }

2015-09-08 21:13:17

What Others Think

Script fails with no output.
m4r14n0ju · 326 weeks ago
This is a function, not a script. If you simply copied it to terminal, there shouldn't be any output. Thanks for the downvote
snipertyler · 326 weeks ago
So you make the ffgif function, then run ffgif myvideothatisntporn.mp4? What does the convert for 5 second part do? Give you an imagine for every frame and 5 seconds worth? Sorry I'm stuck at work with windoze and no access to legit access to use a server to render videos. Otherwise I'd test this myself. We obviously keep ffmpeg off our servers because we're not a multimedia company and we keep our installed packages minimal on all services within reason. That's the way to go for security, freeing up resources, etc.
sonic · 325 weeks and 5 days ago
@sonic if you examine the command, you'll see that $1 is the file, $2 is for -ss, $3 is for -t and $4 is for scale. Examine ffmpeg documentation for the meaning of each of those. By "recording for 5 seconds" it takes a video at (for example) 00:05:00, and ends recording at 00:05:05. It's also converting at 10 frames per second (probably adjustable by changing fps=10)
snipertyler · 325 weeks and 5 days ago
great that i found this forum. People here are great. Learned alot. Keep posting more
Killersmile · 36 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: