x264 and Xvid Encoding
Wednesday, 11 January 2006
Image I will try and cover both x264 encoding and Xvid for Windows. This is basically updated versions of previous guides, with little tips that I picked up over the years. I will of course be updating this guide with optimizations.

I am NOT a expert on these things, but linking people to doom9.org doesn't help half the time, as that site is more technical then most need, and its focus is different.

 

A 20min episode to 3 hour long, Hollywood movie footage, with large amounts of calm, dialog scenes and more complex features such as multiple audio streams, subtitles and extras.

vs.

Video game footage which in most cases is fast, colorful with lots of scene changes are much more difficult to compress, and encoding time being less important for us, I have set up encodes for estimated time of 2 days.

 

WARNING: I do not promise this guide or my settings will result in a nice looking encode at low file size.

 

Please PM me, or post below: any errors, corrections, suggestions.

Note: with this guide you can only use 25 final project FPS...I will edit the guide when I find a workaround.

 

 

 

 

 

X264

What is x264 - http://forum.doom9.org/showthread.php?t=96059

 

“This is not an official x264 build and may not work at all, destroy all the data on your hard drive or make your house or your dog explode (i doubt it can, though...). I'm not responsible for anything that could happen (i just checkout the SVN, apply some patches and compile the sources) - use it at your own risk .“

 

With that said, I believe x264 is ready for mainstream use, see decoding section.

 

 

Steps to convert your movie to x264.

 

If this is your first time compressing x264, see the file links section. Also see glossary at end of guide for some common terms that you need to know.

 

 

Encoding x264.

(This is how I do it, it is not the best way, just my way.)

 

1. Export the video clip uncompressed with the container .avi out of Vegas/Premiere/whatever your editing program, without an audio stream.

 

If you exported with audio, open up VirtualDubMod:

File / Open -> find your clip then load it. Then go to Streams / Stream list -> click on the audio stream that shows up, then hit the Save as Wav button.

 

2. Export audio as Windows audio [*.wav] uncompressed.

 

3. Uninstall x264 (if installed). Many changes in x264 require a full reinstall of the codec. Install the latest version of x264 and MeGUI.

 

This is the most important link-> http://forum.doom9.org/showthread.php?t=89979

More direct download link-> http://www.free-codecs.com/download/x264_Video_Codec.htm

 

4. To create a simple AviSynth script open up notepad and type:

 

 

AVISource("nameofvideofile.avi")

Crop(0,0,-0,-0)

ConvertToYV12()

 

 

File / Save as-> drop down box to: All Files, "name.avs"

 

 

Time to encode the video. Start / Programs / x264 / command line interface decoder  [might look different on your PC]

Open MeGUI then go to the Tools / Settings -> File Locations

Browse and find all the files, if you dont have em, google them or see end of guide

 

In MeGUI: image 

EDIT: a nice MeGUI guide: http://forum.doom9.org/showthread.php?t=106189

5. AviSynth field-> find your “name.avs” file (loads up a window with your video, good to see if it loaded up, now close that)

 

File type -> ' RAW '

Video output -> whatever you want for a output filename. Default works.

 

6. Hit the 'Config' button, see http://forum.doom9.org/showthread.php?t=101813&page=1&pp=20 for profiles. [ The profiles are now included in the 264 full package] Place profiles in ~\ Program Files \ x264 \ profiles \ video. Use "HQ-Slow" for tests, adjust the bit rate to a 1500 - 2500 range.

Check images for my settings, these are set up for a faster encode on easy q3 tricking content, thats why it's only 1000 bitrate. For a final encode you can adjust the sub pixel mode to 7, ME algo to Multi-Hex and run a auto-3pass.

tab-1

tab-2

meguiconfig3.jpg

I suggest never to use ME algo “Exhaustive”, FPS drops through the floor and improvements on the video are unnoticeable. Uneven Milti-hex is enough.

 

 

7. Hit 'Enqueue' button, go to Queue tab, hit Start button. [you can set multiple jobs of course, just like in virtual dub] This will take a while. It is about ½ to 1/8 as fast as Xvid in some of my encodes.

 

Combine audio and video.

8. Put video and audio together using YAMB. Start \ Programs \YAMB. Go to the Mux tab. Add the audio and video, Hit the 'mux' button. Note this tool is much more powerful then just this task.

 

See decoding section. :)

 

 

 

Xvid Encoding

Xvid is a awesome, stable, mature codec. Very good image quality can be made with Xvid, and with Euro connections of 100 Mbit....filesize matters less to many people. I am going to assume you have encoded Xvid before with this section or at least grasped some concepts with encoding x264. With SMP, AVS and 64bit versions in the works, Xvid is still exciting.

 

1. Grab latest Stable Xvid binary [1.1 released] [ http://www.koepi.org/xvid.shtml ]

 

 

2. Load up VirtualDubMod. File / Open ->video file...load up your file.

Then Streams / Stream list.

While in the Stream box: If there is already an audio stream, because you exported your movie with audio, just select it and disable/delete it. Then hit the 'ADD' button to add the LAME mp3 encoded audio file. Do not rewrite the header, we will not be using avi.

 

3. Now go to Video / Compression. Choose Xvid.

NOTE: If there is more then one showing up, select the one with the FOURCC code 'xvid'.

 

This is where the fun starts.

Read this: http://ronald.vslcatena.nl/docs/xvidfaq.html

 

In many cases, people can take the exact settings of a movie (famously, iT2's settings) and those settings will not work, or will look terrible. You must configure xvid for “your” movie. So learning the settings and what most of them do, is important. But I will give you my settings to get you started, it's an improved iT2/GQ3 config.

 

Settings

Hit restore defaults, everything I don't mention, leave default. Defaults are also, the developer recommended setting for encoding.

 

UPDATED for 1.1 [ 12/30/05 ]

Profile@Level: “unrestricted”

Encoding Type: “Twopass - 1st pass”

Target Bitrate: You decide. Try 2000-3500 [Annihilation used 23xx, some ET footage only looks good with above 3500]

 

'More' button to right of Profile Level

Profile Tab

Custom Quant Matrixes people have made can be found all around, but MPEG-custom works nicely. If you rest your mouse pointer on settings, a tool tip may come up and give you a description that may or may not be any help.

Check -> Adaptive Quant

Check -> Quarter Pixel

Check -> Global Motion Comp

Check -> B-Vops

B-Vop Max: 3

 

Go into Xvid configuration and then the More button.

Motion Search Precision-> 6 ultra High

VHQ mode-> Wide 4

Check-> Use VHQ for B-frames.

Check-> Use chroma motion

 

max I-frame interval: 250

 

Quantization Tab

All Mins-> 2 [when compared to “1”, quality difference is unnoticable, while filesize difference is high]

All Maxs-> 31

Check-> Trellis quantization

 

4. Learn how to use Zones for any trouble areas of the movie. And use Zones to save some file size, such as for the credits. See the Xvid config link for details.

 

5. Hit OK, OK, OK, then File \ Save as..

 

Save file type as .ogm [Ogg Media File]

Check the “save as job to run in batch mode” or similar wording. Hit Ok.

Then Video / Compression -> Xvid, OK, set Twopass 2nd pass. Ok.

 

Save file type as .ogm [Ogg Media File]

Check the “save as job to run in batch mode” or similar wording. Hit Ok.

 

Go to File / Job Control -> Start.

 

Encoding audio

x264 [ .wav -> .acc for mp4. ]

Use "Multifrontend.exe" to encode your audio. Add your audio file(s), and go into Locations find your encoder's .exe locations. Point the program to the FAAC.exe

Right now a simple FAAC encode with "-q 70" preset should be fine.

Update: MeGUI now has a built in audio encoder also, that can replace multifrontend, but still using FAAC

 

Xvid [ .wav -> .mp3 for .avi. ]

Load up LAME.exe or use Multifrontend.exe. (Multifrontend is just that, a front end to make things easier. Most audiophiles like to just use the command line version, with its more options.)

 

Read the LAME documentation or

In DosBox, Navigate to the LAME.exe directory.

 

[ Eg. D:\Encoding apps\lame>lame.exe ]

LAME version 3.95 MMX (http://www.mp3dev.org/)

usage: lame.exe [options] <infile> [outfile]

 

<infile> and/or <outfile> can be "-", which means stdin/stdout.

 

Try:

"lame.exe --help" for general usage information

or:

"lame.exe --preset help" for information on suggested predefined settings

or:

"lame.exe --longhelp"

or "lame.exe -?" for a complete options list

 

Encode your audio using the above method. I suggest around 160kb/s VBR.

 

 

 

 

Decoding

x264

Can't play back the movie? Give these suggestions to people that have Downloaded your movie.

 

1. Try using the VideoLan Client for playback of your files. It has built in x264 support, so installing the ffdshow playback filter, is not required. I don't have ffdshow installed, only VLC, Quicktime and Real Alternatives (which link into Media Player Classic), and Roxio's DVD player. I just use BSplayer cause I like the interface better.

 

2. Check your CPU stats, if it's below 2GHz you may not be able to play the movie

properly. Turn off other programs running on your computer.

 

3. Install latest version of ffdshow then play the file with Media Player Classic.

(if it fails, you need to reboot your computer, then run the install again)

 

Note: ffdshow has been known to cause a few problems.

1. While installing ffdshow make sure you check decoding of x264, and un-check everything else, especially decoding of Xvid (Xvid handles itself fine.) Also un-check post processing in the install, if checked. Also for audio decoding, un-check all boxes.

 

2. Install the MatroskaSplitter (make sure to check support for avi and mp4)

 

If you still cant play back the movie, you will need to watch a different version. This is where the Xvid encode comes in.

 

Xvid

 

Ship the Xvid codec with your movie and Media Player Classic. Both probably not needed at this point in time but can't hurt to include them.

 

 

 

 

Alternative CodecsAlternative Codecs

None of that worked for you? Try:

Divx 6 http://labs.divx.com/Codec

WM9 http://www.microsoft.com/windows/windowsmedia/9series/encoder/default.aspx

 

 

 

 

File Download Links

http://www.x264.nl

Encoders

VirtualDubMod - [does almost everything]

http://sourceforge.net/project/showfiles.php?group_id=65889&release_id=201544

 

Multifrontend - [Audio encoder GUI]

http://members.home.nl/w.speek/multi.htm

 

FAAC - [Free Advanced Audio Codec encoder]

http://corecodec.org/frs/download.php/413/bse_FAAC.zip

 

LAME [mp3 encoder latest stable]

http://sourceforge.net/project/showfiles.php?group_id=290 

 

AviSynth. - [This is the frame server, it sends the video into MeGUI for encoding ...and so much more]

http://www.avisynth.org/

 

 

MP4box GUI

YAMB - [used for joining the compressed video and audio] http://forum.doom9.org/showthread.php?s=&threadid=93927&perpage=20&pagenumber=1

 

Playback Filter

ffdshow – [Up to date decoder that supports many formats]

http://www.aziendeassociate.it/cd.asp?dir=/ffdshow 

 

Haali Splitter - [separates audio and video for decoding.]

http://haali.cs.msu.ru/mkv/

 

Players

VLC – [built in decoding features and multi-platform support]

http://www.videolan.org/

Codec

Huffyuv - [skip the install of all the other codecs if you don't know what your doing, I only suggest this codec pak, and only install the codecs you need. More codecs on a system the more conflict you can have]

http://prdownloads.sourceforge.net/gordianknot/Gordian.Knot.Codec.Pack.1.9.Setup.exe?download 

 

Glossary

 

Container(s) – [Eg. Avi, divx, mp4, mp3, mpeg, acc, m4a, 264, and many, many, others.] The container holds your audio, video and any other files such as subtitles, etc. Its the file extension at the end of your files, and allows your movie to contain certain features. One feature avi lacks, is holding VBR encoded audio files. Container format also differ in overhead, in that mp4 ends up taking up less space then a similarly encoded avi, the amount being insignificant compared to the features mp4 has over avi though.

 

VBR - [ Variable bit rate; versus CBR(constant bit rate) and average bit rate encoding. ]

VBR is recommend for a overall higher quality encode. Video is almost always VBR, unless its a streaming source. Audio was CBR now VBR is gaining is use. VBR uses bits more efficiently, in that it uses bits where it is needed (decided by the encoder). A VBR file is slightly larger in file size but of higher quality (when encoding MP3 and AAC at least).

Encoding types, Passes - [Single, Multi, Constant]

When you run and encode, you set the number of passes, for example single pass just encodes the video once and does all estimations and everything as it goes through the file. You can target bitrate or filesize. Now for a multi pass encode its a bit different. The first pass is always used just to scan the file, looking for motion, color and scene changes. This prepares for the 2nd encode by figured out where to place bits and how to reach a certain filesize more accuratly. The 2nd pass then does the encode just like a SIngle pass would, but now has better information so the encode almost always comes out better with an multi pass. More then 2 passes, you will see very little improvment with a 3rd pass often an unnoticable.

Constant quality - used for streaming mostly, the encode is a constant bitrate, usually low quality, but very high quality encodes can be created also(lossless encoding), but VBR is always recommended for video.

 

Change log

v1.5 - 1/10/05

new x264 SMP code and MeGUI build updates

rewrote for clarity and organization

 

v1.4

xvid 1.1 (woo!)

 

v1.3 - 12/15/2005

pub'd

added details on steps

glossary

 

v1.2

Xvid added

 

v1.1 - 11/21/2005

profiles

GUIs

links

 

v1.0

original

 

 

 

Credits

Typed up by fei
Credits go to countless people that have helped me over the years few that stick out in my mind:

 

-Xvid

JRB

Sean

Max

many people on doom9 forums

 

-x264

many people on doom9 forums

reflex

tox|k

 


Comment (0)
Last Updated ( Monday, 23 July 2007 )