Changes between Version 40 and Version 41 of x264EncodingGuide
- Timestamp:
- 02/23/2013 04:17:01 PM (3 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
x264EncodingGuide
v40 v41 5 5 x264 is a H.264/MPEG-4 AVC encoder. The goal of this guide is to inform new users how to create a high-quality H.264 video. 6 6 7 There are two rate control modes that are usually suggested for general use: [#crf Constant Rate Factor (CRF)] or [#twopass Two-Pass ABR]. The ratecontrol is a method that will decide how many bits will be used for each frame. This will determine the file size and also how quality is distributed.7 There are two rate control modes that are usually suggested for general use: [#crf Constant Rate Factor (CRF)] or [#twopass Two-Pass ABR]. The rate control is a method that will decide how many bits will be used for each frame. This will determine the file size and also how quality is distributed. 8 8 9 9 If you need help compiling and installing libx264 see one of our [wiki:CompilationGuide FFmpeg and x264 compiling guides]. 10 10 11 11 == Constant Rate Factor (CRF) ==#crf 12 This method allows the encoder to attempt to achieve a certain output quality for the whole file when output file size is of less importance. This provides maximum compression eff ectiveness with a single pass and each frame gets the bitrate it needs to keep the requested quality level. The downsidesis that you can't tell it to get a specific filesize or not go over a specific size or bitrate.12 This method allows the encoder to attempt to achieve a certain output quality for the whole file when output file size is of less importance. This provides maximum compression efficiency with a single pass. Each frame gets the bitrate it needs to keep the requested quality level. The downside is that you can't tell it to get a specific filesize or not go over a specific size or bitrate. 13 13 14 14 === 1. Choose a CRF value === 15 The range of the quantizer scale is 0-51; where 0 is lossless, 23 is default, and 51 is worst possible. A lower value is a higher quality and a subjectively sane range is 18-28. Consider 18 to be visually lossless: it should look the same or nearly the same as the input but it isn't technically lossless. Increasing the CRF value +6 is roughly half the bitrate while -6 is roughly twice the bitrate. General usage is to choose the highest quality that still provides an acceptable quality. If the output looks good then try a higher value and if it looks bad then choose a lower value. 15 The range of the quantizer scale is 0-51; where 0 is lossless, 23 is default, and 51 is worst possible. A lower value is a higher quality and a subjectively sane range is 18-28. Consider 18 to be visually lossless: it should look the same or nearly the same as the input but it isn't technically lossless. 16 17 Increasing the CRF value +6 is roughly half the bitrate while -6 is roughly twice the bitrate. General usage is to choose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value and if it looks bad then choose a lower value. 16 18 17 19 '''Note:''' The CRF quantizer scale mentioned on this page only applies to 8-bit x264 (10-bit x264 quantizer scale is 0-63). You can see what you are using with `x264 --help` listed under `Output bit depth`. 8-bit is more common amongst distributors. 18 20 19 21 === 2. Choose a preset === 20 A preset is a collection of options that will provide a certain encoding speed to compression ratio. A slower preset will provide better compression (compression is quality per filesize). General usage is to use the slowest preset that you have patience for. Current presets in descending order of speed are: `ultrafast`, `superfast`, `veryfast`, `faster`, `fast`, `medium`, `slow`, `slower`, `veryslow`, `placebo`. Ignore `placebo` as it is a joke and a waste of time (see [#faq FAQ]). You can see a list of current presets with `-preset help`, and what settings they apply with `x264 --fullhelp`. 22 A preset is a collection of options that will provide a certain encoding speed to compression ratio. A slower preset will provide better compression (compression is quality per filesize). This means that, for example, if you target a certain file size or constant bit rate, you will achieve better quality with a slower preset. Similarly, for constant quality encoding, you will simply save bitrate by choosing a slower preset. 23 24 The general guideline is to use the slowest preset that you have patience for. Current presets in descending order of speed are: `ultrafast`,`superfast`, `veryfast`, `faster`, `fast`, `medium`, `slow`, `slower`, `veryslow`, `placebo`. The default preset is `medium`. Ignore `placebo` as it is not useful (see [#faq FAQ]). You can see a list of current presets with `-preset help`, and what settings they apply with `x264 --fullhelp`. 21 25 22 26 You can optionally use `-tune` to change settings based upon the specifics of your input. Current tunings include: `film`, `animation`, `grain`, `stillimage`, `psnr`, `ssim`, `fastdecode`, `zerolatency`. For example, if your input is animation then use the `animation` tuning, or if you want to preserve grain then use the `grain` tuning. If you are unsure of what to use or your input does not match any of tunings then omit the `-tune` option. You can see a list of current tunings with `-tune help`, and what settings they apply with `x264 --fullhelp`. 23 27 24 Another optional setting is `-profile:v` which will limit the output to a specific H.264 profile. This can generally be omitted unless the target device only supports a certain profile . Current profiles include: `baseline`, `main`, `high`, `high10`, `high422`, `high444`. Note that usage of `-profile:v` is incompatible with lossless encoding.28 Another optional setting is `-profile:v` which will limit the output to a specific H.264 profile. This can generally be omitted unless the target device only supports a certain profile (see [#compatibility Compatibility]). Current profiles include: `baseline`, `main`, `high`, `high10`, `high422`, `high444`. Note that usage of `-profile:v` is incompatible with lossless encoding. 25 29 26 You can list all possible internal presets/tunes for your ffmpeg like 30 As a shortcut, you can also list all possible internal presets/tunes for FFmpeg by specifying no preset or tune option at all: 27 31 28 `$ ffmpeg -i some_file -vcodec libx264 -preset help -tune help dummy.avi` 32 {{{ 33 ffmpeg -i input -c:v libx264 -preset -tune dummy.mp4 34 }}} 29 35 30 36 === 3. Use your settings === 31 Use these same settingsfor the rest of your videos if you are encoding more. This will ensure that they will all have similar quality.37 Once you've chosen your settings, apply them for the rest of your videos if you are encoding more. This will ensure that they will all have similar quality. 32 38 33 39 === CRF Example === 40 41 The following example will encode a video with x264, using a slower than normal preset, with a slightly better quality than the default (23). 34 42 35 43 {{{ 36 44 ffmpeg -i input -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv 37 45 }}} 46 47 Note that in this example, the audio stream of the input file is simply copied over to the output and not re-encoded. 38 48 39 49 ---- … … 126 136 libx264 offers a `-tune zerolatency` option. See the [[StreamingGuide]]. 127 137 128 === Compatibility === 138 === Compatibility ===#compatibility 129 139 130 140 If you want your videos to have highest compatibility with target players (for instance, with older iOS versions or all Android devices) then you'll want to specify


