Video Codecs and the Free World

How codecs are hurting multimedia, how Linux is dealing with it, and why free codecs can save it.
Encoding and Transcoding Video

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]

Using and Promoting Free Codecs

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.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

In later version of ffmpeg

Fanta's picture

In later version of ffmpeg you need to prefix
the video codec with lib

e.g libxvid and not xvid

great explanation

Anonymous's picture

This whole codecs business always felt like a big scam to me, and now I know why- because it is! Thanks for a detailed and helpful article.

Video Codecs

Anonymous's picture

Yes i agree! I would be also happy, if you have explained which kind of video codec is best in current scenario. e.g H.264, MPEG-4, xvid etc

for instance i came across to one blog called: video codecs :pros & Cons

Video codecs

alphakamp's picture

Video codecs in linux and windows have always been a hassle for me. I go so far as to not even bother unless the video format is flash. As far as DVDs I'll put it in a regular DVD player thank you.

As far as DVDs I'll put it

Torres's picture

As far as DVDs I'll put it in a regular DVD player thank you.

Yes it is true.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix