From .mov to web-ready media

To serve video across browsers, you'll typically need two containers: MP4 and WebM. Converting a source .mov file into both formats with FFmpeg is straightforward. In practice, you'd also specify codecs at conversion time, but the commands below let FFmpeg apply its defaults.

These steps assume you have FFmpeg installed (for example, via Docker, as described in Media application basics) and that your input file, glocken.mov, is in a media directory. All commands here were tested with FFmpeg version 4.3.2. If container and codec terminology is unfamiliar, review Media file basics first.

Creating the containers

Generate an MP4 and a WebM file, each carrying both audio and video streams:

  1. MP4:

    /media # ffmpeg -i glocken.mov glocken.mp4
    
  2. WebM:

    /media # ffmpeg -i glocken.mov glocken.webm
    

Expect WebM encoding to take longer than MP4. File sizes will vary by source, but WebM often compresses more aggressively. Note that FFmpeg 4.2.2 defaulted the video bitrate to 200k, while 4.3.2 sets no default; this directly affects output size. To inspect the resulting sizes, use ls -a in your media folder:

/media # ls -l
-rw-r--r-- 1 root  root  12080306 Mar 7 12:16 glocken.mov
-rwx------ 1 root  root  10106446 Mar 7 12:33 glocken.mp4
-rwx------ 1 root  root   9503301 Mar 7 18:30 glocken.webm

To deliberately produce a smaller file, explicitly request a lower bitrate:

/media # ffmpeg -i glocken.mov -b:v 200k glocken.webm
...
frame=  300 fps=3.6 q=0.0 Lsize=     483kB time=00:00:10.01 bitrate= 395.0kbits/s speed=0.121x
video:359kB audio:117kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.356068%
/media # ls -l
-rw-r--r-- 1 root  root  12080306 Mar 7 12:16 glocken.mov
-rwx------ 1 root  root  10106446 Mar 7 12:33 glocken.mp4
-rwx------ 1 root  root    494497 Mar 7 18:45 glocken.webm

Verifying the output

Confirm the container and stream details with FFmpeg or Shaka Packager, as described in Media application basics:

/media # packager input=glocken.mp4 --dump_stream_info
/media # ffmpeg -i glocken.mp4

Switching codecs

A codec is distinct from a container: two files with the same extension may store data compressed with different codecs. For example, WebM permits audio encoded as Vorbis or Opus. FFmpeg lets you change codecs explicitly. The following command produces an .mkv file using Vorbis for audio and AV1 for video:

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

Here, -c:a selects the audio codec and -c:v the video codec. For step-by-step codec conversion instructions, see the Media conversion guide. The tables below list the FFmpeg libraries recommended for WebM and MP4 files, the formats suggested for DASH and HLS respectively.

Video libraries

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

Audio libraries

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

Once your files are in the right containers with the right codecs, the next step is adjusting the bitrate.