---
title: Supercronching videos for embedding in websites with ffmpeg
date: 2024-06-14
desc: "TL;DR: I convert it from video to gif to video"
hero:
ai: "Photo by Xe Iaso, Canon EOS R6mkii, Helios 44-2 58mm f/2"
file: orange-tulips
prompt: "A close-up of orange tulips in a field, the tulip in the center is in focus and the rest are slightly out of focus."
social: true
---
Sometimes I record little screencasts to help explain things when I'm writing articles. These are intended to be very small fragments to help visually explain things before I explain what's going on in text. I use macOS (command-shift-5) to record them, but macOS makes fairly large files by default. I believe that these things should be as small as possible, so I figured out a super cheap hack to make them _tiny_.
Before I show you how I do it, here's an example video where I explore my homelab Kubernetes cluster and galavant around a few namespaces with [`k9s`](https://k9scli.io/):
When macOS first recorded this, it was a 29 MB file:
```
du -hs /Users/cadey/Desktop/Screen\ Recording\ 2024-06-14\ at\ 14.20.10.mov
29M /Users/cadey/Desktop/Screen Recording 2024-06-14 at 14.20.10.mov
```
This is way overkill for a 20 second video. Here's what ffprobe says about the video:
> Stream #0:0\[0x1\]\(und\): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1766x1206, 12507 kb/s, 60 fps, 60 tbr, 6k tbn (default)
Yikes, that resolution is way too high, it's almost bigger than 1080p! I don't need 60fps either, and 12 Mbps is way beyond overkill. I want to make this as _small_ as possible. The details don't matter too much as long as the result is legible.
So what I did is convert the video to an animated GIF, and then converted that GIF back to an MP4 file. This is a super hacky way to make the video as small as possible without impacting legibility too much. Here's the script I wrote:
```sh
#!/usr/bin/env bash
# cronchgif.sh
set -e
[ ! -z "${DEBUG}" ] && set -x
if [ $# -ne 2 ]; then
echo "usage: cronchgif.sh