Last active
June 18, 2024 20:10
-
-
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 - 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 rgb8 -r 10 -f gif 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
: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
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 rgb8 -r 10 -f gif 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 rgb8 -r 10 -f gif 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 downYou can tweak these settings (or add others) - see:
ffmpeg
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.
Alternatives:
Optimize for speed
If you want faster conversions, for example, if you're regularly dropping large numbers of files into your conversion folder at once, you can also install
parallel
(viabrew install parallel
) and use a slightly different script:Optimize for gif file size
If you want gifs as small as possible, at the cost of slower conversions, you can install both
parallel
andgifsicle
(viabrew install parallel gifsicle
) and use this script:Miscellaneous:
If you later want to edit the shell script that gets triggered when you drop files in your folder, you can right-click on your folder and select
Folder Actions Setup
then selectEdit Workflow
for the conversion folder action