Different Types of Video File Formats and Why WebM and MP4 Beat Them All
Tags: mp4, javascript, webdev
Published: 2022-04-19 05:00:10

Which video formats are the best in terms of size/quality and are compatible with most players on the web, Android & iOS? The short answer for 2021 is: WebM backed up by MP4 is the winning stack to consider. Glance through this article for all the why's and get some encoding automation options.

💡 This content will be helpful for developers who are working on video sharing apps, CMSs, and ecommerce platforms. We didn’t cover the part about streaming in much detail, but ping us in the comments if you’re interested.

## Video File Formats, Codecs, and Containers: What’s the Difference?

You’ve probably come across such acronyms as AVI, MPEG-4, WMV, DivX, WebM, or MP4. For non-savvy users, they stand for different types of video files. But the truth is, some of them are indeed file formats defined by their _multimedia containers,_ and others are _codecs_ that help to shrink video and audio data inside those containers.

There are three main reasons to start differentiating formats, codecs, and containers:

- Video file formats and extensions don’t tell much about file characteristics. Containers and codecs do.
- Containers and codecs define whether a file will be played on a particular device.
- Containers and codecs influence how the data is stored and compressed, hence have a direct impact on video size and quality.

Let’s look at video file formats, containers and codecs from a developer’s perspective and distill their main characteristics.

### What’s a multimedia container?

The word _container_ speaks for itself. It’s like a bucket that may contain:

- Encoded video and audio tracks (can be several in different languages)
- Subs and interactivity elements like chapters and menus
- Synchronization information to make it all play together
- Metadata for SEO purposes


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p5udugu59l48qg8eusgl.png)
'Video containers are also called video wrappers and can store various types of data.'

Each multimedia container stores different types of data and is compatible with particular codecs and players. Here is an overview of the containers you’ve probably heard about:

<table>
    <thead>
    <tr>
        <th><strong>Container</strong></th>
        <th><strong>Video file extensions</strong></th>
        <th><strong>Perks</strong></th>
        <th><strong>Limitations</strong></th>
        <th><strong>Quality and compression</strong></th>
        <th><strong>Best for</strong></th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>Audio Video Interleave, AVI</td>
        <td>.avi</td>
        <td>
            <ul>
                <li>Supports many different codecs, can run both on Mac and Windows<br/><br/></li>
                <li>High quality of video</li>
            </ul>
        </td>
        <td>
            <ul>
                <li>No video chapters or interactive menus<br/><br/></li>
                <li>Doesn’t support some modern compression techniques</li>
            </ul>
        </td>
        <td>Low degree of compression and relatively large file sizes with possible quality losses</td>
        <td>DVD</td>
    </tr>
    <tr>
        <td>MPEG-4 Part 14, MP4</td>
        <td>.mp4</td>
        <td>
            <ul>
                <li>Browser compatible<br/><br/></li>
                <li>Was designed for low bit rates and is bandwidth friendly<br/><br/></li>
                <li>Supports chapters and interactivity</li>
            </ul>
        </td>
        <td>
            <ul>
                <li>Relatively high loading time<br/><br/></li>
                <li>Losses of video and audio quality after compression<br/><br/></li>
                <li>Codec dependent<br/><br/></li>
                Non loyalty-free
            </ul>
        </td>
        <td>High degree of compression and smaller file sizes</td>
        <td>Web, mobile, social media, streaming</td>
    </tr>
    <tr>
        <td>Matroska</td>
        <td>.mkv<br/>.mk3d<br/><br/></td>
        <td>
            <ul>
                <li>Supports all codecs<br/><br/></li>
                <li>Open-source and loyalty free</li>
            </ul>
        </td>
        <td>Is not natively supported on mobile devices</td>
        <td>Different levels of lossy and lossless compression</td>
        <td>DVD, Web</td>
    </tr>
    <tr>
        <td>Ogg</td>
        <td>.ogg<br/>.ogv<br/>.ogx</td>
        <td>
            <ul>
                <li>Open-source and free<br/><br/></li>
                <li>Is designed to provide efficient video streaming</li>
            </ul>
        </td>
        <td>
            <ul>
                <li>Not supported by Safari and Internet Explorer<br/><br/></li>
                <li>Codec dependent</li>
            </ul>
        </td>
        <td>Lossy and lossless compression, relatively small file size</td>
        <td>Streaming</td>
    </tr>
    <tr>
        <td>QuickTime File Format</td>
        <td>.mov<br/>.qt</td>
        <td>Good for video editing (does it in place, without rewriting the data)</td>
        <td>Is supported by QuickTime Player and just a few other players</td>
        <td>High quality with substantial file sizes</td>
        <td>Apple devices</td>
    </tr>
    <tr>
        <td>Flash Video, FLV</td>
        <td>.flv</td>
        <td>Supports all types of interactive content</td>
        <td>
            <ul>
                <li>No chapters or interactive elements<br/><br/></li>
                <li>Not supported by iOS or web<br/><br/></li>
                <li>High video making cost</li>
            </ul>
        </td>
        <td>No severe loss of quality, relatively big file sizes</td>
        <td>Web, Interactive content</td>
    </tr>
    <tr>
        <td>WebM</td>
        <td>.webm</td>
        <td>
            <ul>
                <li>Open source and loyalty free<br/><br/></li>
                <li>Based on Matroska container profile and supports most codecs<br/><br/></li>
            </ul>
        </td>
        <td>
            <ul>
                <li>Relatively low video quality<br/><br/></li>
                <li>No support for some browsers and devices<br/><br/></li>
                <li>No interactive elements</li>
            </ul>
        </td>
        <td>High video quality with relatively small file sizes</td>
        <td>Web</td>
    </tr>
    </tbody>
</table>

### What’s a codec?

Codecs compress (en**co**de) or decompress (**dec**ode) video and audio files. As video data is always massive, codecs shrink it to make storage and delivery easier.

[Video content](https://elements.envato.com/lp/create/video-templates/) is booming these days, so it’s hard to underestimate the role of codecs: thanks to encoding and decoding, anyone can create or watch videos all around the globe.

> _“Imagine that all image files have to be put in an archive. You start emailing people your photos inside .zip or .rar files, in accordance with this new law. Although both WinZip and WinRar have different features, at the end of the day, it's either a JPEG, PNG, GIF or BMP inside that file and that's what really makes the image. You'd say "The codec is JPEG, in a ZIP container.“_
>
> – a simple explanation by a Reddit user.

👉 [Learn about the Most Common Image File Extensions](/image-file-types/)

What codecs actually do is:

- Compress a video file and make it fit the multimedia container format
- Decompress the file and make it ready to play if the destination device supports the codec


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zilqx4ffff8xa59posq5.png)

Here is a list of popular codecs with supported multimedia container formats.

<table>
    <tbody>
    <tr>
        <td><strong>Some popular video codecs</strong></td>
        <td><strong>Highlights</strong></td>
        <td><strong>Supported container formats</strong><br/><br/></td>
        <td><strong>Best for</strong></td>
    </tr>
    <tr>
        <td>H.264/AVC</td>
        <td>The most commonly used nowadays, supports video streaming and is also used on cable broadcasting.</td>
        <td>MP4<br/>MOV<br/>F4V<br/>3GP<br/>TS<br/><br/></td>
        <td rowspan="2">Online HD videos and streaming. H.265 is the best in terms of video quality. H.264 is better for
            streaming thanks to high compatibility.
        </td>
    </tr>
    <tr>
        <td>H.265/HEVC</td>
        <td>Offers 50% better compression than H.264/AVC. Supports 8K resolution.</td>
        <td>TS<br/>MP4<br/>3GP<br/>MKV<br/><br/></td>
    </tr>
    <tr>
        <td>AV1</td>
        <td>Open-source and loyalty-free codec, competing with H.265.</td>
        <td>MP4<br/>3GP<br/>MKV<br/><br/></td>
        <td>Those who need H.264 and H.265 for free.</td>
    </tr>
    <tr>
        <td>VP9</td>
        <td>A free codec developed by Google. Supported by Android, Chrome, and YouTube but not supported by Apple.</td>
        <td>WEBM<br/>MKV<br/><br/></td>
        <td>Audiences on Google, Android, or YouTube.</td>
    </tr>
    </tbody>
</table>

MPEG-4 and DivX are legacy codecs that can still be seen nowadays but are outshined by their widespread competitors, H.264 and H.265. They already lag behind them in terms of efficiency and mobile delivery.

💡 Codecs and containers are frequently confused. I bet you can’t tell the difference between MPEG-4 and MP4 even after reading the paragraphs above. Cheat sheet: MPEG is a compression method, and MPEG-4 is one of its versions which is designed for low bandwidth audio/video encoding. MP4, abbreviated from MPEG-4 Part 14, is a media container.

If you see an .mp4 file, it doesn’t mean it was encoded with the MPEG-4 codec. As the MP4 container is compatible with a number of popular codecs, it can be any of them. On the other hand, videos encoded in MPEG-4 can be a part of any supported container like Matroska or Ogg.

### What’s a video file format?

A video file format is one that stores digital video data. As we already know, the way the data is stored is defined by the multimedia container; that’s why video file formats and extensions are usually named after them, causing lots of confusion.

Here’s a list of the most used video file formats with their corresponding containers, codecs, and file extensions.

<table>
    <tbody>
    <tr>
        <td><strong>Video file format</strong></td>
        <td><strong>Video filename extension</strong></td>
        <td><strong>Multimedia container</strong><br/><br/></td>
        <td><strong>Video codec</strong></td>
    </tr>
    <tr>
        <td>Matroska</td>
        <td>.mkv</td>
        <td>Matroska</td>
        <td>any</td>
    </tr>
    <tr>
        <td>Ogg Video</td>
        <td>.ogv<br/>.ogg<br/></td>
        <td>Ogg</td>
        <td>Theora, Dirac</td>
    </tr>
    <tr>
        <td>WebM</td>
        <td>.webm</td>
        <td>WebM based on Matroska</td>
        <td>VP8, VP9, AV1</td>
    </tr>
    <tr>
        <td>MP4</td>
        <td>.mp4<br/>.m4p (with DRM)<br/>.m4v</td>
        <td>MPEG-4 Part 14 (MP4)</td>
        <td>H.265, H.264, MPEG-4 Part 2, MPEG-2, MPEG-1</td>
    </tr>
    </tbody>
</table>

And here is how it looks in the real world:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sn46602gh5kuvu1zfwaj.png)

## How to Pick Video File Formats and Why WebM and MP4 Are Worth Considering

When choosing from different types of video file formats, there are four things you should think about:

- What kind of players and devices should the video be compatible with?
- Does the size matter, and how much video data are you ready to store?
- What level of video playback quality do you expect?
- Will you need the video to be livestreamed?

If you need a video file format that’s compatible with most devices, platforms, and browsers, including low bandwidth cases, look at MP4. It provides the best balance between quality and size, is compatible with several of the most popular codecs, and is widely supported.

💡 To further improve web performance, encode MP4 videos to WebM and use them together. WebM files are smaller in size and are the best fit for most web browsers. Force WebM every time a browser supports it, and if not, fall back to MP4. This can be done via video source tags. [Check out this setup guide from Google](https://web.dev/video-and-source-tags/).

## Video File Processing, Reformatting and Automation

To prepare your video files for the web or mobile apps, convert them to the formats you chose. The best practice is to use FFmpeg. It’s a free and open-source tool designed for command-line-based video and audio file processing. It can easily [convert your files to WebM and MP4 containers](https://web.dev/containers-and-codecs/) and even allows you to specify codecs.

Apart from reformatting files and choosing codecs, you might want to process them to fit your website. Such processing can include: cropping, trimming, adjusting resolution, and generating thumbnails.

All these operations can be performed on autopilot if you adopt Uploadcare, an out-of-the-box infrastructure for file uploads, processing, and delivery. Apart from reformatting files to web-friendly WebM, Ogg, and MP4, [Uploadcare lets you standardize video assets in terms of size and quality](https://uploadcare.com/docs/transformations/video-encoding/). In fact, it’s a single robust API that allows you to:

- Run URL-based video transformations in the browser
- Set up a background workflow with automated delivery
- Process and standardize user-generated video content

👉 [Learn more about image and video transformations with Uploadcare](https://uploadcare.com/products/transformations/)

## Encoding and Handling User-Generated Video Content

Let’s say you’re building a platform for pasta lovers who can share their favourite recipes or host live workshops. Asking users to upload video files of certain types can create friction. On the other hand, delivering files as they are can affect your web performance at low bit rates and grossly inflate traffic costs.

That’s why the best practice is to receive files as they are and encode them programmatically upon delivery. This can be done by setting up file encoding functionality, but that’s obviously not the best option in terms of time and money. Instead, you can take a buy-don’t-build approach and use a third-party image CDN with video encoding support.

Uploadcare has a built-in image CDN that takes on all the video handling, including video storage, editing, and reformatting, so you can focus on your core product.

**Case study:** Polished is a marketplace that offers job seekers to get video feedback from hiring professionals. The team had to implement video uploading, processing, and delivery to get the service up and running.

If done in-house, such infrastructure would’ve taken considerable time and resources, so they integrated Uploadcare: an out-of-the-box API-based solution. As a result, they launched the product in just two months and now handle video files up to 400 MB with no sweat.

👉 [Read the full story](https://uploadcare.com/customers/polished/)

## So, WebM, MP4, or Ogg? Choose Your Fighter!

Now you know the difference between popular video file formats and what actually makes that difference. Hint: codecs and containers do! Choose your file stack wisely and consider delegating file handling to a trusted provider. Reinventing the wheel when it comes to video may turn out to be a great waste of time and resources.