Video Codecs and the Free World
Few video producers ever would have guessed that the term codec would become a household term, but with so many codecs on the market, average computer users have little choice but to be painfully aware that if their computer does not have the correct codec installed, they will not be able to view their favorite Web or DVD video content. Therefore, any computer enthusiast, professional sysadmin or video producer should be familiar with codecs, why they exist and how to deal with them.
The term codec is a combination of two words: code and decode. The concept is simple; if I had only one page of paper upon which I wanted to write two pages of content, I might write a note in some kind of code, leaving out certain letters or words. This would fit the content onto the one page allotted, but it would make no sense to intended readers, unless I gave those readers a key on how to decode the writing so they could piece it all back together and understand what had been written. This is precisely what a codec does with video.
Ideally, a codec effectively delivers high-quality video to end users in a reasonable amount of download time. However, large companies often opt to use a codec for its exclusivity so they can charge for the key to decode that video, such as with DVDs and streaming video. So the reason that many codecs exist at all is not to further the quality and effectiveness of video compression and delivery, but to hinder delivery to the nonpaying audience—sometimes even at the expense of video quality.
End users, system administrators and video content producers are all affected by codec compatibility and availability. Being familiar with codecs is important, as computers are now the hub of many people's entertainment centers.
A missing codec typically affects the entire system. If, for example, Xvid is not installed on the system, Xvid will not be available for Web browsers, media players or media editors. Install the Xvid component, and all of the applications on a GNU/Linux system will recognize it and utilize it when needed.
With proprietary software, even though a system has a codec installed, proprietary applications may not utilize the codec, simply because it has been programmed not to use the codec for political reasons. There is no practical reason, for instance, that Digidesign's Avid or Apple's Final Cut Pro cannot recognize and edit Ogg files, especially given the price tags of these applications.
Keep in mind that there is a difference between a codec and a file format. File formats, such as .mp4, .mov or .avi, are actually just containers for video and audio streams. So an .mp4 file, for example, may use a codec like Xvid, h.264, x264, Decklink and so on, or it may, in fact, use the actual MPEG-4 codec (or any number of other codecs). Although the system usually can detect the actual codec being used within a file, it may confuse the user if a file format (container) is taken to be the same thing as a codec (encoder).
Most systems come with a certain amount of codecs ready to use with the OS's default Web browser and media player. Apple and Microsoft bundle their own proprietary and supported codecs with their systems, and Linux distros distribute their supported open-source codecs. Still, in all three cases, end users or system administrators are going to have to download non-bundled and unsupported codecs at some point.
On today's systems, acquiring codecs often is reduced to a few clicks of the mouse. The smoothest experience for end users may easily be on the Linux desktop, as distributions, such as Ubuntu, Linspire, Fedora and OpenSUSE, are so sensitive to the Linux-doesn't-play-media preconception that they have made it almost automated.
To get a codec to watch DVDs on your Linux machine, simply place a DVD into the computer, and the default player opens (such as Totem or Kaffeine or Xine). If an MPEG-2 decoder is not installed already, the system offers to download and install it. A few clicks of the mouse, and the codec is installed, and the movie player, usually without so much as a relaunch, plays the DVD.
Similarly, most Web browsers will detect a missing codec and either direct users to the Web site containing the downloadable installer for the codec, or, even better, the system will intervene and offer to download and install the package automatically. Again, with a few clicks of the mouse, the codec is installed and ready to enable the video in the browser.
If the Web browser attempts to play a video without the proper codec installed, there are cases where the only feedback the user will get is a blank space where the video should be. You can, however, easily force the system to prompt for a codec download.
First, right-click on the empty space in the browser where the video should be playing, and open that movie (it may be missing sound and picture though) in your distro's default movie player. When the system's media player is unable to play the video, it will offer to find the appropriate codec and install it.
If the Linux system does not recognize the codec being used, or if your distro of choice does not offer an automated codec solution, you can do a little detective work and discover what codec you need to find and install it manually.
This kind of codec forensics is most easily done with VideoLAN's VLC player; it's free, open source and prepackaged for most popular Linux distros. Once you've installed VLC player on your system, open the movie you want to play. Most likely, VLC will play the video, but if you still need to discover its codec so that the video can play on your system outside the VLC player, go to the View menu and select Stream and Video Info. This opens a comprehensive list of the streams (video, audio, timecode, subtitle and so on) contained in the file and what codec was used in creating each stream.
Armed with this information, go back to your distribution's package manager, and search for the codec that VLC has revealed is being used. Or, if you are running Slackware or Gentoo or something similar, seek out the codec on-line. A typical open-source solution will be a GStreamer package, containing a number of open-source decoders for popular proprietary codecs. Again, these can be installed either via your package manager or manually.
If you are trying to achieve in-browser playability, be aware that sometimes a decoding package, such as Flash, will be specific to the Web browser in which you are trying to view video. So, take care to install the correct package for compatibility with your browser (Firefox, Konqueror, Opera and so on).
After you've installed the codec, relaunch your browser if necessary, and try to play the video again.
Whether you are encoding video you have produced and want to distribute or are taking video from one source and transcoding it into a format more friendly to your system, there are handy open-source encoders that generate video files playable by many popular consumer content players. The most effective is the FFmpeg program—sometimes wrapped in a GUI and sometimes used strictly on the command line. The FFmpeg man page is extensive but fairly easily to use.
Video encoding is best learned by doing, and although there are many important variables when encoding video, there are no magic settings; they change in relation to the target size of the video as well as the actual content (for example, how frequently pixels change chroma or luma values from one video frame to another).
To encode a video, first make sure you have FFmpeg installed on your system. If not, add it via the command line (sudo apt-get install ffmpeg on Debian systems), or use your distribution's package manager.
The command to encode looks like this:
ffmpeg -i [filename] -vcodec [codec to use] -s [target frame size] ↪-b [target bit rate in kbps] -r [target frames per second] ↪-acodec [audio codec to use] -pass 2 -ar [target audio sample rate] ↪-ab [audio bit rate in kbps] -f [target file format] [output filename]
For example:
ffmpeg -i bigmovie.m4v -vcodec xvid -s 720x480 -b 3000k -r 24 ↪-acodec libfaac -pass 2 -ar 128k -f .mp4 freemovie.mp4
The example above transcodes a video from a proprietary MPEG-4 format into the open-source codec of Xvid with libfaac sound, in a standard definition frame size and a fairly high video quality.
The important variables are frame size (-s), as it determines scalability of the video, and bit rate (-b for video and -ar for audio), which determines how much information is being sent per video frame—the higher the bit rate, the sharper and nicer the image will be but also the file size will be larger. Finally, the -pass variable determines how much preprocessing the encoder will do to the video. In one-pass mode, the encoding is done fairly quickly and not always optimally. With two-pass encoding, FFmpeg reviews the video file once, gathers necessary data, and then does the actual encoding on the second pass. The end result is a higher quality compression, but you can expect double or triple the encoding time.
The other popular way of transcoding video is with GUI programs that rip video from encoded DVDs, making them viewable in an unrestricted codec. This also is ideal for creating a home media server, with your entire movie collection digitized and ready to play at any moment. Obviously, the legality of this varies from day to day and from country to country. However, the GUI programs are plentiful and utilize the same variables as FFmpeg. You will need to set the video codec to which you want to save your video, the audio codec, the bit rates of each, frame size and so on.
The great codecs of the Free Software movement, Ogg Vorbis and Ogg Theora, are obviously very well supported on GNU/Linux. Generating them is done easily with ffmpeg2theora. The command-line variables for ffmpeg2theora are similar to those for FFmpeg:
ffmpeg2theora [filename] -x [target horizontal pixel count] ↪-y [target vertical pixel count] -V [target bi trate in kbps] ↪-A [audio bit rate] -c [audio channels] -H [audio sample rate] ↪-o [output filename]
When it became clear to the Open Source movement that video codecs were doomed to remain proprietary and counter-productive, the Ogg format was born. Open to all and freely available to any system, Ogg Vorbis (for sound) and Ogg Theora (for video) are advanced and fully featured codecs.
A common argument against using Ogg is that it requires users of Microsoft and Apple products (or, the majority of computer users) to seek out a suitable player. Yet, it's clear by now that requiring users to download a media player or media plugin is not at all uncommon and will quite probably become even more common as content delivery becomes more Internet-reliant and computer-centric. People today expect to have to download a video player to watch certain video content. The real problem with Ogg is that there is no ubiquitous media player for the format; RealPlayer has Real Media, QuickTime has QuickTime Player, Windows Media has Windows Media Player, Flash has Flash Player and so on. People easily can find those, but where do they go for Ogg playback?
Promote both free software and free codecs by promoting Ogg formats, but don't fail to promote a player that easily and effectively plays media on all major platforms. One of the better players for this job is VLC player, which installs on Windows, Mac OS X, GNU/Linux, BSD, BeOS and Solaris. Another is miro, an iTunes-like aggregator of video podcasts, IP TV and YouTube, as well as media on your local machine. Both play Ogg, so send a link to the player along with the Ogg clips you distribute.
The fact is, and will remain, that open-source tools are the saving grace of video professionals and system administrators working in a multiplatform multimedia world. FFmpeg and VLC Player have both been trusted playback, video-analyzing and video-conversion programs in my video toolkit for years, and they solve postproduction problems that proprietary, overpriced editing packages introduce with exclusive codec licenses and incompatibility.
Here are two contrasting examples:
A recent update to Final Cut Suite, Apple's premier video production suite, dropped support for a number of codecs while adding support for Apple's proprietary ones. Being a closed system, there is no solution to this problem, only the work-around of transcoding the source material.
The open-source application Blender supports any codec that its host system supports, and updates can be requested of programmers on Blender's IRC channel, often resulting in a patch within days. Final Cut Studio is well over a thousand dollars per client license. Blender, of course, is free.
As long as the primary market for codecs are the companies that continue to desire to protect their digital content, new codecs will continue to be developed that will require a separate license to use. This will result in myriad codecs on the Web and in the video production world. And, as long as licenses are required to use proprietary codecs, the more divided and convoluted the delivery methods will become.
Utilize free codecs fearlessly and unify video production as well as delivery. The Open Source movement is stronger than ever, and the Creative Commons ideals in the art world are getting serious press for encouraging freely distributed works by big-name acts like Radiohead and Prince, adventurous independents like the movie Rune, bountiful pod-safe music, the Internet Archive and so on. The climate is such that free codecs have the unique opportunity to become the popular choice for maximized compatibility and end-user freedom.
Seth Kenlon is a film and video editor, systems consultant and software trainer. Concurrently with all of that, he is a Linux user, supporter and promoter.