Changes between Version 12 and Version 13 of Encode/H.264


Ignore:
Timestamp:
Aug 14, 2012, 8:31:04 PM (6 years ago)
Author:
rogerdpack
Comment:

tweak some crf verbiage, CBR et al headers

Legend:

Unmodified
Added
Removed
Modified
  • Encode/H.264

    v12 v13  
    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 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. 
     5There are two ratecontrol modes that are usually suggested for general use: [#crf Constant Rate Factor (CRF)] or ABR with [#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. 
    66 
    77If you need help compiling and installing libx264 see one of our [wiki:CompilationGuide FFmpeg and x264 compiling guides]. 
    88 
    99== Constant Rate Factor (CRF) ==#crf 
    10 This 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. 
     10This method allows you to choose a certain output quality for the whole file when output file size is of less importance. This provides maximum compression effectiveness with a single pass and each frame gets the bitrate it needs to keep the requested quality level. The downsides is that you can't tell it to get a specific filesize or not go over a specific size or bitrate. 
    1111 
    1212=== 1. Choose a CRF value === 
     
    2020You can also choose a tune and/or profile. 
    2121 
    22 === 3. Continue encoding === 
     22=== 3. Use your settings === 
    2323Use 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. 
    2424 
     
    7979---- 
    8080 
    81 === Additional Information === 
     81== Additional Information == 
    8282 
    83 ABR (Average Bit Rate).  Like 
     83 
     84=== ABR (Average Bit Rate) === 
     85 
    8486{{{ 
    8587ffmpeg -i input -vcodec libx264 -b 1000k ... 
    8688}}} 
    8789 
    88 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. 
     90This is the default, and provides something of a "running average" target, with the end goal that the final file match this number "overall on average" (so basically, if it gets a lot of black frames, which cost very little, it will encode them with less than the requested bitrate, but then 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 swings. 
    8991 
    90 You can "fake" a Constant Bit Rate setting by tuning the parameters of the ABR, like 
     92=== CBR (Constant Bit Rate) === 
     93 
     94There is no native CBR mode, but you can "simulate" a constant bit rate setting by tuning the parameters of ABR, like 
    9195{{{ 
    92 ffmpeg -i myfile.avi -vcodec libx264 -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v 
     96ffmpeg -i input -vcodec libx264 -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v 
    9397}}} 
    9498 
    95 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. 
     99in this example, bufsize is the "rate control buffer" so it will enforce your requested "average" (4000k in this case) across each 1835k worth of video.  So basically it is assumed that the receiver/end player will buffer that much data so it's ok to fluctuate within that quantity. 
    96100 
    97 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). 
     101Of 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, up to the crf level). 
    98102 
    99 You can also "fake" a maximum bit rate by specifying both crf *and* maxrate settings, like 
     103=== CRF with maximum bit rate === 
     104 
     105You can also also use a crf with a maximum bit rate by specifying both crf *and* maxrate settings, like 
    100106{{{ 
    101107ffmpeg -i input -vcodec libx264 -crf 20 -maxrate 400k -bufsize 1835k 
    102108}}} 
    103109 
    104 This will effectively "target" crf 20, but if the output exceeds 400k, it will degrade to something less than crf 20 in that case. 
     110This will effectively "target" crf 20, but if the output exceeds 400kb/s, it will degrade to something less than crf 20 in that case. 
    105111 
    106112---- 
     
    115121== FAQ == 
    116122=== Will two-pass provide a better quality than CRF? === 
    117 [http://doom10.org/index.php?PHPSESSID=okj08qe73ictdtv532augv8nu7&topic=267.msg2071#msg2071 No]. 
     123[http://doom10.org/index.php?PHPSESSID=okj08qe73ictdtv532augv8nu7&topic=267.msg2071#msg2071 No], though it does allow you to target a file size accurately. 
    118124 
    119125=== Why is `placebo` a waste of time? ===