DEV Community

printfapps
printfapps

Posted on

Shrink a screen recording with ffmpeg from the command line

You recorded your screen for a bug report or a demo. One minute, 285 MB. Too big to attach, too big to send.

How do you do it?

You ask an AI, and get ffmpeg -i in.mov out.mp4. It works: 46 MB. Better, still big.

You ask for smaller and get a scale=960:-1. On a window recording that's 1280×1001, it fails:

[libx264] height not divisible by 2 (960x751)
Enter fullscreen mode Exit fullscreen mode

The video encoder needs even sizes, and -1 gave it 751. You ask again: it should be -2. Then you add -crf 28 for a smaller file, -pix_fmt yuv420p so it plays everywhere, and -movflags +faststart so it starts playing before it's fully downloaded.

You save it somewhere: a Markdown note, or a shrink.sh file. Next time it's another file, or you want it 1920 wide, and you have to find the script and edit the middle of the ffmpeg line.

With cmdbook, the script has one place to live, and it gets a GUI for free.

The file and the width become fields of a form

Here's how

1. Save the script once. Create a command in cmdbook and paste the script (it's at the end).

2. Mark what changes. The file and the width become placeholders:

IN="{{prompt:file}}"
...
-vf "scale={{prompt:width?1280|960|1920}}:-2"
Enter fullscreen mode Exit fullscreen mode

1280|960|1920 becomes a dropdown. The first one is the default.

3. Click Run. cmdbook shows a form. Drag the recording onto it, pick a width, press Enter.

4. Get the small file. It's saved next to the original, with -small in the name:

285M    Screen Recording.mov
6.0M    Screen Recording-small.mp4
Enter fullscreen mode Exit fullscreen mode

One minute of 1080p, from 285 MB to 6 MB, in 4 seconds on my Mac. The script drops the audio (-an), since screen recordings usually have none. If yours has sound, delete -an.

Next time, your last width is already selected.

That's all a script needs to get a GUI: mark the parts that change. The rest is the script you already have.

Try cmdbook here: printf.app/cmdbook

The full script (needs ffmpeg)

IN="{{prompt:file}}"
OUT="${IN%.*}-small.mp4"
ffmpeg -hide_banner -v error -stats -y -i "$IN" \
  -vf "scale={{prompt:width?1280|960|1920}}:-2" \
  -c:v libx264 -crf 28 -preset fast -pix_fmt yuv420p -movflags +faststart -an "$OUT"
du -h "$IN" "$OUT"
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The 285 MB to 6 MB result in 4 seconds is the number that sells it — one minute of 1080p, and the file is suddenly small enough to attach to a bug report without thinking twice.

The detail I appreciated most was the scale=-2 fix. The AI-suggested scale=960:-1 failing on a 1280x1001 recording with "height not divisible by 2 (960x751)" is exactly the kind of small, confusing error that makes people give up on ffmpeg, and the explanation of why -2 works is clear.

One question: does the same -crf 28 setting hold up on a longer or 4K recording, or do you reach for a different CRF once the source gets bigger? I am curious where this recipe starts to trade visible quality for size.