DEV Community

Cover image for VP9/WebM vs H.264/MP4: Measuring File Size on the Same Clip
disankyo
disankyo

Posted on

VP9/WebM vs H.264/MP4: Measuring File Size on the Same Clip

Codec comparisons can be misleading. One video comes out smaller, so it's tempting to call that codec more efficient. But if the two encodes use different quality settings, the result doesn't tell you much.


A fair test starts with the same source footage and a similar visual quality target.

1. Start with the same source clip

Pick one video and keep its resolution, frame rate, and duration unchanged.

Don't resize one version, trim a few seconds from another, or change the frame rate between exports. Those differences affect file size before the codec even enters the picture.

For example, use the same 1080p, 30 fps, 60-second source for both encodes.

2. Match visual quality, not the setting number

Use a quality-based encoding mode for each codec, then adjust the settings until the results look reasonably close.

This matters because quality values aren't directly comparable across encoders. An H.264 CRF of 23 and a VP9 quality setting of 23 don't guarantee the same visual result.

Compare the output at the same resolution and viewing size. Look closely at details such as text edges, fine textures, motion, and gradients. If one version is noticeably blurrier or shows more blocking, adjust its settings before comparing file sizes.

Once the visual quality is reasonably matched, record the settings and compare the resulting files.

3. Measure the complete output

Don't compare only the video stream if the goal is to understand what a viewer will download.

The final file can also contain audio, metadata, subtitles, and container overhead. Measure the complete exported file, whether it's WebM or MP4.

Then decode each output and check that the frame count, resolution, and duration are still correct. A smaller file isn't a useful result if frames are missing or the export has changed the video unexpectedly.

4. Test more than one type of footage

Different clips put different demands on an encoder.

A talking head, a screen recording with small text, and a fast camera pan can produce very different results. Fine text and sharp edges may expose artifacts that aren't obvious in a landscape shot. Fast motion can reveal problems that a static scene hides.

Run the comparison on a few representative clips rather than drawing a conclusion from one video.

5. Check playback compatibility

File size is only part of the decision.

VP9 is commonly used in WebM, while H.264 is commonly delivered in MP4. But codec and container are separate parts of the format, and browser or player support depends on the actual combination.

Test the exported files in the browsers and devices your audience uses. Saving a few megabytes doesn't help much if the video won't play where it's needed.

Keep the source file, encoder settings, output sizes, and playback results together. That gives you a repeatable baseline for the next test — and makes the comparison more useful than simply declaring one format the winner.

Top comments (0)