Last active
October 26, 2020 23:24
-
-
Save montehurd/d6647cf5a5c1859e0716 to your computer and use it in GitHub Desktop.
Simple optimized .mov to .gif conversion from macOS command line using only ffmpeg and gifsicle - with instructions for automatic conversion any time a .mov file is dropped into a special folder.
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
ffmpeg -i in.mov -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 > out.gif |
Super helpful tool!
Thanks!! So was your tip about using command-shift-5
to quickly record the ".mov" files!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I primarily use this to convert short screen recordings (via the macOS
command-shift-5
keyboard shortcut) to more share-able gifs.Once the installation instructions below are completed, converting a screen recording (or other)
.mov
file to a gif is as simple as dropping it in a special folder - a couple seconds later, a gif version of the file appears in the folder:Benefits
Installation:
Then use Homebrew to install
ffmpeg
andgifsicle
libraries:Hit
command-space
to open Spotlight searchType
terminal
and open the terminal appInstall
ffmpeg
by pasting the following command into terminal, then pressenter
:brew install ffmpeg
Install
gifsicle
by pasting the following command into terminal, then pressenter
:brew install gifsicle
Usage:
Manual:
Once installation steps are complete, a command like the following can be used to convert a
.mov
file to a.gif
:ffmpeg -i in.mov -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 > out.gif
Automatic (run when mov files placed in a folder):
Typing such a command can be tedious (plus you would have tweak it for the specific location of each
.mov
file to be converted), so instead we can configure macOS to do this automatically any time a.mov
file is dropped into a folder. macOS'sAutomator
provides Folder Actions to allow scripts to be triggered when files are placed in a folder.Here's a shell script triggering our mov-to-gif command once for every file we drop in the folder:
Here's sticking that script into an Automator "Folder Action" workflow so it can be triggered when dropping files in a folder:
Technical notes:
ffmpeg -i in.mov -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 > out.gif
ffmpeg
command is used to simplify the color palate and reduce the frame rate of the.mov
file-r
controls the frame rate - here we use 10 frames per second, which is high enough to make it easy to see what's going on, but low enough to help keep the file size downgifsicle
command is used to convert the resulting.mov
file to an optimized.gif
--optimize=3
helps keep the gif file size down even more without compromising quality too muchYou can tweak these settings (or add others) - see:
ffmpeg
settings docsgifsicle
settings docsThoughts:
Aside from the gif-specific bits, you may find this useful as an example of how to trigger a script to run any time you drop a file in a folder.
I suppose it's a fair example of how to pass the result of one command (
ffmpeg
via itsstdout
) to the input of a second command (gifsicle
via itsstdin
) too.