AI • Science • Technology • Future

Side Projects

Convert Every Video in a Folder to GIF with a Shell Script

Image from the original article
Featured image: original publisher image. Via original publisher.

Turning screen recordings into GIFs is a common need for developers and content creators. A simple script can automate this process for entire folders of video files.

What Happened

A user recorded several screen clips and wanted to share them directly in documents or chat without requiring a click to play.

They began by asking an AI for an ffmpeg command to convert a video to a GIF. The first result produced a grainy, large file. After refining the command with additional filters—palettegen and paletteuse—the output improved significantly.

When expanding to a folder of ten recordings, the original command processed one file at a time. It failed on a file named Screen Recording 2026-11-20 at 10.15.32.mov due to spaces in the filename.

How It Works

The solution is a shell script that runs on macOS and requires ffmpeg. It processes all video files in a folder and its subfolders.

  • The script uses find to locate all video files: .mov, .mp4, .m4v, .webm, and .mkv.
  • Each file is converted to a GIF using ffmpeg with specific filters.
  • The fps=$FPS and scale=$WIDTH:-2:flags=lanczos parameters control quality and size.
  • It skips files where a GIF already exists and is up to date.
  • If ffmpeg fails to read a file, it reports the error but continues processing others.

The script includes placeholders for user input:

  1. DIR: A folder path, marked as {{prompt:folder}}.
  2. FPS: Frame rate options: 12, 8, 15, or 24. Default is 12.
  3. Default is 640.

After saving the script, it can be used with a tool like cmdbook. The user creates a command, pastes the script, and defines the placeholders.

When run, cmdbook presents a form. The user drags a folder into the first field, selects a frame rate and width, and presses Enter. The script then runs automatically.

For example, a 60-second 1080p screen recording becomes an 800px GIF at 12 fps in about 11 seconds on a Mac.

Why It Matters

This workflow enables quick sharing of screen clips without file size or format overhead. It supports real-time documentation, quick feedback loops, and efficient communication in team settings.

Image from the original article
original publisher image. Via original publisher. · Source

It shows how a simple script, combined with a GUI tool, can turn a technical process into a user-friendly experience.

Limitations and Open Questions

The script only works with specific video formats. It does not support audio or metadata.

It fails on files with spaces in names, requiring manual adjustment or a more robust path handling.

Editing parameters like frame rate or width requires finding and modifying lines in the command, which is not intuitive for non-technical users.

While the script skips up-to-date GIFs, it does not track or store metadata like original duration or resolution.

It assumes ffmpeg is installed. Users must install it via brew install ffmpeg if missing.

There is no built-in error logging or reporting beyond the final summary line.

The full script is available at the original source.

For users interested in similar automation, see how a local Markdown editor stays fast or how to evaluate AI time savings.

Sources & further reading

Featured image: original publisher image. Via original publisher. Image source