Learn Measure Blog Live About

Containers and codecs

Containers and codecs

Updated
Appears in: Media

To support multiple browsers, you'll need to use FFmpeg to convert your mov file to two different containers: an MP4 container and a WebM container. In actual practice, you would likely specify a codec at the same time. For now, I'm letting FFmpeg use its defaults.

To create the MP4:

ffmpeg -i glocken.mov glocken.mp4

To create the WebM:

ffmpeg -i glocken.mov glocken.webm

To create this article, I used FFmpeg version 4.2.2-tessus. If the command lines don't work for your version of FFmpeg, consult the FFmpeg documentation.

Webm takes longer to create than MP4. This isn't surprising when you look at the results. While MP4 compresses to about two-thirds of the original file's size, WebM is down to a mere fraction of the original's size. Though, your results may vary. You can see this for yourself using the ls -a bash command in the folder where your media files are located. For example:

-rw-r--r-- 1 jmedley  eng  12080306 Apr 21 13:13 glocken.mov
-rw-r--r-- 1 jmedley eng 10146121 Apr 21 13:25 glocken.mp4
-rw-r--r-- 1 jmedley eng 491743 Apr 21 13:30 glocken.webm

Check your work

To verify your results, use FFmpeg and Shaka Packager as already shown in Media Application basics:

packager input=glocken.mp4 --dump_stream_info
ffmpeg -i glocken.mp4

Codecs

Next the codec. As stated in Media file basics, a codec is not the same thing as a container (file type). Two files of the same container type could hold data compressed using different codecs. The WebM format for example allows audio to be encoded using either vorbis or opus. To change the codec I use FFmpeg. For example, this command outputs an mkv file with a vorbis audio codec and an av1 video codec.

ffmpeg -i glocken.mov -c:a vorbis -c:v av1 glocken.mkv

In this example, the -c:a flag and the -c:v are for specifying the audio and video codecs respectively.

The cheat sheet lists commands needed to convert codecs. The tables below summarize the libraries used in FFmpeg to perform the codec conversions for WebM and MP4 files. These are the formats recommended for DASH and HLS respectively.

Video

Codec Extension Library
av1 WebM
mkv
libaom-av1
h264 MP4 libx264
vp9 WebM libvpx-vp9

Audio

Codec Extension Library
aac MP4 aac
opus WebM libopus
vorbis WebM libvorbis

Next, I'll show you how to change the file's bitrate.

Last updated: Improve article