| | 7 | == Variable Bitrate == |
| | 8 | |
| | 9 | libvpx offers a variable bitrate mode by default. In this mode, it will simply try to reach the specified bit rate on average, e.g. 1 MBit/s. This is the "target bitrate". |
| | 10 | |
| | 11 | {{{ |
| | 12 | ffmpeg -i input.mp4 -c:v libvpx -b:v 1M -c:a libvorbis output.webm |
| | 13 | }}} |
| | 14 | |
| | 15 | Choose a higher bit rate if you want better quality. Note that you shouldn't leave out the {{{-b:v}}} option as the default settings will produce mediocre quality output. |
| | 16 | |
| | 17 | In addition to the "default" VBR mode, there's a constant quality mode (like in the x264 encoder) that will ensure that every frame gets the number of bits it deserves to achieve a certain quality level, rather than forcing the stream to have an average bit rate. This results in better overall quality and should be your method of choice when you encode video with libvpx. In this case, the target bitrate becomes the maximum allowed bitrate. You enable the constant quality mode with the CRF parameter: |
| | 18 | |
| | 19 | {{{ |
| | 20 | ffmpeg -i input.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output.webm |
| | 21 | }}} |
| | 22 | |
| | 23 | By default the CRF value can be from 4–63, and 10 is a good starting point. Lower values mean better quality. |
| | 24 | |
| | 25 | '''Important:''' If neither `-b:v` nor `-crf` are set, the encoder will use a low default bitrate and your result will probably look very bad. Always supply one of these options—ideally both. |
| | 26 | |
| | 27 | If you want to tweak the quality even further, you can set two more parameters: |
| | 28 | |
| | 29 | * `-qmin` – the minimum quantizer (default 4, range 0–63) |
| | 30 | * `-qmax` – the maximum quantizer (default 63, range `qmin`–63) |
| | 31 | |
| | 32 | These Q values are quantization parameters, and lower generally means "better quality". If you set the bounds from 0 to 63, this means the encoder has free choice of how to assign the quality. For a better overall quality, you can try to set `-qmin` to 0 and `-qmax` to 50 or lower. For example: |
| | 33 | |
| | 34 | {{{ |
| | 35 | ffmpeg -i input.mp4 -c:v libvpx -qmin 0 -qmax 50 -crf 5 -b:v 1M -c:a libvorbis output.webm |
| | 36 | }}} |
| | 37 | |
| | 38 | Needless to say that this requires a bit of tweaking. If in CRF mode you set the maximum bit rate too low, or the quality too high (i.e., low `qmin`, `qmax` or `crf`), libvpx will "saturate" the bitrate and you'll end up with constant bit rate encoding again, which is not ideal. To quote the [http://www.webmproject.org/docs/encoder-parameters/ VP8 reference]: "In practice this means that easy clips may undershoot the target maximum bitrate, because they are constrained by the CQ level, but harder clips will be bounded by the target maximum data rate and will increasingly revert to standard VBR behavior." |
| | 39 | |
| 18 | | |
| 19 | | == Variable Bitrate == |
| 20 | | |
| 21 | | libvpx offers two different variable bitrate modes, which are very similar. Like in the x264 encoder (for H.264 video), a constant quality mode will ensure that every frame gets the number of bits it deserves to achieve a certain quality level, rather than forcing the stream to have an average bit rate. This results in overall better quality and should be the default method of encoding video with libvpx. |
| 22 | | |
| 23 | | There are four important parameters for encoding VBR with libvpx, all of which are optional, but there are some caveats: |
| 24 | | |
| 25 | | * `-qmin` – the minimum quantizer (default 4) |
| 26 | | * `-qmax` – the maximum quantizer (default 63) |
| 27 | | * `-b:v` – the target bit rate setting. If not set, the encoder will choose ~1000 kBit/s as a default, but only when the `-crf` option is used. |
| 28 | | * `-crf` – the overall quality setting. If not set, the encoder will do "normal" VBR, trying to reach the target bitrate in within the `qmin`/`qmax` bounds. If set, the encoder will use CQ mode, and the target bitrate will become the maximum allowed bitrate. The CRF value is 10 by default. |
| 29 | | |
| 30 | | Important: If neither `-b:v` nor `-crf` are set, the encoder will use a default bitrate of 256 kBit/s and your result will probably look very bad. |
| 31 | | |
| 32 | | So, how do you set the quality? |
| 33 | | |
| 34 | | * `-qmin` should be set from 0–4, and `-qmax` from 50–63. These Q values are quantization parameters, and lower generally means "better quality". If you set the bounds from 0 to 63, this means the encoder has free choice of how to assign the quality. You can try to set `-qmax` to 50 to get an overall better quality. |
| 35 | | * `-crf` defaults to 10 and seems like a good choice. Lower values mean better quality, and the worst quality is achieved with `-crf 63`. |
| 36 | | * `-b:v` should be set to your target bitrate if you don't use `-crf`, or your maximum allowed bit rate if you use `-crf`. In the latter case, libvpx will try not to overshoot it. |
| 37 | | |
| 38 | | To summarize this, in one example with constant quality and an allowed maximum bit rate of 1 MBit/s: |
| 39 | | |
| 40 | | {{{ |
| 41 | | ffmpeg -i input.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output.webm |
| 42 | | }}} |
| 43 | | |
| 44 | | Or, if you want to have libvpx just target 2 MBit/s: |
| 45 | | |
| 46 | | {{{ |
| 47 | | ffmpeg -i input.mp4 -c:v libvpx -b:v 2M -c:a libvorbis output.webm |
| 48 | | }}} |
| 49 | | |
| 50 | | You can also artificially force libvpx to use a certain quality if you specify `-qmin` and `-qmax` without any bit rate or CRF value, but this is not an ideal solution. |