Changes between Initial Version and Version 1 of Encode/H.264

Aug 5, 2012, 11:51:33 PM (7 years ago)

make initial page


  • Encode/H.264

    v1 v1  
     1= FFmpeg and x264 Encoding Guide =
     3x264 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.
     5First you must choose your ratecontrol. A ratecontrol is a method that will decide how many bits will be used for each frame. This will determine the file size and how quality is distributed. There are two main methods that are useful for general users: Constant Rate Factor (CRF) and Two-Pass. Use CRF if you don't know what ratecontrol method to use.
     7If you need help compiling and installing see one of our [wiki:CompilationGuide FFmpeg and x264 compiling guides].
     9== Constant Rate Factor (CRF) ==
     10This method will allow you to choose a certain output quality for the whole file and output file size is of less importance. This provides maximum compression effectiveness with a single pass and each video gets the bitrate it needs. The downsides is that you can't tell it to get a specific filesize or not go over a specific size.
     12=== 1. Choose a CRF value ===
     13The range 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 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  '''Note:''' These CRF values apply to 8-bit x264.
     17=== 2. Choose a preset ===
     18A preset is a collection of options that will provide a certain encoding speed: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).
     20=== 3. Keep going ===
     21Use these same settings for the rest of your videos if you are encoding more. This will ensure that they will all have the same quality.
     23=== CRF Example ===
     26ffmpeg -i input -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv
     31== Two-Pass ==
     32This method is generally used if you are targeting a specific output file size and output quality is of less importance. This is best explained with an example. Your video is 10 minutes (600 seconds) long and an output of 50 MB is desired. Since duration / file size = bitrate:
     35(50 MB * 8192 [converts MB to kilobits]) / 600 seconds = ~683 kilobits/s total bitrate
     36683k - 128k (desired audio bitrate) = 555k video bitrate
     40=== Two-Pass Example ===
     43ffmpeg -i input -c:v libx264 -preset fast -b:v 555k -pass 1 -an -f mp4 - && \
     44ffmpeg -i input -c:v libx264 -preset fast -b:v 555k -pass 2 -c:a libfaac -b:a 128k output.mkv
     47As with CRF, choose the slowest preset you can tolerate.
     51== Lossless H.264 ==
     52You can use `-qp 0` or `-crf 0` to encode a lossless output. Only two of the presets are generally useful: `ultrafast` or `veryslow` since either a fast encoding speed or best compression are usually the most important factors.
     54=== Lossless Example (fast encodinng) ===
     57ffmpeg -i input -c:v libx264 -preset ultrafast -qp 0 output.mkv
     61=== Lossless Example (best compression) ===
     64ffmpeg -i input -c:v libx264 -preset verslow -qp 0 output.mkv
     69== Overwriting default preset settings ==
     70You can overwrite default preset settings with the x264opts option or by using the libx264 private options (see `libx264 AVOptions` in `ffmpeg -h`).  This is not recommended unless you know what you are doing. The presets were created by the x264 developers and tweaking values to get a better output is usually a waste of time.
     75ffmpeg -i input -c:v libx264 -preset slow -crf 22 -x264opts keyint=123:min-keyint=20 -c:a copy output.mkv
     80== Tips ==
     81Encode a random section instead of the whole video with the `-ss` and `-t` options to quickly get a general idea of what the output will look like.
     82* `-ss`: Offset time from beginning. Value can be in seconds or HH:MM:SS format.
     83* `-t`: Output duration. Value can be in seconds or HH:MM:SS format.
     87== FAQ ==
     88=== Will two-pass provide a better quality than CRF? ===
     89[ No].
     91=== Why is `placebo` a waste of time? ===
     92It helps at most ~1% compared to the `veryslow` preset at the cost of a much higher encoding time. It's diminishing returns: `veryslow` helps about 3% compared to the `slower` preset, `slower` helps about 5% compared to the `slow` preset, and `slow` helps about 5-10% compared to the `medium` preset.
     94=== Why doesn't my lossless output look lossless? ===
     95Blame the rgb->yuv conversion.