Posted on November 15, 2023 | #bash

Turn screen recording into a gif

When scrolling Twitter, I really like seeing gifs of other people’s games and game development progress. And I also do things like that sometimes! So I made a little bash script so that I don’t have to google how to use ffmpeg all the time.

Usage: You give it a path and the resulting gif will be placed in your current working directory.

#!/bin/bash

# Check if exactly one argument is provided
if [ "$#" -ne 1 ]; then
    echo "Supply a <file> to be turned into a gif!"
    exit 1
fi

# Extract the filename without the path
input_file="$1"
base_filename=$(basename "$input_file")

# Replace the extension with .gif and ensure it's in the current directory
output_file="${base_filename%.*}.gif"

# Use ffmpeg to convert the file to GIF
ffmpeg -i "$input_file" -vf "fps=10" "$output_file"

Notes

I work on a Mac, so I only really tested this with .mov files. This is what Quicktime player produces from a screen recording, don’t ask me why. But this command should work for any video file type, since ffmpeg looks at the file extension to determine what it’s working with.

I have it aliased to gif in my .zshrc:

alias gif="~/Scripts/gif.sh"