VPX

From wiki.selur.net
Jump to navigation Jump to search

VPX stands for the two open, royalty-free video formats VP8 and VP9 of the WebM project. Hybrid encodes both with vpxenc, the command line encoder of the reference library libvpx. VP9 compresses clearly better than VP8 and also offers 10/12 bit, 4:2:2/4:4:4 and lossless coding; VP8 is the older format that is still needed for some players and WebRTC setups.

Base → Video: VPX, then the VPX tab

What it does

Both codecs predict each frame from already coded frames or from neighbouring blocks, transform the remainder and quantize it. The quantizer runs from 0 (best) to 63 (worst). Besides normal frames the encoder uses golden frames and alternate reference frames (alt-ref): frames that are coded in higher quality, kept as long-term references and, in the case of alt-ref frames, never shown themselves. Alt-ref frames are built from several future frames, which is why they need look-ahead (Max frames to lag) and work best in 2-pass.

The Codec control decides whether VP8 or VP9 is written; a number of controls only exist for one of the two and are locked for the other. The encoding modes:

  • specific filesize/bitrate (2-pass): a first pass collects statistics, the second distributes a given bit rate or file size. The separate 1st pass and 2nd pass entries run only that pass.
  • constrained quality (2-pass / 1-pass): aims at a quality level, but never spends more than a maximum bit rate.
  • average bitrate (1-pass): one pass towards a bit rate.
  • constant quantizer (1-pass): constant quality level, the size results from the content.
  • lossless (1-pass): VP9 only.

Requirements

vpxenc is part of Hybrid. VP8 is always 8-bit 4:2:0. VP9 with 4:2:2 or 4:4:4 needs the profile simple or full, VP9 with 10 or 12 bit the profile complex or full; many hardware decoders only handle 8-bit 4:2:0 (low). VP8 and VP9 are normally stored in WebM or Matroska.

Settings

The option column shows the vpxenc option a control ends up as. Controls that belong to the other codec or to another encoding mode are locked; the tables name the conditions and say where an option is VP8 only or VP9 only.

Base

VPX Base tab
VPX Base tab

General Settings

Control vpxenc option Range / values Hybrid default Meaning
Encoding mode --passes, --pass, --end-usage, --lossless specific filesize/bitrate (2-pass), 2pass - 1st pass, 2pass - 2nd pass, constrained quality (2-pass), average bitrate (1-pass), constant quantizer (1-pass), constrained quality (1-pass), lossless (1-pass) specific filesize/bitrate (2-pass) Rate control mode, see above. Constant quantizer is written as --end-usage=q, constrained quality as --end-usage=cq, lossless as --lossless=1. lossless is only offered for VP9. The rows below the mode change with it.
Target mode – custom, 1/4 CD … 1 BD 50 custom Common media sizes for the target size; custom allows a free size or bit rate. Only in the specific filesize/bitrate modes.
Target size (MiB) --target-bitrate 0.2 MiB and up, step 0.1 off, 700 Aim at a file size: Hybrid computes the video bit rate from the size, the length and the other streams. Only meaningful for 2-pass.
Bitrate (kbit/s) --target-bitrate 16 – 245760 on, 1500 Target bit rate of the bit rate based modes.
Bitrate mode --end-usage VBR, CBR VBR VBR lets the bit rate follow the content and is the choice for files. CBR keeps the rate constant for streaming over a link with fixed bandwidth. Bit rate modes only.
Quantizer level --cq-level 0 – 63 18 Quality level of the constant quantizer and constrained quality modes; lower is better and bigger. Shown instead of the bit rate rows in these modes.
Maximum rate --target-bitrate 16 – 245760 15000 Upper bit rate limit (kbit/s) of the constrained quality modes: the encoder keeps the quality level as long as it stays below this rate. Locked in constant quantizer mode.

Codec, Speed and Complexity

Control vpxenc option Range / values Hybrid default Meaning
Codec --codec VP8, VP9 VP9 Which of the two formats is written. Switching it locks and unlocks the codec specific controls and adjusts some ranges.
Profile --profile low (0), simple (1), complex (2), full (3) low Bitstream profile. VP9: 0 = 8-bit 4:2:0, 1 = 8-bit 4:2:2/4:4:4, 2 = 10/12-bit 4:2:0, 3 = 10/12-bit 4:2:2/4:4:4; the profile decides which entries In-Output bit-depth and Color sampling offer. VP8: the profile number trades decoding complexity against quality (simpler sub-pixel and loop filters for higher numbers).
Basic speed control --good, --best, --deadline good, best, manual good good is the normal quality mode, fine-tuned with the CPU utilization modifier. best is much slower for a small gain. manual writes Deadline per frame as --deadline.
CPU utilization modifier --cpu-used VP9: -9 – 9, VP8: -16 – 16 0 Speed step inside the speed mode: higher values encode faster and compress worse, 0 is the slowest and best. Changing the codec only narrows the range (a value outside is moved to the limit). Locked with best.
Deadline per frame (µs) --deadline 0 – 1000000 1000000 Time budget per frame, only with Basic speed control manual. 0 equals best, a value above the frame duration good, a smaller one the realtime mode; the 2-pass modes only tell 0 from above 0.
Token partitioning --token-parts 1 partition (SD), 2 partitions (SD), 4 partitions (HD), 8 partitions (HD) 2 partitions (SD) VP8 only (shown instead of the tile row). Splits the coefficient data into independent partitions so that a decoder can use several threads for it. More partitions for larger frames.
Tile (columns/rows) --tile-columns, --tile-rows 0 – 6 / 0 – 2 (log2) 2 / 1 VP9 only. Splits the frame into 2ⁿ tile columns and rows that can be encoded and decoded in parallel; more tiles cost a little compression. The rows box is locked and set to 0 while Threads is not 0.

Format

Control vpxenc option Range / values Hybrid default Meaning
In-Output bit-depth --input-bit-depth, --bit-depth 8-bit, or 10-bit and 12-bit 8-bit Bit depth of the video Hybrid feeds and the encoder writes. 10 and 12 bit: VP9 only, with the profile complex or full; otherwise the control is locked at 8-bit.
Color sampling --i420, --i422, --i444 i420, or i422 and i444 i420 Chroma format of the output. With the profiles low and complex it is fixed to i420; simple and full offer i422 and i444 (VP9 only, VP8 is always i420).
Color space --color-space unknown, bt601, bt709, smpte170, smpte240, bt2020, reserved, sRGB unknown VP9 only. Color space flagged in the VP9 stream. It only describes the video, nothing is converted.
Screen content mode (VP8) --screen-content-mode=1 off, on off VP8 only. Tunes the encoder for screen recordings, slides and similar content instead of camera material.
Max I-frame bitrate (%) --max-intra-rate 0 – 100 0 Limits the size of a key frame, as a percentage of the target bit rate per frame. 0 = no limit (not written). VP8 and VP9.
Max P-frame bitrate (%) --max-inter-rate 0 – 100 0 VP9 only. The same limit for inter frames. 0 = no limit (not written).

Advanced

VPX Advanced tab
VPX Advanced tab

Frame Settings

Control vpxenc option Range / values Hybrid default Meaning
GOP size min/max --kf-min-dist, --kf-max-dist 0 – 10000 each 0 / 250 Smallest and largest distance between key frames. A larger maximum saves bits, a smaller one makes seeking faster and limits the damage of transmission errors.
Max frames to lag --lag-in-frames 0 – 25 25 How many future frames the encoder may look at before it codes a frame. Needed for alt-ref frames; 0 switches the look-ahead off. Only in the 2-pass modes. Must be 0 or at least the maximum golden frame distance + 2; Hybrid raises it if necessary.
Frame drop (%) --drop-frame 0 – 99 0 Allows the encoder to drop frames when the client buffer falls below this fill level, to hold the bit rate. Causes stutter; 0 disables it.
Spatial resampling --resize-allowed on/off off Allows the encoder to code frames at a lower resolution when the bit rate gets tight; the decoder scales them back.
Parallel decoding --frame-parallel=1 on/off off VP9 only. Restricts the stream so that a decoder can decode several frames in parallel. Costs some compression.
Down-/Upscale threshold (buf %) --resize-down, --resize-up 0 – 100 each 100 / 100 Buffer fill levels at which the encoder switches to a lower resolution (below the first value) and back up (above the second). Only with Spatial resampling.
Alternate reference reduction frame decision --auto-alt-ref VP9: 0 – 6, VP8: 0 – 1 1 Lets the encoder insert alt-ref frames on its own; 0 = off. With VP9, values from 2 on enable multi-layer alt-ref frames. Only in the 2-pass modes; in the 1-pass modes it is set to 0 and locked.
Golden frame cbr boost --gf-cbr-boost 0 – 1000 0 VP9 only, and only written with Bitrate mode CBR: extra bits (in percent) for golden frames in CBR mode.
Golden frame dist (min/max) --min-gf-interval, --max-gf-interval 0 – 24 / 0 – 23 0 / 0 VP9 only. Smallest and largest distance between golden/alt-ref frames. 0 leaves the choice to the encoder. The maximum has to be 0 or at least 2, and the minimum may not exceed it; Hybrid corrects the values.

Noise reduction

These controls set the temporal filter that builds the alt-ref frame; they are only available while Alternate reference reduction frame decision is above 0.

Control vpxenc option Range / values Hybrid default Meaning
Max noise reduction reference frame count --arnr-maxframes 0 – 15 5 Number of frames that are blended into an alt-ref frame. More frames remove more noise from the reference.
Max noise reduction reference strength --arnr-strength 0 – 6 3 Strength of that filter.
Noise reduction direction --arnr-type backward, forward, centered centered VP8 only. Which neighbours of the alt-ref frame are used: earlier frames (1), later frames (2) or both. centered is the encoder's default and is not written.

Further controls

Control vpxenc option Range / values Hybrid default Meaning
Target level --target-level none, 1, 1.1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 6, 6.1, 6.2 none VP9 only. VP9 level the stream should stay within (limits for picture size, sample rate, bit rate and buffer), for hardware players. Written as 10 … 62; none is written as 255 (off).
Tune --tune none, PSNR, SSIM none Optimizes the encoder decisions for one of the two metrics. VP8 and VP9.
Adaptive quantization --aq-mode none, variance, complexity, cyclic refresh, equator360 none VP9 only, 2-pass modes and average bitrate (1-pass). Varies the quantizer inside a frame: by variance, by complexity, with a cyclic refresh of picture areas, or for 360° video.
Tune content --tune-content default, screen, film default VP9 only. Adapts internal decisions to screen recordings or to film material.
Stereo mode --stereo-mode none, left-right, bottom-top, right-left off, none Declares the frame packing of a 3D video. It is a flag for the player; the picture is not changed. The list is active once the box is checked.
Corpus Complexity --corpus-complexity on/off off VP9 only, specific filesize/bitrate modes. Switches on the corpus VBR variant of the 2-pass rate control. Hybrid always writes the option in the VP9 2-pass modes, with 0 or 1.

VP9 Temporal

All four controls are VP9 only.

Control vpxenc option Range / values Hybrid default Meaning
Enable temporal dependency model --enable-tpl on/off on Lets the encoder spend more bits on blocks that many later frames refer to. The encoder has it on by default, so Hybrid writes 0 or 1 explicitly. It only has an effect in 2-pass; locked in the 1-pass modes.
Alt-ref adaptive quantization --alt-ref-aq=1 on/off off A special adaptive quantization for the alt-ref frames. 2-pass modes only.
Frame periodic boost --frame-boost=1 on/off off Periodically raises the quality of a frame. 2-pass modes only.
Keyframe temporal filtering --enable-keyframe-filtering=1 on/off off Applies the temporal filter to key frames as well. Available in every encoding mode.

Rate Control

VPX Rate Control tab
VPX Rate Control tab

Client Requirements

Control vpxenc option Range / values Hybrid default Meaning
Initial buffer size (ms) --buf-initial-sz 0 – 60000 4000 How much data the player buffers before it starts playing, as a duration at the target bit rate.
Optimal buffer size (ms) --buf-optimal-sz 0 – 60000 5000 The buffer fill the encoder tries to keep.
Buffer size (ms) --buf-sz 0 – 60000 6000 Total size of the player's buffer. The three values describe how much the bit rate may vary over time; they matter for streaming, hardly for files.
Undershoot datarate --undershoot-pct 0 – 100 0 How far the rate control may fall below the target on easy frames to save bits for hard ones, in percent. 0 keeps the codec's own setting and writes nothing.
Overshoot datarate --overshoot-pct 0 – 100 0 How far the rate control may go above the target on hard frames, in percent. 0 keeps the codec's own setting and writes nothing.

Rate Control

Control vpxenc option Range / values Hybrid default Meaning
Quantizer min/max --min-q, --max-q 0 – 63 each 0 / 63 Best and worst quantizer the rate control may use. Raising the minimum saves bits on easy scenes, lowering the maximum protects quality at the price of missing the bit rate. Written in the 2-pass, average bitrate (1-pass) and constrained quality modes; locked for constant quantizer and lossless (lossless forces 0/0).
CBR <-> VBR frame adjust (%) --bias-pct 0 – 100 70 How strongly the 2-pass rate control follows the complexity found in the first pass: 0 distributes the bits evenly (CBR-like), 100 fully by complexity (VBR). 2-pass modes only.
Section min/max (%) --minsection-pct, --maxsection-pct 1 – 10000 each 15 / 10000 Lowest and highest bit rate a single GOP may get, in percent of the target bit rate. 2-pass modes only.
Statistics file --fpf file path empty File for the first-pass statistics. Empty: Hybrid uses a file in its temp folder. Needed when the two passes are run as separate jobs. The button opens a file dialog.

Misc

VPX Misc tab
VPX Misc tab
Control vpxenc option Range / values Hybrid default Meaning
Noise filtering --noise-sensitivity 0 – 6 0 Simple temporal denoiser inside the encoder; higher is stronger. A dedicated denoising filter before the encoder usually does better, so 0 is the normal choice.
Sharpness --sharpness 0 – 7 0 Weakens the loop filter: values above 0 give a sharper but more blocky picture and lower PSNR.
Threads --threads 0 – 64 0 Upper limit for the encoder threads. With 0 Hybrid writes twice the number of logical CPUs (64 at most).
Static threshold --static-thresh 0 – 10000 0 Blocks that change less than this threshold are skipped. Speeds up encoding of static content, but any value above 0 can leave stale picture areas.
Row multi-threading --row-mt on/off on VP9 only. Threading by rows of blocks, which uses many cores much better than tiles alone. The output is then not bit-identical from run to run.
Error resilience --error-resilient=1 on/off off Makes the stream more robust against lost packets, at a cost in compression. Only for streaming over unreliable links.
No too small warning – on/off off Hybrid warns when the computed output size is below 1 MB and raises it to 1 MB. This switch suppresses that.
Command line addition (appended) text empty Free text added at the end of the encoder options, without any check.

The Configuration row at the bottom saves, loads and deletes named sets of these settings.

Example

VP9, specific filesize/bitrate (2-pass) at 1500 kbit/s, VBR, profile low, good with CPU utilization 0, on a 10-bit YUV 4:2:0 source (640x352, 25 fps). The profile low is 8-bit, so Hybrid converts the video to 8-bit 4:2:0 in the script. First pass:

vspipe "encodingTempSynthSkript.vpy" - --outputindex 0 -c y4m --progress | vpxenc --codec=vp9 --row-mt=1 --passes=2 --pass=1 --target-bitrate=1500 --end-usage=vbr --fpf="test.stats" --profile=0 --good --corpus-complexity=0 --cpu-used=0 --min-q=0 --max-q=63 --bias-pct=70 --minsection-pct=15 --maxsection-pct=10000 --lag-in-frames=25 --buf-sz=6000 --buf-initial-sz=4000 --buf-optimal-sz=5000 --drop-frame=0 --resize-allowed=0 --kf-min-dist=0 --kf-max-dist=250 --auto-alt-ref=1 --arnr-maxframes=5 --arnr-strength=3 --noise-sensitivity=0 --sharpness=0 --static-thresh=0 --aq-mode=0 --tile-columns=2 --tile-rows=1 --min-gf-interval=0 --max-gf-interval=0 --threads=64 --width=640 --height=352 --i420 --color-space=unknown --target-level=255 --input-bit-depth=8 --bit-depth=8 --enable-tpl=1 --ivf -o NUL -

The second pass is the same call with --pass=2 and the real output:

... --pass=2 ... --enable-tpl=1 --ivf -o "test.ivf" -

How Hybrid calls it

  • The filter script (Vapoursynth or AviSynth) is piped into vpxenc as Y4M; frame size, chroma format and bit depth are also passed as options.
  • vpxenc writes an IVF file into the temp folder, which Hybrid then muxes into the chosen container.
  • For the 2-pass modes Hybrid creates two jobs: the first writes to NUL and fills the statistics file, the second reads it.
  • --codec comes first; for VP9 --row-mt follows directly.
  • VP9 only options (tiles, --aq-mode, --min-gf-interval/--max-gf-interval, --tune-content, --color-space, --target-level, --frame-parallel) are left out for VP8; VP8 gets --token-parts instead.
  • --lag-in-frames, --bias-pct, --minsection-pct, --maxsection-pct, --enable-tpl, --alt-ref-aq, --frame-boost and --corpus-complexity are only written in the 2-pass modes.
  • Before writing --max-gf-interval Hybrid checks it against the look-ahead: the look-ahead is raised to the interval + 2, or the interval is lowered when that is not possible (in 1-pass the encoder's look-ahead of 25 applies).
  • Options whose value 0 means "encoder default" (--undershoot-pct, --overshoot-pct, --max-intra-rate, --max-inter-rate) are only written when they are above 0.

Background

VP8 or VP9

VP9 needs roughly half the bit rate of VP8 for the same quality on HD material, but encodes slower. VP8 only makes sense when the target cannot play VP9. Lossless coding, 10/12 bit, 4:2:2/4:4:4, tiles, levels, adaptive quantization and the controls of the VP9 Temporal box exist only in VP9; token partitions, the screen content mode and the noise reduction direction only in VP8.

Speed

The pair Basic speed control and CPU utilization modifier has by far the largest influence on encoding time. For VP9, good with a modifier of 1 or 2 is a common compromise; 0 is the slowest setting of good. Together with Row multi-threading and tile columns the encoder scales over many cores.

Sources