DEV Community

Muhammad Usman
Muhammad Usman

Posted on

How I Reduced a Video from 137MB to 29MB Using FFmpeg (Without Killing Quality)

If you're shipping videos on the web, file size matters—a lot. Large videos slow down page loads, hurt performance, and burn bandwidth.

I recently optimized a video and reduced it from 137MB to just 29MB (~79% smaller) using a single FFmpeg command.

Here’s exactly what I used:

ffmpeg -hide_banner -loglevel info -stats \
-i input.mp4 \
-c:v libx264 -preset slow -crf 23 \
-profile:v high -level 4.1 \
-movflags +faststart \
-vf "scale=1920:-2" \
-c:a aac -b:a 128k \
output-optimized.mp4
Enter fullscreen mode Exit fullscreen mode

🔍 What each part does

1. Efficient video encoding

-c:v libx264
Enter fullscreen mode Exit fullscreen mode

Uses H.264 — the most widely supported codec for web.


2. Better compression (smaller file size)

-preset slow
Enter fullscreen mode Exit fullscreen mode

Slower encoding = better compression efficiency.
Worth it when you're preparing assets ahead of time.


3. Quality control

-crf 23
Enter fullscreen mode Exit fullscreen mode

CRF (Constant Rate Factor) controls quality:

  • Lower = higher quality
  • Higher = smaller file

23 is the sweet spot for most web use cases.


4. Web compatibility

-profile:v high -level 4.1
Enter fullscreen mode Exit fullscreen mode

Ensures the video works smoothly across browsers and devices.


5. Faster playback on websites

-movflags +faststart
Enter fullscreen mode Exit fullscreen mode

Moves metadata to the beginning of the file so the video can start playing immediately (no full download required).


6. Resize smartly

-vf "scale=1920:-2"
Enter fullscreen mode Exit fullscreen mode
  • Limits width to 1920px
  • Keeps aspect ratio intact
  • Prevents unnecessarily large resolutions

7. Optimize audio

-c:a aac -b:a 128k
Enter fullscreen mode Exit fullscreen mode

AAC audio at 128 kbps — good balance between quality and size.


📊 Final Result

Metric Before After
File Size 137 MB 29 MB
Reduction ~79%
Quality High Visually similar

🚀 When to use this

This setup is perfect for:

  • Landing pages
  • Product demos
  • Background videos
  • Marketing assets
  • Any web-delivered video

💡 Pro tip

If you need:

  • Higher quality: use -crf 20–22
  • Smaller size: use -crf 24–28

Final Thoughts

You don’t need fancy tools to optimize video for the web.
FFmpeg alone can dramatically cut file size while keeping quality intact.

If you're still uploading raw videos to production—this is low-hanging fruit worth fixing.


Let me know if you want a version tuned for mobile, ultra-low bandwidth, or streaming 👇

Top comments (0)