Skip to content

Instantly share code, notes, and snippets.

@contolini
Created July 8, 2026 17:23
Show Gist options
  • Select an option

  • Save contolini/95d0fe0c36b0579ecf0d1bcba069d83d to your computer and use it in GitHub Desktop.

Select an option

Save contolini/95d0fe0c36b0579ecf0d1bcba069d83d to your computer and use it in GitHub Desktop.
Converting a video file into an animated gif on a Mac

Installing vid2gif command

  1. brew install ffmpeg gifsicle
  2. Paste the below vid2gif function into whatever file you store your aliases in. If you're using Oh My Zsh it's ~/.oh-my-zsh/custom/aliases.zsh.
  3. Restart your terminal session or reload your shell environment, e.g. omz reload
  4. Use the command with vid2gif --src ~/some-video.mov. You can optionally specify a target name, resolution or fps.
function vid2gif() {
src="" # required
target="" # optional (defaults to source file name)
resolution="" # optional (defaults to source video resolution)
fps=10 # optional (defaults to 10 fps -- helps drop frames)
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
param="${1/--/}"
declare $param="$2"
fi
shift
done
if [[ -z $src ]]; then
echo -e "\nPlease call 'v2g --src <source video file>' to run this command\n"
return 1
fi
if [[ -z $target ]]; then
target=$src
fi
basename=${target%.*}
[[ ${#basename} = 0 ]] && basename=$target
target="$basename.gif"
if [[ -n $fps ]]; then
fps="-r $fps"
fi
if [[ -n $resolution ]]; then
resolution="-s $resolution"
fi
runcommand="ffmpeg -i "$src" -pix_fmt rgb8 $fps $resolution "$target" && gifsicle -O3 "$target" -o "$target""
echo ""
echo ".------------------------."
echo "|\\\\//////// 90 min |"
echo "| \\/ __ ______ __ |"
echo "| / \|\.....|/ \ |"
echo "| \__/|/_____|\__/ |"
echo "| A |"
echo "| ________________ |"
echo "|___/_._o________o_._\___|"
echo ""
echo "ツ running >> $runcommand"
echo "ツ ..."
echo ""
eval " $runcommand"
osascript -e "display notification \"$target successfully converted and saved\" with title \"v2g complete\""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment