Introducing WebM

Today, Google, in co-operation witt Opera, Mozilla, CoreCodec (Matroska developers) and a range of other companies, have announced at Google I/O 2010 that WebM is the new royalty free video codec for the web.

Earlier this year, Google purchased On2, the company that developed of a range of video codecs including VP3, VP6, VP7 and VP8. VP3 is a well known codec that formed the basis of Theora. VP6 is a codec supported by Adobe Flash, VP7 is used by Skype for video conferencing. Their latest offering, VP8, now forms the basis of the new WebM video format. The code for the VP8 codec has been released royalty free under the BSD licence.

WebM, which stands for Web Media, is a format based on 3 technologies:

  1. Container: A variation of Matroska called WebM.
  2. Video codec: VP8.
  3. Audio codec: Vorbis.

The Container Format

Matroska is a widely supported container format, which is able to contain a wide range of codecs, including, among others, h.264, VC-1, Theora, AAC, AC3 and Vorbis. This is due to the high degree of flexibility inherent in the design of Matroska.

Matroska itself if based on a binary markup language called EBML, the design of which was inspired by XML. In short, EBML files contain a header that declares the DocType and version information, followed by a tree of elements and data, marked up using a special binary notation. The Matroska specification defines a range of elements, and their binary notation, that can be used for marking up the data in Matroska files.

The WebM format is a subset of Matroska, which has been optimised for streaming over HTTP.

WebM, which uses the DocType “webm”, can be distinguished from Matroska, which uses the DocType “matroska”. Technically speaking, a valid WebM version 1 file supports a subset of elements from Matroska version 1, and WebM version 2 supports those in addition to some of the additional elements from Matroska version 2.

To further optimise WebM for use on the WebM, some additional formatting guidelines are imposed upon WebM files, over and above the Matroska counterpart. These guidelines include plaicing the indexing information at the beginning of the file, and keyframes stored at the beginning of clusters.

The WebM container is only permitted to contain the codecs VP8 and Vorbis, and browsers will not support any other codecs within WebM – not even Theora or h.264. Although there are no technical limitations with WebM that inherently prevent such codecs from being used, this was an intentional decision to improve the usability of WebM.

The idea being that if you have a player that supports WebM, you can be more confiden that the file will play without having to install additional codecs. This is a problem that has plagued container formats like AVI for years. You can’t easily determine what it contains until you start playing it. Some AVI files may contain DivX, Xvid, h.264 or a wide range of other codecs.

Benefits of Matroska

Matroska presented some nice benefits over competing container formats, sucha s MP4, commonly used with h.264, or even Ogg, which is supported by Opera, Firefox and Chrome for Theora and Vorbis. Like Ogg, Matroska is publicly specified and available to use freely, unlike, for example, MP4.

The main benefit of Matroska over Ogg is that the seeking information can be placed at the beginning, making it significantly easier to seek in a WebM file being transferred over HTTP. When the user tries to seek, if that part of the video hasn’t yet downloaded, then the browser needs to request that section from the server.

For Ogg, browsers have to do at least 2 separate requests when a video loads — one to get the beginning of the file and a range request to get the end — before the length of the video can be determined, and before seeking can occur, which then potentially results in additional requests.

For WebM, all the information is presented up front, meaning that if a user seeks the video, the browser knows exactly where in the video to go, or which part of the file to request from the server.

This is not to say that Ogg itself is a bad format. Quite the contrary, it’s just optimised for different use cases. Ogg is very good to use as a streaming container format where seeking is not required, or for storing your Vorbis encoded music collection locally, where the player isn’t subject to the overhead of HTTP requests.

WebM, on the otherhand, had to be specifically designed for use with the HTML video element served over HTTP, and as such, benefited from the design decisions of Matroska.

Audio and Video Codecs

The VP8 codec provides significant quality enhancements over its predecessors; most notably Theora. Comparisons between Theora and h.264 have shown that the quality of Theora is not up to scratch. Thanks to Google, VP8 has now been released freely.

There haven’t yet been any serious, independent comparisons between h.264 and VP8, so it’s difficult to say which is better. Although h.264 is certainly more mature than VP8, and has a lot more hardware support in existing devices, VP8 is likely to continually improve over the coming years.

The main limitation with VP8 at the moment is the lack of hardware acceleration. Firefox, Opera and Chrome all currently use software decoding of VP8, which means that it can increase CPU usage, particularly for high definition videos, and watching a lot of video will drain your battery more than hardware decoded h.264.

However, Google have announced that they are working with hardware partners, and its possible that we’ll see devices shipping with support within a year or two.

Vorbis, of course, has been supported by Firefox, Opera and Chrome for a while already, and so it was a natural choice to use in combination with VP8 in WebM.

YouTube

Over the past few weeks, YouTube has been working to convert many existing videos into WebM. To try this out using a browser that supports WebM, follow the instructions provided by the WebM Project. While not all videos have been re-encoded yet, thousands of videos are already available in WebM format, and will work in Opera, Firefox and Chrome.

Demo Time

Just so you can see for yourself what VP8 looks like, get yourself a copy of the preview releases of Opera, Firefox and Chrome, sit back, relax and watch Elephant’s Dream from the Orange Open Movie Project (website). I encoded this myself from the lossless source files using a special build of ffmpeg with libvpx_vp8 (the VP8 codec library).

Creating Your Own Videos

The absolute easiest way to create your own WebM video is to upload your source video to YouTube and wait for it to be encoded. Other services, including encoding.com and HD Could also offer transcoding services for a small fee.

If you want to encode the videos yourself, you need to get your hands dirty with a tool like ffmpeg with libvpx_vp8, or a commercial alternative. Google have released the source code for libvpx_vp8, and builds of ffmpeg with it should be available shortly. More information is available on the The WebM Project tools page

The Matroska developers have also been working on on updating their Matroska muxing software to support the WebM profile. New tools called mkvalidator and mkclean will help you to validate your WebM files, and to clean and remux files that aren’t valid. mkclean will also remux MKV files containing VP8/Vorbis to WebM.

Browser Support

Preview releases have been released for Opera, Mozilla Firefox and, of course, Google Chrome.

More details are available on WebMProject.org.

13 thoughts on “Introducing WebM

  1. Hi, what was your command line to encode to WebM/Vorbis in a Matroska container?

  2. http://x264dev.multimedia.cx/?p=377 is the best comparative analysis I’ve found so far. It’s at a spec and code level though – no testing actual media.

    The summary is that the author thinks WebM is an improvement over Theora, fairly comparable to h264 baseline, not as good as h264 main profile, decoding cost is fairly high, likely that it infringes h264 patents (but time will tell).

  3. Works very good, smooth and stable in Firefox build (not tested yet in Opera due to missing library dependencies).

    What is interesting is that aside that seeking works very good i have small latency problem with it. When you will seek somehwere in the file (doesn’t depend if it is already in cache or not, or if it is forward or backward), I always get audio first and still video frame for about 1 second, after this 1 second (in which audio is playing) i got video playing actually.

    So kind of synchronisation problem i suppose.

    (Linux build here)

  4. Could you write a short tutorial on how to encode with ffmpeg?

  5. Manuel: Official ffmpeg svn can’t yet encode into webm. However, as of a day or two ago, it can read webm files and transcode them into a different format. I was able to take the webm file from here and turn it into an mp4 video with just the command “ffmpeg intput.webm output.mp4”. Once webm encoding makes it into the ffmpeg tree, the reverse will work just as easily.

    If you wish to try encoding now, you can follow the directions here: http://www.webmproject.org/tools/#ffmpeg_patches to get the required patches to ffmpeg and then build libvpx and ffmpeg.

  6. @Manuel: I am in the mail-list and asked once which parameters were the best to encode a video in two-pass with little size. After a few mails I got the following code:

    ffmpeg -pass 1 -passlogfile pass1.fpf -i original.file -threads 4 -vcodec libvpx_vp8 -altref 1 -token_partitions 2 -lag 16 -keyint_min 0 -g 360 -mb_static_threshold 0 -skip_threshold 0 -level 116 -qmin 1 -qmax 51 -minrate 0 -maxrate 900k -an pass1.webm

    ffmpeg -pass 2 -passlogfile pass1.fpf -i original.file -threads 4 -vcodec libvpx_vp8 -vb 300k -altref 1 -token_partitions 2 -lag 16 -keyint_min 0 -g 360 -mb_static_threshold 0 -skip_threshold 85 -level 116 -qmin 1 -qmax 51 -minrate 0 -maxrate 900k -acodec libvorbis -aq 2 -ar 44100 finalfile.webm

    Replacing original.file and finalfile.webm for the wanted file names. Also you can replace the numbers on -vb and -aq with higher numbers if you don’t care about the extra space.

  7. I couldn’t succed in compiling mkclean nor mkvalidator for Ubuntu Lucid
    I’ve run run ./bootstrap.sh then in /mkvalidator or /mkclean :
    sudo make
    sudo checkinstall
    i can see that the package is installed in Synaptic but i can’t run the tol from the command line…
    any idea please ?
    + any chance to get a PPA for these tools ?

  8. antistress, you first need to compile and install coremake, which is included in the tarball. This is how I compiled them on Mac.

    
    cd corec/tools/coremake/
    ./build.sh
    cd ../../../
    coremake gcc_osx_x86
    make all
    

    Look at the files in the coremake directory and see which profile is appropriate for your system. Substitute that for gcc_osx_x86 above.

    This will build mkclean, mkvalidator and mkvtree for you. The binaries will be located in ./release/gcc_osx_x86/ (or the folder named appropriately for the profile you used).

    If you want to install them, then do:

    sudo mv release/gcc_osx_x86/mk* /usr/local/bin/
  9. Excellent, thank you very much 🙂

    This is how I compiled them on Ubuntu 32bits.

    cd corec/tools/coremake/
    ./build.sh
    cd ../../../
    coremake gcc_linux
    make all

    sudo mv release/gcc_linux/mk* /usr/local/bin/

Comments are closed.