Changes between Version 10 and Version 11 of Encode/H.264


Ignore:
Timestamp:
Aug 14, 2012, 4:18:18 AM (6 years ago)
Author:
llogan
Comment:

ABR is not default; move rogers random stuff to additional information section

Legend:

Unmodified
Added
Removed
Modified
  • Encode/H.264

    v10 v11  
    33x264 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. 
    44 
    5 There are two most popular methods that are useful for general use: Constant Rate Factor (CRF) rate control and Two-Pass Encoding.  Explained below. 
    6  
    7 First 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 also how quality is distributed.  
    8  
    9 CRF is basically a "keep this same constant quality always" setting.  0 is considered lossless, 51 is worst quality.  You can either set this value, or set a bit rate with one of the other methods, not both.  This is easy to use for beginners--just figure out how much quality you want, then record using this setting.  It has good results even with just 1 pass. 
    10  
    11 The default is ABR (Average Bit Rate).  Like 
    12 {{{ 
    13 ffmpeg -i input -vcodec libx264 -b 1000k ... 
    14 }}} 
    15  
    16 This is something of a "running average" that allows for swings above and below this number, with the end goal that the final file will match this number "on average" (so basically, if it gets a lot of black frames, which cost very little, the next few seconds of non-black frames it will encode at very high quality, to bring the average back in line).  Using 2-pass can help this method to be more effective.  You can also use this in combination with a "max bit rate" setting in order to prevent some of the swing. 
    17  
    18 You can "fake" a Constant Bit Rate setting by tuning the parameters of the ABR, like 
    19 {{{ 
    20 ffmpeg -i myfile.avi -vcodec libx264 -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v 
    21 }}} 
    22  
    23 bufsize is the "rate control buffer" so it will keep that "average" (4000k in this case) across every block of 1835k.  So basically it is assumed that the receiver/end player will buffer that much data so it's ok to fluctuate within that time span. 
    24  
    25 Of course, if it's all just empty/black frames then it will still serve less than that many bits/s (but it will raise the quality level as much as it can to try to satisfy the requested parameters). 
    26  
    27 You can also "fake" a maximum bit rate by specifying both crf *and* maxrate settings, like 
    28 {{{ 
    29 ffmpeg -i input -vcodec libx264 -crf 20 -maxrate 400k -bufsize 1835k 
    30 }}} 
    31  
    32 This will effectively "target" crf 20, but if the output exceeds 400k, it will degrade to something less than crf 20 in that case. 
     5There are two ratecontrol modes that are usually suggested for general use: [#crf Constant Rate Factor (CRF)] and [#twopass Two-Pass encoding]. 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. 
    336 
    347If you need help compiling and installing libx264 see one of our [wiki:CompilationGuide FFmpeg and x264 compiling guides]. 
    358 
    36 == Constant Rate Factor (CRF) == 
     9== Constant Rate Factor (CRF) ==#crf 
    3710This 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. 
    3811 
     
    5831---- 
    5932 
    60 == Two-Pass == 
     33== Two-Pass ==#twopass 
    6134This 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 `bitrate = file size / duration`: 
    6235 
     
    10679---- 
    10780 
     81=== Additional Information === 
     82 
     83ABR (Average Bit Rate).  Like 
     84{{{ 
     85ffmpeg -i input -vcodec libx264 -b 1000k ... 
     86}}} 
     87 
     88This is something of a "running average" that allows for swings above and below this number, with the end goal that the final file will match this number "on average" (so basically, if it gets a lot of black frames, which cost very little, the next few seconds of non-black frames it will encode at very high quality, to bring the average back in line).  Using 2-pass can help this method to be more effective.  You can also use this in combination with a "max bit rate" setting in order to prevent some of the swing. 
     89 
     90You can "fake" a Constant Bit Rate setting by tuning the parameters of the ABR, like 
     91{{{ 
     92ffmpeg -i myfile.avi -vcodec libx264 -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v 
     93}}} 
     94 
     95bufsize is the "rate control buffer" so it will keep that "average" (4000k in this case) across every block of 1835k.  So basically it is assumed that the receiver/end player will buffer that much data so it's ok to fluctuate within that time span. 
     96 
     97Of course, if it's all just empty/black frames then it will still serve less than that many bits/s (but it will raise the quality level as much as it can to try to satisfy the requested parameters). 
     98 
     99You can also "fake" a maximum bit rate by specifying both crf *and* maxrate settings, like 
     100{{{ 
     101ffmpeg -i input -vcodec libx264 -crf 20 -maxrate 400k -bufsize 1835k 
     102}}} 
     103 
     104This will effectively "target" crf 20, but if the output exceeds 400k, it will degrade to something less than crf 20 in that case. 
     105 
     106---- 
     107 
    108108== Tips == 
    109109Encode 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.