Changes between Version 5 and Version 6 of Encode/VP9


Ignore:
Timestamp:
Jul 3, 2017, 5:51:27 PM (5 months ago)
Author:
slhck
Comment:

improve article structure, add explanation on speed/quality

Legend:

Unmodified
Added
Removed
Modified
  • Encode/VP9

    v5 v6  
     1= FFmpeg and VP9 Encoding Guide = 
     2 
     3[[PageOutline(2, Contents)]] 
     4 
    15libvpx-vp9 is the VP9 video encoder for [http://www.webmproject.org/about/ WebM], an open, royalty-free media file format. This guide is an attempt to summarize the most important options for creating video with libvpx-vp9. 
    26 
     
    59Note that in the below examples, the libvorbis audio encoder is used. Make sure your FFmpeg version also includes libvorbis (check with {{{ffmpeg -codecs}}}), as the native Vorbis encoder from FFmpeg does not provide comparable quality. 
    610 
    7 == Variable Bitrate ==#variableb 
     11== Variable Bitrate (VBR) ==#variableb 
    812 
    9 libvpx-vp9 offers a variable bitrate (VBR) mode by default. In this mode, it will simply try to reach the specified bit rate on average, e.g. 2 MBit/s. This is the "target bitrate". 
     13=== Average Bitrate (ABR) ===#averageb 
     14 
     15libvpx-vp9 offers a simple variable bitrate (VBR) mode by default. This is also sometimes called "Average Bitrate" or "Target Bitrate". In this mode, it will simply try to reach the specified bit rate on average, e.g. 2 MBit/s. It is not usually recommended to use this mode, as the output may not be compression-efficient, or lead to quality variations. Instead, use [#twopass Two-Pass] or [#constantq Constant Quality] encoding. 
    1016 
    1117{{{ 
     
    1521Choose 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. 
    1622 
     23=== Two-Pass ===#twopass 
     24 
     25In order to create more efficient encodes when a particular target bitrate should be reached, you should choose two-pass encoding. For this, you need to run the encoding step twice: 
     26 
     27{{{ 
     28ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -c:a libvorbis -pass 1 -f webm /dev/null && \ 
     29ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -c:a libvorbis -pass 2 output.webm 
     30}}} 
     31 
     32{{{ 
     33#!div style="border: 1pt dotted; margin: 1em; background-color: #fffff9;" 
     34'''Note:''' Windows users should use `NUL` instead of `/dev/null`. 
     35}}} 
     36 
     37If you want to constrain the bitrate, for example when streaming your video, use the options given in the [#constrainedq Constrained Quality] section. 
     38 
    1739=== Constant Quality ===#constantq 
    1840 
    19 In addition to the "default" VBR mode, there's a constant quality (CQ) mode (like 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 and should be your method of choice when you encode video with libvpx-vp9. 
     41In 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. 
    2042 
    2143To trigger this mode, you must use a combination of `-crf` and `-b:v` 0. `-b:v` '''MUST''' be 0.  
     
    4567== Constant Bitrate == 
    4668 
    47 Like most other encoders, libvpx offers a constant bitrate (CBR) encoding mode as well, which tries to encode the video in such a way that an average bitrate is reached. This doesn't mean that every frame is encoded with the same amount of bits (since it would harm quality), but the bitrate will be very constrained. You should use constant bitrate encoding if you need your video files to have a certain size, or if you're streaming the videos over a channel that only allows a certain bit rate. 
     69Like most other encoders, libvpx offers a constant bitrate (CBR) encoding mode as well, which tries to encode the video in such a way that an average bitrate is reached. This doesn't mean that every frame is encoded with the same amount of bits (since it would harm quality), but the bitrate will be very constrained. You should use constant bitrate encoding if you need your video files to have a certain size, or if you're streaming the videos over a channel that only allows a certain bit rate. Generally though, using constrained quality is the recommended option in this case. 
    4870 
    4971The syntax for setting a constant bit rate is: 
     
    5981libvpx-vp9 has a lossless encoding mode that can be activated using `-lossless 1`. 
    6082 
     83== Controlling Speed and Quality ==#speed 
     84 
     85libvpx-vp9 has two main control knobs for speed and quality: 
     86 
     87=== Deadline / Quality === 
     88 
     89`-deadline` can be set to `realtime`, `good`, or `best`. For legacy reasons, the option is also accessible with `-quality` in ffmpeg. 
     90 
     91- `good` is the default and recommended for most applications. 
     92- `best` is recommended if you have lots of time and want the best compression efficiency. 
     93- `realtime` is recommended for live / fast encoding. When using `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. 
     94 
     95=== CPU Utilization === 
     96 
     97`-cpu-used` sets how efficient the compression will be. For legacy reasons, the option is also accessible with `-speed` in ffmpeg.  
     98 
     99When the deadline/quality parameter is `good` or `best`, values for `-cpu-used` can be set between 0 and 5. The default is 0, but using 1 or 2 will reduce 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. For two-pass encoding, it is recommended to set a higher speed for the first pass (e.g., 4), and a lower one for the second pass (e.g. 1).  
     100 
     101When the deadline/quality is set to `realtime`, 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)%`. 
     102 
     103 
    61104== Also see == 
    62105 
     106* [https://www.webmproject.org/docs/encoder-parameters/ WebM project libvpx Encoder Parameter Guide] 
    63107* [https://developers.google.com/media/vp9/ Google VP9 Guide] 
    64108* [https://sites.google.com/a/webmproject.org/wiki/ffmpeg/vp9-encoding-guide VP9 Encoding Guide]