x264 Options Explained

This is a sticky topic.
  • Time
  • Show
Clear All
new posts

  • tvssarma
    That was really helpful and overwhelming for a newbie like me

    Leave a comment:

  • tarakstokes
    thanks so much.............

    Leave a comment:

  • cata12
    Streaming solutions

    @ coldfire82
    If you are looking to stream live shows online have a look at blinkotv or livestream but I would recommend first option because of the better video quality.

    Leave a comment:

  • coldfire82
    nice guide - no doubt, but i was looking for any option to enable/disable or choose any selected FMO type for encoding used for error resilience version if there is any, since we can use various fmo types within h.264 but no idea about in x264? also about options to play live stream - udp channel ?
    any hints would be helpful


    A good resource of H.264/MPEG4

    Leave a comment:

  • admin
    x264 Options: Input/Output

    <img src="http://www.digital-digest.com/images/articleimages/x264_options/x264_io.gif" alt="x264 Options: Input/Output" title="x264 Options: Input/Output" border="0">

    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Show progress indicator:</b></div>
    <b>Description:</b> This option when enabled shows you how many frames have been encoded and how many frames are left. Best to leave it <u>On</u> if you don't want to sit there guessing how much is still left to do.
    <b>Command Line:</b> --progress
    (enables progress indicator)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Disable PSNR computation:</b></div>
    <b>Description:</b> This option disables noise reduction calculations. It is recommended that you leave this option <u>On</u> (to diable PSNR).
    <b>Command Line:</b> --no-psnr
    (disables PSNR computation)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Threads:</b></div>
    <b>Description:</b> This sets the number of CPU threads to use in encoding. An Intel Pentium processor with HyperThreading counts as 2 threads. Dual Core processors are also 2 threads. Dual core processor with HyperThreading (eg. Intel Extreme Edition) will have 4 threads.
    <b>Command Line:</b> --threads n
    (where 'n' is the number of threads)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Output Type:</b></div>
    <b>Description:</b> Selectable within the x264 command line by the output filename. A file with extension .264 will equal the "RAW" setting.
    <b>Command Line:</b> --output x
    (where 'x' is the output filename with the extension being .264, .mp4 or .mkv to indicate output type)
    Last edited by admin; 13 Jun 2006, 10:35 PM.

    Leave a comment:

  • admin
    x264 Options: Partitions

    <img src="http://www.digital-digest.com/images/articleimages/x264_options/x264_partitions.gif" alt="x264 Options: Partitions" title="x264 Options: Partitions" border="0">

    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Partitions:</b></div>
    <b>Description:</b> These options determine the partition search types. Generally, you want to enable <u>all</u> of these options whenever possible, as they will improve encoding quality. The "P4x4" option requires the "P8x8" option.
    <b>Command Line:</b> --analyse x
    (where 'x' is 'p8x8', 'p4x4' {requires 'p8x8'}, 'b8x8', 'i8x8', 'i4x4' , 'none' or 'all')
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>8x8 DCT:</b></div>
    <b>Description:</b> This option has been separated from the above because it has a different command line flag. This option is required if you want to select the "I8x8" option above.
    <b>Command Line:</b> --8x8dct
    (enables 8x8 DCT)
    Last edited by admin; 13 Jun 2006, 10:18 PM.

    Leave a comment:

  • admin
    x264 Options: Analysis

    <img src="http://www.digital-digest.com/images/articleimages/x264_options/x264_analysis.gif" alt="x264 Options: Analysis" title="x264 Options: Analysis" border="0">

    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Mixed References:</b></div>
    <b>Description:</b> This option allows x264 to have greater control over "Reference Frames" (see "Common options" section). Especially needed if the "Reference Frames" is set to a high value.
    <b>Command Line:</b> --mixed-refs
    (enables mixed references)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>No Fast P Skip:</b></div>
    <b>Description:</b> Fast P Skip can improve encoding speed at the expense of a very slight quality drop. Leave this option set to <u>Off</u> (to allow for Fast P Skips) is recommended unless encoding for maximum quality with no regard to encoding time.
    <b>Command Line:</b> --no-fast-pskip
    (disables fast P skip)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Motion Estimation Method:</b></div>
    <b>Description:</b> This option select the way motion is detected by x264. Motion is what compression codecs are all about, tracking differences between scenes to allocate the various frame types and bitrates.
    <b>Available Options (listed from fastest to slowest, encoding speed wise):</b>
    Diamond: Only use when maximum encoding speed is required.
    Hexagon: A good option for when quality is not the most important factor, but still important.
    Multi Hex: Also known as "Uneven Multi-Hexagon". <u>This is the most common setting</u>, as it is a good trade off between speed and quality.
    Exhaustive: Slowest and totally unnecessary (it isn't estimation anymore, rather, it's Motion Calculation, pixel by pixel).
    <b>Command Line:</b> --me x
    (where 'x' is 'dia', 'hex', 'umh' or 'esa')
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Subpixel Motion Estimation:</b></div>
    <b>Description:</b> Also known as "Partition Decision". A very important option that determines how x264 makes decisions about motion estimation. The options are available from 1 to 7, with 1 being the fastest (lowest quality) and 7 being the slowest (best quality). A setting of <u>6</u> is the most common, with 1 or 7 being used in extreme cases (fastest encoding or best quality). A setting of 6 or 7 enables the B-frames RDO option (see "B-Frames options" section).
    <b>Command Line:</b> --subme n
    (where 'n' is the estimation value)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Trellis RD Quantization:</b></div>
    <b>Description:</b> This option when turned on is supposed to improve quality, but at a severe slow down of encoding. The quality improvements are also subjective. Leaving it <u>Off</u> is recommended unless you have a fast computer and using multi-pass encoding. Never turn it on in single pass quantizer mode, as it would lead to unexpected results.
    <b>Available Options:</b>
    Disabled: Use this for 1-pass encoding
    Final MB: Use this for typical 2-pass encoding
    Always: Use this for maximum quality (slowest speed)
    <b>Command Line:</b> --trellis n
    (where 'n' is 0 {disabled}, 1 {Final MB} or 2 {Always})
    Last edited by admin; 28 Jun 2006, 03:27 PM.

    Leave a comment:

  • admin
    x264 Options: Frame Options

    <img src="http://www.digital-digest.com/images/articleimages/x264_options/x264_frame.gif" alt="x264 Options: Frame Options" title="x264 Options: Frame Options" border="0">

    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Scene Cut:</b></div>
    <b>Description:</b> This option sets how x264 determines when a scene change has occurred and hence when a key frame is needed. A higher value will allow x264 to be more sensitive to scene changes. A video that has very few camera movements may require a higher scene cut value, for example. The default value of <u>40</u> should work well in most cases, plus or minus 5 for low/high action videos.
    <b>Command Line:</b> --scenecut n
    (where 'n' is the scene cut value)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>CABAC:</b></div>
    <b>Description:</b> Stands for Context Adaptive Binary Arithmetic Coding. Improves encoding efficiency at the expense of playback/decoding efficiency. The default option of leaving this setting <u>On</u> is recommended, unless the encoded video is to be played back on devices with limited decoding power (eg. portable devices such as the iPod or high resolution clip playback on the Xbox).
    <b>Command Line:</b> --no-cabac
    (disables CABAC)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>GOP Size (Min/Max):</b></div>
    <b>Description:</b> This option sets the minimum and maximum number of frames before a key frame has to be inserted by x264. For example, a minimum setting that is the <u>same as the framerate</u> of the video (eg. 24/25/30) will prevent the encoded video from having two subsequent key frames within a second of each other, which only aims to increase file size without any noticeable quality improvements.

    Similarly, a maximum setting ensures that a key frame is inserted at least every X number of frames. A video without key frames will have lower quality and there will be problem with seeking (if you try to skip to a part of the video without a key frame, there won't be any video until the next key frame is reached, also known as "seeking lag"). A recommend setting, as with DivX/XviD encoding, is to set this as <u>10 times the framerate</u>, which equates to 10 seconds of video between key frames (ensures "seeking lag" is at most 10 seconds).
    <b>Command Line:</b> --keyint m --min-keyint n
    (where 'm' and 'n' are the max and min GOP size values)
    Last edited by admin; 14 Jun 2006, 01:17 AM.

    Leave a comment:

  • admin
    x264 Options: B-Frames

    <img src="http://www.digital-digest.com/images/articleimages/x264_options/x264_b-frames.gif" alt="x264 Options: B-Frames" title="x264 Options: B-Frames" border="0">

    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Direct Mode:</b></div>
    <b>Description:</b> This option when selected can improve compression efficiency. Disabled by default, <u>Auto</u> seems to be the most common value, with <u>Spatial</u> being used occasionally.
    <b>Available Options:</b>
    Temporal: least used (at least in Sharktooth's profiles)
    Auto: most common
    <b>Command Line:</b> --direct x
    (where 'x' is 'none', 'spatial', 'temporal' or 'auto')
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Bias:</b></div>
    <b>Description:</b> Sets how much bias x264 should give the usage of B-frames (higher means more use of B-frames). Setting this to 100 is the equivalent of not selecting the "Adaptive" option (see below). A default value of <u>0</u> works well. Option only available when at least 1 B-frame has been set.
    <b>Command Line:</b> --b-bias n
    (where 'n' is the bias value)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Adaptive:</b></div>
    <b>Description:</b> Turns on adaptive B-frames, which allows x264 to determine the number of B-frames to use (within the set B-frames limit in the previous section). A default value of <u>On</u> works well. Option only available when at least 1 B-frame has been set.
    <b>Command Line:</b> --no-b-adapt
    (disables adaptive B-frames)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Pyramid:</b></div>
    <b>Description:</b> Turns on B-frame Pyramid option, which allows B-frames to be used as references for other B-frames in prediction. A default value of <u>On</u> (when available) works well. Option only available when at least 2 B-frame has been set.
    <b>Command Line:</b> --b-pyramid
    (enables adaptive B-frames)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>RDO:</b></div>
    <b>Description:</b> Turns on/off RDO for B-Frames. Turning it <u>On</u> will improve quality at the expense of encoding speed, but it is almost always worth it. Must have at least 1 B-frame and must have a "Subpixel Motion Estimation" (see "Analysis options" section) of 6 or 7.
    <b>Command Line:</b> --b-rdo
    (enables RD based mode decision for B-frames)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Weighted Prediction:</b></div>
    <b>Description:</b> Turns on weighted prediction for B-frames, which results in improved accuracy and therefore a more efficient encoding. Set it to <u>On</u> in most cases. Option only available when at least 1 B-frame has been set.
    <b>Command Line:</b> --weightb
    (enables weighted prediction)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Bidirectional M.E.:</b></div>
    <b>Description:</b> Turns on bidirectional M.E, which allows predictions based on motion both before and after the B-frames. Set it to <u>On</u> in most cases.
    <b>Command Line:</b> --bime
    (enables bidirectional M.E.)
    Last edited by admin; 13 Jun 2006, 10:07 PM.

    Leave a comment:

  • admin
    x264 Options: Common

    <img src="http://www.digital-digest.com/images/articleimages/x264_options/x264_common.gif" alt="x264 Options: Common" title="x264 Options: Common" border="0">

    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Mode:</b></div>
    <b>Description:</b> Selects the encoding mode to be used by the encoder. Single pass encoding can give unexpected output file sizes (Quantizer and Quality modes) and/or poorer quality compared to multi pass encoding.
    <b>Available Options:</b>
    Single Pass - Bitrate: Encodes the video once (single pass) with a set constant bitrate for each frame
    Single Pass - Quantizer: Single pass encoding with a set quantizer (higher quantizer => lower quality) for each frame
    Single Pass - Quality: Single pass encoding with a set quality rating for each frame
    Two Pass: Encodes the video twice (once to determine it's properties, another to ensure the selected output file size is reached with maximum efficiency). <u>This is the most common setting</u>.
    Three Pass: Same as Two Pass except for an extra encoding pass to ensure even better quality/accurate file size
    <b>Command Line:</b> --bitrate, --qp, --crf, --pass 1/2/3
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Quantizer:</b></div>
    <b>Description:</b> Only available with "Single Pass - Quantizer" mode is selected. Set the quantizer value for the encoding. A high quantizer will equal a low quality (and smaller file size). A quantizer value between <u>20</u> (high quality) and <u>30</u> (low quality) should be used. Anime/cartoons or scenes with large patches of color or less details benefit from having a higher quantizer, typical movies require a lower quantizer.
    <b>Command Line:</b> --qp n
    (where 'n' is the quantizer value)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Quality:</b></div>
    <b>Description:</b> Only available with "Single Pass - Quality" mode is selected. Set the quality value for the encoding. A high quality value equals a higher quality encoding (and larger file size).
    <b>Command Line:</b> --crf n
    (where 'n' is the quality value)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>B-Frames:</b></div>
    <b>Description:</b> Selects the number of consecutive B-frames x264 should use. It is also the maximum number of consecutive B-frames x264 can use if the "Adaptive" B-frames option (see next section) is selected. B-frames are frames that are small in size, but when placed correctly, offer no loss of quality. This can help improve compression. With the "Adaptive" option on (x264 will decide how many B-frames to use), having a setting of <u>3</u> is recommended as this gives x264 enough room to work with.
    <b>Command Line:</b> --bframes n
    (where 'n' is the number of B-frames)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Reference Frames:</b></div>
    <b>Description:</b> Selects the maximum number of reference frames that can be used. Referenced frames are frames that refer to other frames (eg. if both frames are similar). Having a high referenced frame will improve quality but slow up encoding. For typical content, a reference frame of <u>3</u> to <u>5</u> is recommended. For content with a lot of repetition (eg. animation), a reference frame of <u>8</u> to <u>10</u> can be used. If a large number of reference frames is selected, then the "Mixed References" options should also be selected to allow x264 greater control (see "Analysis Options" section).
    <b>Command Line:</b> --ref n
    (where 'n' is the number of reference frames)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Loop Filter:</b></div>
    <b>Description:</b> Also known as "de-blocking" filter. Connected with the "Alpha" and "Beta" setting next to it. One of the fundamental differences between H.264 and previous codecs. Should always be enabled or excessive video artifacts may appear. Controversial because blocking (when the video looks like a series of different colored squares in low bitrate video) and artifacts are treated as details by the human visual system, and removing them makes people think details is lost, when it's actually the other way around (more "actual" details shown due to less artifacts). This is an interesting topic that is better discussed in <a href="http://gabe.5000megs.com/guide/DeathTheSheep_x264_VfW_guide.html" target="_blank">DeathTheSheep's x264 guide</a>.
    <b>Command Line:</b> --nf
    (disables loop filter)
    <hr size="1">

    <div style="font-size: 14px; text-decoration: underline"><b>Alpha/Beta:</b></div>
    <b>Description:</b> This controls the "Loop Filter" (see above). Also known as Strength (Alpha) and Threshold (Beta). Alpha determines the strength of the deblocking action. Beta determines when x264 decides something is a block and when something isn't - a high value means x264 sees more video as blocks than a lower value. For example, a too high Beta value and a too high Alpha means x264 will identify too many blocks (even when they aren't artifacts) and apply too much filtering to remove them, making the picture look "washed out" and lacking detail. Both values can be positive or negative. <u>0/0</u> (Alpha/Beta) is the default and recommended setting, unless you find the video quality unacceptable, then you should try combinations. Do not go under -2 or above 3. This is an interesting topic that is better discussed in <a href="http://gabe.5000megs.com/guide/DeathTheSheep_x264_VfW_guide.html" target="_blank">DeathTheSheep's x264 guide</a>.
    <b>Command Line:</b> --filter <alpha:beta>
    Last edited by admin; 14 Jun 2006, 01:16 AM.

    Leave a comment:

  • admin
    Frames Basics and x264 Profiles

    <b>Frames Basics:</b>

    Modern compressed video are made up of 3 different types of frames. Intra (I) frames (also known as key frames), Predictive (P) and Bidirectional (B) frames. Certain types of frames can be referenced, which means a frame sometimes only need to stores the difference between it-self and the referenced frame. The problem with referencing is that any error that occurs when frame Y references frame X will be carried over and propagated if frame Y is it-self referenced later on. This is why there are also frames which can't be referenced.

    The I frame stores the entire image and so are the least compressible. Video seeking (when you skip to a part of a video) requires I-frames, as otherwise a symptom called seeking lag will occur when the video is blank until the next I-frame is encountered.

    P-frames store the difference (called "referencing") between itself and an I-frame or other P-frames. This means P-frames can be referenced, so it needs to store enough information for this to happen, but not as much I-frames because of it's encoding technique (motion compensation).

    B frames also store the differences between itself and other frames as well (uses both previous and future frames for reference), but it can't be referenced ("B-frame pyramid" excepted), so they are the most compressible (holds least amount of information). 264 supports "B-frame pyramids", which allow B-frames to be referenced for other consecutive B-frames, but otherwise B-frames can't be referenced by any other frame, so less information is stored.

    So basically, a compressed video will be a combination of I, P and B frames, some referencing others. The successful combination of these frames and the referencing determines how well the video is compressed.

    <b>x264 Profiles:</b>

    Profiles are the easiest way to configure x264. Profiles are basically pre-configured x264 settings that have been saved and can be loaded time and time again to encode files. They save you time by not requiring you to re-set all the options whenever you use x264, and most importantly, they give new users a chance to experience x264 without understanding what the options are.

    <i>Sharktooth</i> from the Doom9 forums has produced several profiles for everyday usage, and has made it available for <a href="http://www.digital-digest.com/software/download.php?sid=774&ssid=0&did=3" target="_blank">download</a>. You should read the <a href="http://forum.doom9.org/showthread.php?t=101813" target="_blank">official forum thread</a> for details of what each profile is intended for, although the profiles "PD-PSP", "PD-Xbox_Hires", "PD-Xbox_LoRes" and "PD-iPod" should come in handy for encoding a PSP/Xbox/iPod compatible video. There are even profiles specifically designed for Anime/cartoons

    The other piece of good news is that software like MeGUI allow you to import profiles, and StaxRip has these profiles built into the software it self (and also allow you to edit and create your own profiles).

    But what if you are curious and you want to find out just what options are being selected in a profile? It's actually very easy to view profiles, because they are actually just XML files. Clicking on the XML file should open them in Internet Explorer, and you should see a screen similar to the one below:

    <img src="http://www.digital-digest.com/images/articleimages/x264_options/profile.gif" alt="Profiles" title="Profiles" border="0">

    What the above shows is that for this particular profile, NbBframes to 3, KeyframeInterval to 250, trellis to false and so on. On the x264 command line, the three options I've mentioned would translates to the following:

    <div style="background: #000000; color: #FFFFFF; width:300px">x264.exe --bframes 3 --keyint 250 --trellis 0</div>
    Last edited by admin; 14 Jun 2006, 01:27 AM.

    Leave a comment:

  • admin
    started a topic x264 Options Explained

    x264 Options Explained

    <b>What is this guide about?</b>

    This guide aims to explain, to people just starting out with H.264 encoding, what the various options in x264 mean and how they affect the encoded video. For each option, a description is provided, as well as a list of possible options (and their descriptions), the command line version of the option and the recommend setting is shown in <u>underline</u> whenever possible.

    If you are reading this guide, then it must mean that you already know all about H.264 and H.264 playback. If you don't, head on to our <a href="http://www.digital-digest.com/articles/mp4_h264_playback_page1.html" title="H.264 Playback Guide">H.264 Playback Guide</a> to get acquainted with this new video compression format.

    Future versions of this guide will feature more information regarding compatibility (eg. with QuickTime, iPod, PSP, Xbox).

    <b>What is x264?</b>

    <img src="http://www.digital-digest.com/images/articleimages/x264_options/x264.gif" alt="x264" title="x264" border="0">

    <a href="http://www.divx-digest.com/software/x264.html" title="x264">x264</a> is a free H.264 encoder. It is mainly aimed at intermediate users, so it has lots of options that will be confusing to the average user. If you don't know your trellis from your pyramid, then this guide will hopefully help you to understand things a bit better (or just enough so that you don't have to select options at random).

    The x264 options discussed in this article are ones that can be inputted using the command line version of the tool or through a Windows GUI software called <a href="http://www.digital-digest.com/software/staxrip.html" title="StaxRip">StaxRip</a>. A separate <a href="http://www.digital-digest.com/articles/staxrip_h264_page1.html">StaxRip H.264 Encoding Guide</a> is also available, so don't fret if you can't figure out how to use this software (or to even install it).

    <b>Why use StaxRip?</b>

    Or rather, why not use MeGUI? MeGUI is probably the best tool around with dealing with x264, but it can be daunting for new users because of the numerous options that are included. StaxRip is aimed more at beginners, and so has (as the author states) only the important x264 options available to configure. Plus, StaxRip assumes no knowledge of Avisynth scripting.

    You can also read our <a href="http://www.digital-digest.com/articles/MeGUI_H.264_Conversion_Guide_page1.html">MeGUI H.264 Conversion Guide</a>.

    <b>Software Requirements:</b><ul><li> <a href="http://www.divx-digest.com/software/x264.html" title="x264">x264</a>
    <li> <a href="http://www.digital-digest.com/software/staxrip.html" title="StaxRip">StaxRip</a>

    <b>Basic x264 usage:</b>

    At it's most basic, x264 is a command line tool, where you can specify the input, output and encoding options all through a glorious black-background/white-text command line interface.

    The command line syntax is as follows

    <div style="background: #000000; color: #FFFFFF; width:300px">x264.exe <i>options</i> --output output.*** inputfile.*** <i>widthxheight</i></div>

    A simple example of a x264 command line entry:

    <div style="background: #000000; color: #FFFFFF; width:300px">x264.exe --bitrate 1087 --output "test.mp4" "test.avi"</div>

    A more complicated example of a x264 command line entry:

    <div style="background: #000000; color: #FFFFFF; width:300px">x264.exe --pass 2 --bitrate 1087 --stats "test.stats" --ref 3 --bframes 3 --b-pyramid --weightb --b-rdo --bime --direct auto --filter -4:-3 --analyse all --8x8dct --subme 6 --me umh --trellis 1 --mixed-refs --progress --no-psnr --output "test.264" "test.avs"</div>

    There are many graphical user interfaces (GUIs) which allow you to set these options through a normal Windows program, and StaxRip is one of them.

    Throughout this guide, whenever an x264 option is explained, both the command line equivalent and the StaxRip/GUI version of the option will be shown.
    Last edited by admin; 24 Nov 2006, 10:53 PM.