Changes between Version 14 and Version 15 of Encode/VP9


Ignore:
Timestamp:
Jan 27, 2019, 8:35:40 PM (6 months ago)
Author:
veikk0
Comment:

Mention 2-pass CRF mode, mention the benefits of 2-pass in libvpx, add info about row-mt switch.

Legend:

Unmodified
Added
Removed
Modified
  • Encode/VP9

    v14 v15  
    1414* 2-pass average bitrate
    1515* Constant quality
     16* 2-pass constant quality
    1617* Constant bitrate
    1718
     
    3233=== Two-Pass ===#twopass
    3334
    34 In order to create more efficient encodes when a particular target bitrate should be reached, you should choose two-pass encoding. For two-pass, you need to run `ffmpeg` twice, with almost the same settings, except for:
     35Two-pass is the recommended encoding method for libvpx-vp9 as some quality-enhancing encoder features are only available in 2-pass mode.
     36
     37There are two different 2-pass encoding methods available in libvpx-vp9: a conventional mode for targeting an average bitrate, and a two-pass constant quality mode that uses the more contemporary CRF-style approach for the final pass to achieve a certain perceptual quality level while still gaining the aforementioned compression benefits by also doing a first pass.
     38
     39For two-pass, you need to run `ffmpeg` twice, with almost the same settings, except for:
    3540
    3641* In pass 1 and 2, use the `-pass 1` and `-pass 2` options, respectively.
     
    3944* In pass 1, you can leave audio out by specifying `-an`.
    4045
     46For two-pass targeting an average bitrate, the target bitrate is specified with the `-b:v` switch:
     47
    4148{{{
    4249ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -pass 1 -an -f webm /dev/null && \
    4350ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -pass 2 -c:a libopus output.webm
     51}}}
     52
     53Constant quality 2-pass is invoked by setting `-b:v` to zero and specifiying a quality level using the `-crf` switch:
     54
     55{{{
     56ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f webm /dev/null && \
     57ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -c:a libopus output.webm
    4458}}}
    4559
     
    4963}}}
    5064
    51 For two-pass encoding, you can choose a higher encoding speed for the first pass (e.g., 4), and a lower one for the second pass (e.g. 1). This will speed up the entire process (for more info, scroll down to the [#speed section about controlling speed]:
    52 
    53 {{{
    54 ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -pass 1 -speed 4 -c:a libopus -f webm /dev/null && \
    55 ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -pass 2 -speed 1 -c:a libopus output.webm
    56 }}}
     65For libvpx-vp9, the traditional wisdom of speeding up the first pass by using a faster encoding speed setting does not apply; `-speed` values from 0 to 4 result in the same speed for the first pass and yield the exact same results in the final encode, whereas any speed setting above 4 results in the first pass utilising only a single core, slowing things down significantly. Therefore the `-speed` switch can be entirely omitted from the first pass, since the default value of 1 will result in fast speed.
    5766
    5867If you want to constrain the bitrate, for example when streaming your video, use the options given in the [#constrainedq Constrained Quality] section.
     
    6069=== Constant Quality ===#constantq
    6170
    62 In addition to the "default" VBR mode, there's a constant quality (CQ) mode (like CRF in the x264 encoder) that will ensure that every frame gets the number of bits it deserves to achieve a certain (perceptual) quality level, rather than forcing the stream to have an average bit rate. This results in better overall quality. If you do not care about the file size, this should be your method of choice.
     71In addition to the "default" two-pass modes, there's a constant quality (CQ) mode (similar to CRF in the x264 encoder) that targets a certain perceptual quality level while only using a single pass. While using this single-pass mode will result in less efficient compression due to libvpx's preference for 2-pass encoding, this mode may still be useful if the extra time required for the first pass and the additional CPU cycles used for better compression in 2-pass mode aren't worth it for your use case.
    6372
    64 To trigger this mode, you must use a combination of `-crf` and `-b:v` 0. `-b:v` '''MUST''' be 0.
     73To trigger this mode, you must use a combination of `-crf` and `-b:v` 0. Note that `-b:v` '''MUST''' be 0. Setting it to anything higher or omitting it entirely will instead invoke the [#constrainedq Constrained Quality mode].
    6574
    6675{{{
     
    7281=== Constrained Quality ===#constrainedq
    7382
    74 libvpx-vp9 also has a constrained quality (CQ) mode that will ensure that a constant (perceptual) quality is reached while keeping the bitrate below a specified upper bound or within a certain bound. This method is useful for bulk encoding videos in a generally consistent fashion.
     83libvpx-vp9 also has a constrained quality (CQ) mode that will ensure that a constant (perceptual) quality is reached while keeping the bitrate below a specified upper bound or within a certain bound. While the caveats of single-pass encoding mentioned above stil apply, this method can still be useful for bulk encoding videos in a generally consistent fashion.
    7584
    7685{{{
     
    124133When the deadline/quality parameter is `good` or `best`, values for `-cpu-used` can be set between 0 and 5. The default is 0. Using 1 or 2 will increase encoding speed at the expense of having some impact on quality and rate control accuracy. 4 or 5 will turn off rate distortion optimization, having even more of an impact on quality.
    125134
    126 When the deadline/quality is set to `realtime`, the encoder will try to hit a particular CPU utilization target, and encoding quality will depend on CPU speed and the complexity of the clip that you are encoding. See [https://www.webmproject.org/docs/encoder-parameters/ the vpx documentation] for more info. In this case, the valid values for `-cpu-used` are between 0 and 15, where the CPU utilization target (in per cent) is calculated as `(100*(16-cpu-used)/16)%`.
     135When the deadline/quality is set to `realtime`, the encoder will try to hit a particular CPU utilization target, and encoding quality will depend on CPU speed and the complexity of the clip that you are encoding. See [https://www.webmproject.org/docs/encoder-parameters/ the vpx documentation] for more info. In this case, the valid values for `-cpu-used` are between 0 and 15, where the CPU utilization target (in per cent) is calculated as `(100*(16-cpu-used)/16)%`.
     136
     137=== Row based multithreading ===#rowmt
     138
     139With version 1.7.0, libvpx added support for row based multithreading which greatly enhances the number of threads the encoder can utilise. This improves encoding speed significantly on systems that are otherwise underutilised when encoding VP9. Since the amount of additional threads depends on the number of tiles, which itself depends on the video resolution, encoding higher resolution videos will see a larger performance improvement.
     140
     141FFmpeg added support for row based multithreading in version 3.4, released on January 25th, 2018. As of libvpx version 1.7.0 this multithreading enhancement is not enabled by default and needs be manually activated with the `-row-mt 1` switch.
    127142
    128143== Compatibility ==#compatibility