# Codecs

## Video codecs

The codec status table is a complete list of all supported codecs, regenerated daily. Some binary codecs for use with MPlayer are available in the download section of our homepage.

The most important ones above all:

- MPEG-1 (VCD) and MPEG-2 (DVD) video

- native decoders for all DivX variants, 3ivX, M$ MPEG-4 v1, v2 and other MPEG-4 variants

- native decoder for Windows Media Video 7/8 (WMV1/WMV2), and Win32 DLL decoder for Windows Media Video 9 (WMV3), both used in `.wmv` files

- native Sorenson 1 (SVQ1) decoder

- native Sorenson 3 (SVQ3) decoder

- 3ivx v1, v2 decoder

- Cinepak and Intel Indeo codecs (3.1,3.2,4.1,5.0)

- MJPEG, AVID, VCR2, ASV2 and other hardware formats

- VIVO 1.0, 2.0, I263 and other H.263(+) variants

- FLI/FLC

- RealVideo 1.0 & 2.0 from libavcodec, and RealVideo 3.0 & 4.0 codecs using RealPlayer libraries

- native decoder for HuffYUV

- Various old simple RLE-like formats

If you have a Win32 codec not listed here which is not supported yet, please read the codec importing HOWTO and help us add support for it.

### FFmpeg/libavcodec

FFmpeg contains libavcodec, the leading open source video and audio codec library. It is capable of decoding most multimedia formats, usually at higher speeds than the alternatives, and aims to add support for the rest of them eventually. It is the default decoder for the majority of codecs that MPlayer supports. Encoding is also possible for some formats and supported in MEncoder.

For a complete list of supported video and audio codecs please visit the FFmpeg homepage.

MPlayer contains libavcodec. Just run `./configure` and compile.

### Xvid

Xvid is a free software MPEG-4 ASP compliant video codec, which features two pass encoding and full MPEG-4 ASP support, making it a lot more efficient than the well-known DivX codec. It yields very good video quality and good performance due to CPU optimizations for most modern processors.

It began as a forked development of the OpenDivX codec. This happened when ProjectMayo changed OpenDivX to closed source DivX4, and the non-ProjectMayo people working on OpenDivX got angry, then started Xvid. So both projects have the same origin.

Note that Xvid is not necessary to decode Xvid-encoded video. libavcodec is used by default as it offers better speed.

#### Installing Xvid

Like most open source software, it is available in two flavors: official releases and the CVS version. The CVS version is usually stable enough to use, as most of the time it features fixes for bugs that exist in releases. Here is what to do to make Xvid CVS work with MEncoder (you need at least autoconf 2.50, automake and libtool):

1.     cvs -z3 -d:pserver:anonymous@cvs.xvid.org:/xvid login

2.     cvs -z3 -d:pserver:anonymous@cvs.xvid.org:/xvid co xvidcore

3.     cd xvidcore/build/generic

4.     ./bootstrap.sh

5.     ./configure

   You may have to add some options (examine the output of `./configure --help`).

6.     make && make install

7. If you specified `--enable-divxcompat`, copy `../../src/divx4.h` to `/usr/local/include/`.

8. Recompile MPlayer with `--with-xvidlibdir=/path/to/libxvidcore.a` `--with-xvidincdir=/path/to/xvid.h`.

### x264

#### What is x264?

x264 is a library for creating H.264 video streams. It is not 100% complete, but currently it has at least some kind of support for most of the H.264 features which impact quality. There are also many advanced features in the H.264 specification which have nothing to do with video quality per se; many of these are not yet implemented in x264.

##### Encoder features

- CAVLC/CABAC

- Multi-references

- Intra: all macroblock types (16x16, 8x8, and 4x4 with all predictions)

- Inter P: all partitions (from 16x16 down to 4x4)

- Inter B: partitions from 16x16 down to 8x8 (including SKIP/DIRECT)

- Ratecontrol: constant quantizer, constant bitrate, single or multipass ABR, optional VBV

- Scene cut detection

- Adaptive B-frame placement

- B-frames as references / arbitrary frame order

- 8x8 and 4x4 adaptive spatial transform

- Lossless mode

- Custom quantization matrices

- Parallel encoding of multiple slices

- Interlacing

#### What is H.264?

H.264 is one name for a new digital video codec jointly developed by the ITU and MPEG. It can also be correctly referred to by the cumbersome names of "ISO/IEC 14496-10" or "MPEG-4 Part 10". More frequently, it is referred to as "MPEG-4 AVC" or just "AVC".

Whatever you call it, H.264 may be worth trying because it can typically match the quality of MPEG-4 ASP with 5%-30% less bitrate. Actual results will depend on both the source material and the encoder. The gains from using H.264 do not come for free: Decoding H.264 streams seems to have steep CPU and memory requirements. For instance, on a 1733 MHz Athlon, a DVD-resolution 1500kbps H.264 video requires around 35% CPU to decode. By comparison, decoding a DVD-resolution 1500kbps MPEG-4 ASP stream requires around 10% CPU. This means that decoding high-definition streams is almost out of the question for most users. It also means that even a decent DVD rip may sometimes stutter on processors slower than 2.0 GHz or so.

At least with x264, encoding requirements are not much worse than what you are used to with MPEG-4 ASP. For instance, on a 1733 MHz Athlon a typical DVD encode would run at 5-15fps.

This document is not intended to explain the details of H.264, but if you are interested in a brief overview, you may want to read The H.264/AVC Advanced Video Coding Standard: Overview and Introduction to the Fidelity Range Extensions.

#### How can I play H.264 videos with MPlayer?

MPlayer uses libavcodec's H.264 decoder. libavcodec has had at least minimally usable H.264 decoding since around July 2004, however major changes and improvements have been implemented since that time, both in terms of more functionalities supported and in terms of improved CPU usage. Just to be certain, it is always a good idea to use a recent Subversion checkout.

If you want a quick and easy way to know whether there have been recent changes to libavcodec's H.264 decoding, you might keep an eye on FFmpeg Subversion repository's web interface.

#### How can I encode videos using MEncoder and x264?

If you have the subversion client installed, the latest x264 sources can be gotten with this command:

    svn co svn://svn.videolan.org/x264/trunk x264

MPlayer sources are updated whenever an x264 API change occurs, so it is always suggested to use MPlayer from Subversion as well. Perhaps this situation will change when and if an x264 "release" occurs. Meanwhile, x264 should be considered very unstable, in the sense that its programming interface is subject to change.

x264 is built and installed in the standard way:

    ./configure && make && sudo make install

This installs libx264.a in /usr/local/lib and x264.h is placed in /usr/local/include.

With the x264 library and header placed in the standard locations, building MPlayer with x264 support is easy. Just run the standard:

    ./configure && make && sudo make install

The `./configure` script will autodetect that you have satisfied the requirements for x264.

## Audio codecs

### The most important audio codecs above all:

- MPEG layer 1/2/3 (MP1/2/3) audio (native code, with MMX/SSE/3DNow! optimization)

- Windows Media Audio 7 and 8 (AKA WMAv1 and WMAv2) (native code, with libavcodec)

- Windows Media Audio 9 (WMAv3) (using DMO DLL)

- AC-3 Dolby audio (native code, with MMX/SSE/3DNow! optimization)

- AC-3 passing through sound card hardware

- AAC

- Ogg Vorbis audio codec (native library)

- RealAudio: DNET (low bitrate AC-3), Cook, Sipro and ATRAC3

- QuickTime: Qualcomm and QDesign audio codecs

- VIVO audio (g723, Vivo Siren)

- Voxware audio (using DirectShow DLL)

- alaw and ulaw, various gsm, adpcm and pcm formats and other simple old audio codecs

- Adaptive Multi-Rate (AMR) speech codecs

### Software AC-3 decoding

This is the default decoder used for files with AC-3 audio.

The AC-3 decoder can create audio output mixes for 2, 4, or 6 speakers. When configured for 6 speakers, this decoder provides separate output of all the AC-3 channels to the sound driver, allowing for full "surround sound" experience without the external AC-3 decoder required to use the hwac3 codec.

Use the `-channels` option to select the number of output channels. Use `-channels 2` for a stereo downmix. For a 4 channel downmix (Left Front, Right Front, Left Surround and Right Surround outputs), use `-channels 4`. In this case, any center channel will be mixed equally to the front channels. `-channels 6` will output all the AC-3 channels as they are encoded - in the order Left, Right, Left Surround, Right Surround, Center and LFE.

The default number of output channels is 2.

To use more than 2 output channels, you will need to use OSS, and have a sound card that supports the appropriate number of output channels via the SNDCTL_DSP_CHANNELS ioctl. An example of a suitable driver is emu10k1 (used by Soundblaster Live! cards) from August 2001 or newer (ALSA CVS is also supposed to work).

### Hardware AC-3 decoding

You need an AC-3 capable sound card, with digital out (S/PDIF). The card's driver must properly support the AFMT_AC3 format (C-Media does). Connect your AC-3 decoder to the S/PDIF output, and use the `-ac hwac3` option. It is experimental but known to work with C-Media cards and Soundblaster Live! + ALSA (but not OSS) drivers and DXR3/Hollywood+ MPEG decoder cards.

### libmad support

libmad is a multiplatform, integer (internally 24bit PCM) only MPEG audio decoding library. It does not handle broken files well, and it sometimes has problems with seeking, but it may perform better on FPU-less (such as ARM) platform than mp3lib.

If you have a proper installation of libmad, `./configure` will notice and support for MPEG audio decoding via libmad will be built automatically.

### Hardware MPEG audio codec

This codec (selected by `-ac hwmpa`) passes through MPEG audio packets to hardware decoders, such as the ones found in full-featured DVB cards and DXR2 adapters. Don't use it in combination with any other audio output device (such as OSS and ALSA) that isn't able to decode it (you will hear only white noise).

### AAC codec

AAC (Advanced Audio Coding) is an audio codec sometimes found in MOV and MP4 files. An open source decoder called FAAD is available from . MPlayer includes a CVS snapshot of libfaad 2.1 beta, so you do not need to get it separately.

If you use gcc 3.2 which fails to compile our internal FAAD or want to use the external library for some other reason, download the library from the download page and pass `--enable-faad-external` to `./configure`. You do not need all of faad2 to decode AAC files, libfaad is enough. Build it like this:

    cd faad2/
    sh bootstrap
    ./configure
    cd libfaad
    make
    make install

Binaries are not available from audiocoding.com, but you can (apt-)get Debian packages from Christian Marillat's homepage, Mandrake/Mandriva RPMs from the P.L.F and Fedora RPMs from Livna.

### AMR codecs

Adaptive Multi-Rate speech codec is used in third generation (3G) mobile phones. Reference implementation is available from The 3rd Generation Partnership Project (free for private use). To enable support, download and install support libraries for AMR-NB and AMR-WB following the instructions on that page. Recompile MPlayer afterwards.

## Win32 codecs importing HOWTO

### VFW codecs

VFW (Video for Windows) is the old Video API for Windows. Its codecs have the `.DLL` or (rarely) `.DRV` extension. If MPlayer fails at playing your AVI with this kind of message:

    UNKNOWN video codec: HFYU (0x55594648)

It means your AVI is encoded with a codec which has the HFYU fourcc (HFYU = HuffYUV codec, DIV3 = DivX Low Motion, etc.). Now that you know this, you have to find out which DLL Windows loads in order to play this file. In our case, the `system.ini` contains this information in a line that reads:

    VIDC.HFYU=huffyuv.dll

So you need the `huffyuv.dll` file. Note that the audio codecs are specified by the MSACM prefix:

    msacm.l3acm=L3codeca.acm

This is the MP3 codec. Now that you have all the necessary information (fourcc, codec file, sample AVI), submit your codec support request by mail, and upload these files to the FTP site: ftp://upload.mplayerhq.hu/MPlayer/incoming/<codecname>/

On Windows NT/2000/XP search for this info in the registry, e.g. search for "VIDC.HFYU". To find out how to do this, look at the old DirectShow method below.

### DirectShow codecs

DirectShow is the newer Video API, which is even worse than its predecessor. Things are harder with DirectShow, since

- `system.ini` does not contain the needed information, instead it is stored in the registry and

- we need the GUID of the codec.

#### New Method:

Using Microsoft GraphEdit (fast)

1. Get GraphEdit from either DirectX SDK or doom9.

2. Start `graphedit.exe`.

3. From the menu select Graph Insert Filters.

4. Expand item DirectShow Filters.

5. Select the right codec name and expand item.

6. In the entry DisplayName look at the text in winged brackets after the backslash and write it down (five dash-delimited blocks, the GUID).

7. The codec binary is the file specified in the Filename entry.

If there is no Filename and DisplayName contains something like device:dmo, then it is a DMO-Codec.

#### Old Method:

Take a deep breath and start searching the registry...

1. Start `regedit`.

2. Press Ctrl F, disable the first two checkboxes, and enable the third. Type in the fourcc of the codec (e.g. `TM20`).

3. You should see a field which contains the path and the filename (e.g. `C:\WINDOWS\SYSTEM\TM20DEC.AX`).

4. Now that you have the file, we need the GUID. Try searching again, but now search for the codec's name, not the fourcc. Its name can be acquired when Media Player is playing the file, by checking File Properties Advanced. If not, you are out of luck. Try guessing (e.g. search for TrueMotion).

5. If the GUID is found you should see a FriendlyName and a CLSID field. Write down the 16 byte CLSID, this is the GUID we need.

If searching fails, try enabling all the checkboxes. You may have false hits, but you may get lucky...

Now that you have all the necessary information (fourcc, GUID, codec file, sample AVI), submit your codec support request by mail, and upload these files to the FTP site: ftp://upload.mplayerhq.hu/MPlayer/incoming/<codecname>/

If you want to add a codec yourself, read DOCS/tech/codecs.conf.txt.