Skip to content

Instantly share code, notes, and snippets.

@mrk-han
Last active October 7, 2023 11:54
Show Gist options
  • Save mrk-han/f8f7df31519a780aa797cfe7399abb88 to your computer and use it in GitHub Desktop.
Save mrk-han/f8f7df31519a780aa797cfe7399abb88 to your computer and use it in GitHub Desktop.
Convert (Screen Capture) .mov files to GIF format using Ffmpeg and Gifsicle. Put GIFs into JIRA and Slack with ease! MacOS

Convert (Screen Capture) .mov files to GIF format using Ffmpeg and Gifsicle (MacOS)

Prompts for path to .mov and allows user to enter a .gif name. Then converts that .mov file to a .gif and saves to ~/Downloads/.

Inspired by: https://gist.github.com/dergachev/4627207

To use:

  • Save the code from this gist into a file and name it something like convert_movie_to_gif.sh, and then run chmod +x ./convert_movie_to_gif.sh to make it executable.
    • If gifsicle isn't installed, the script will tell you.
    • If ffmpeg isn't installed, the script will tell you.
  1. From finder: right click on example.mov and hold option then select Copy "example.mov" as Pathname

  2. Run the script and paste the path into your terminal when the script prompts you.

  3. Enter a name for your new file. The script will append .gif to the name given.

The Script

#!/usr/bin/env bash

#-----------------------------------------------------------------------------------
# 1) If ffmpeg and gifsicle are not installed, script will exit
# 2) `option + right click` will give the option to copy the path name of the .mov file you want to convert
# 3) `cmd + v` to paste that path into script in terminal
# 4) enter in name of gif WITHOUT the gif extension at the end
# 5) script will be saved into downloads
#-----------------------------------------------------------------------------------

if ! [ -x "$(command -v ffmpeg)" ]; then
  echo 'Error: ffmpeg is not installed. please install with (brew install ffmpeg)' >&2
  exit 1
fi

if ! [ -x "$(command -v gifsicle)" ]; then
  echo 'Error: gifsicle is not installed. please install with (brew install gifsicle)' >&2
  exit 1
fi

echo -n "enter absolute path to .mov: "
read -r MOVNAME

echo -n "enter name for your gif (the script will add the extension for you): "
read -r GIFNAME

ffmpeg -i "$MOVNAME" -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=4 > ~/Downloads/"$GIFNAME".gif

echo -e "\nSaved ${GIFNAME}.gif to downloads"

Changelog:

  • Removed -s 600x400 to not distort when taking videos of emulators/simulators or things with different dimensions.
  • Added check for gifsicle and ffmpeg
  • Changed delay from 3 to 4 (Slows down the GIF slightly)
@akosasante
Copy link

Thanks! For me at least (running this on MacOS with zsh as a zsh function) I had to remove the quotation marks around ffmpeg -i "$MOVNAME" :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment