Tuesday, November 17, 2026

Compressing mp4 video files using ffmpeg

 ffmpeg is amazing at reducing the size of mp4 video files.

Here's the script I use to compress a directory full of mp4 files on my macBook:


for file in *.mp4; do

   mv $file "$file"-orig.mp4

   caffeinate ffmpeg -i "$file-orig.mp4" -c:v libx264 -crf 28 -preset veryslow -c:a copy "$file"

done

Usually the compression gets a file down to about a half the originals size. I exported a slideshow from iMovie to an mp4 file and the compression got the original size down to 6.8%, but that is a very special case.

"caffeinate" makes sure the Mac doesn't get too sleepy.

No comments: