Convert a video file to a GIF using a MacOS Automator task
While I was writing this post I had a step where I wanted to show a GIF of the operation. MacOS’ built-in screen capture was able to record a section of the screen for me as a Quicktime movie (.mov). For obvious reasons a GIF would be a lot simpler for a blog post, but there was no straight forward mechanism to do what I needed.
A quick Google returned this Medium article describing a couple of utilities that can get the job done. It’s a few extra steps that I didn’t care to do so I wrapped them in an Automator script task and integrated it with Finder for some sweet right-click action.
What you’ll need
- Homebrew
- ffmpeg (via Homebrew:
brew install ffmpeg
) - gifsicle (via Homebrew:
brew install gifsicle
)
- Launch Automator - use
Command + Space
to search for Automator - You’ll be presented with a dialog to open an existing Automator file. Click the New Document button.
- Select Quick Action for the document type and click Choose.
- Welcome to the Automator canvas! In the “Library” on the left, search for
Shell
and drag theRun Shell Script
item to the canvas on the right hand side. - Above the canvas, you’ll see a handful of settings you can configure. Change them to the following:
- Workflow receives current: movie files in Finder.app
- Image: Slide show
- In the Script task, select your preferred shell environment. I stuck with my usual zsh. You’ll also want to set the “Pass input” value to as arguments.
- Paste the following block into the contents of the script task:You’ll notice that the first line appends
export PATH=/usr/local/bin:$PATH filename="$(basename -- $1)" dir="$(dirname -- $1)" mkdir "/tmp/pngs" mkdir "/tmp/gifs" ffmpeg -i $1 -r 10 /tmp/pngs/out%04d.png sips -s format gif /tmp/pngs/*.png --out /tmp/gifs cd /tmp/gifs gifsicle --optimize=3 --delay=10 --loopcount *.gif > $dir/$filename.gif rm -r "/tmp/pngs" rm -r "/tmp/gifs"
/usr/local/bin
to $PATH. This is to get access to the Homebrew installed utilities ffmpeg and gifsicle. Let’s break down the rest:filename
anddir
get me the name of the file and the files directory, respectively.- Then we make some temp directories.
- Run ffmpeg to convert the video file to a series of PNG files.
- Run sips to convert those PNGs to GIFs and put them in another folder.
- Run gifsicle to combine the individual GIF files into a single GIF animated image. You’ll notice the output is the directory the source file was in, with the same name, except for the additional .gif extension.
- Remove our temp directories.
- Your final task should look like this:
- Go ahead and save it with
Command+S
or File > Save. The name you give this action is the same name that will appear in the Actions menu in Finder. - Open Finder and locate a video file. Right click your file and go to Quick Actions > Name of your new action
- Depending on the size of the source video, you’ll have a new animated GIF land in the same directory as your source video:
You can download the Automator task here:
Convert movie to GIF Workflow
- MD5 Checksum
- 643e03331190a9393dc3f0dc27e897e0
- SHA256 Checksum
- cbc4fc3e7642ce3f37e82b15b8cfb9931800ed549db836435b5740c26253cff7
That’s it! Any questions or suggestions please let me know.
About Stellios Williams
Senior Cloud Solutions Architect - Service Providers
VMware
This is my personal tech related blog for anything private and public cloud - including homelabs! My postings are my own and don’t necessarily represent VMware’s positions, strategies or opinions. Any technical guidance or advice is given without warranty or consideration for your unique issues or circumstances.
Comments
Latest Posts
- Restore of a Wordpress deployment is stuck redirecting the port
- Backups and Restores using Velero in TKGm 1.6.1
- Unable to upgrade the database: org.postgresql.util.PSQLException: ERROR: could not open shared memory segment: No such file or directory
- Upgrading Cloud Director 10.4.1 to 10.5
- Installing and Configuring Velero in TKGm 1.6.1 on vSphere
Advertisement
Popular Tags
vmware63
vrealize-suite19
vsphere19
how-to17
vcloud-director12
professional-development10
aws8
certificates8
vrealize-orchestrator7
github6
hugo6
lambda6
tanzu6
vcd6
vcenter6
blog5
s35
homelab4
python4
tanzu-kubernetes-grid4
tkg4
tkgm4
vmware-cloud-director4
vrealize-automation4
vrealize-suite-lifecycle-manager4
api3
api-gateway3
automation3
container-service-extension3
cse3
csp-cloud-builder3
esxi3
javascript3
kubernetes3
pfsense3
powercli3
psc3
upgrade3
vcsa3
velero3
vrealize-log-insight3
vrealize-operations-manager3
vrealize-saltstack-config3
azure2
cassandradb2
certification2
cloud-director2
dns2
hardware2
microsoft2
packer2
rest2
saltstack2
storage2
swagger2
telegraf2
vcd-10.4.12
vcd-10.52
vcloud-availability2
vcp2
vrealize-operations2
active-directory1
adfs1
alp1
app-launchpad1
automator1
blueprints1
bmc1
certificate-authority1
cisco-aci1
clarityui1
cloud-init1
converter1
cpu1
custom-resource1
dell1
docker1
draas1
federation1
firmware1
freebsd1
freenas1
gcp1
ipmi1
ipsec1
json1
macos1
network1
nodejs1
nsx1
opensource1
ova1
postman1
quanta1
route531
saml1
self-hosted1
ubuntu1
utilities1
vcenter-server1
vcloud1
vcpp1
vexpert1
vidm1
virtual-network-gateway1
vmware-identity-manager1
vpn1
vrli1
vro1
vsan1
vvols1
windows-server1
wordpress1