Finding this little set of commands is one of the main reasons why I love the Command Line. Once I realized that almost everything that I was doing in a UI was possible on the CLI, the world opened up. One of the things I return to from time to time is when I can’t find a GIF I want to use in a message or email. Every time, I look up how to convert a video to a GIF and every time, I’m given a new solution. Imgur’s video-to-gif used to be reliable, but the last few times it hasn’t been working as expected.
This last time, I was trying to convert a very important It’s Always Sunny in Philadelphia clip to a reaction gif. Can you believe there is no “thank you” reaction gif from when Dennis reads Charlie’s speech?!. Here’s the gif for your own collections.
The command line functions I found came to get this done came mostly from Funky Cloud Medina’s post on this. I didn’t want to use automator, but just write out a few commands, so here is what I did (on MacOS):
First, install ffmpeg and gifsicle with Homebrew. brew install ffmpeg gifsicle
Next, navigate to the directory where your video is. If you plan on doing this regularly, you can create some permanent directories, but I started with creating two temporary directories for the images and then the final gifs.
mkdir pngs/ gifs/
This will create both gifs
and pngs
folders in the directory you’re currently in.
Next, we’ll process the movie.
ffmpeg -i Untitled.mov -r 10 pngs/out%04d.png
Untitled.mov
is the name of the video file in the directory you’re currently in and outputs each frame to the pngs
folder with increment digits. The incrementing digits are so you don’t overwrite everything and end up with just a single picture file.
Next, we’ll use sips
, the Scriptable Image Processing System. (Check out man sips
from your own CLI for more info!)
sips -s format gif pngs/*.png --out gifs
Almost there! This is processing all the image files into the gifs folder. Let’s now move into the gifs folder with cd: cd gifs
And now we can use gifsicle to merge all the images into a single gif! We’ll do that with the following command:
gifsicle --optimize=3 --delay=10 --loopcount *.gif > ~/Documents/thankyou.gif
And voila! You should have a auto-playing gif file ready for use in all your reactions and emails. Enjoy!