| 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. |
| | 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. |
| | 81 | === Additional Information === |
| | 82 | |
| | 83 | ABR (Average Bit Rate). Like |
| | 84 | {{{ |
| | 85 | ffmpeg -i input -vcodec libx264 -b 1000k ... |
| | 86 | }}} |
| | 87 | |
| | 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. |
| | 89 | |
| | 90 | You can "fake" a Constant Bit Rate setting by tuning the parameters of the ABR, like |
| | 91 | {{{ |
| | 92 | ffmpeg -i myfile.avi -vcodec libx264 -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v |
| | 93 | }}} |
| | 94 | |
| | 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. |
| | 96 | |
| | 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). |
| | 98 | |
| | 99 | You can also "fake" a maximum bit rate by specifying both crf *and* maxrate settings, like |
| | 100 | {{{ |
| | 101 | ffmpeg -i input -vcodec libx264 -crf 20 -maxrate 400k -bufsize 1835k |
| | 102 | }}} |
| | 103 | |
| | 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. |
| | 105 | |
| | 106 | ---- |
| | 107 | |