Kvazaar

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

Kvazaar is an open-source encoder for H.265/HEVC, developed by the Ultra Video Group at Tampere University. It is a pure command line encoder with a constant quantizer mode and a single-pass bit rate mode, and it offers a set of low-level HEVC tools (block sizes, search methods, tiles-related constraints) that other encoders hide. Hybrid drives the command line encoder kvazaar.

Base → Video: kvazaar, then the kvazaar tab

What it does

Kvazaar splits every frame into 64×64 coding tree units, divides them further into coding and prediction units, predicts each unit from already coded frames (inter) or from neighbouring pixels (intra), transforms what is left and quantizes it. The quantizer decides size and quality. Hybrid offers two ways to set it:

  • constant quantizer: the same base quantizer for the whole video. Quality is predictable, the size results from the content. With quantizer 0 the encoding can also be made lossless.
  • average bitrate: one pass that steers the quantizer towards a bit rate.

Almost all other settings trade encoding time against compression: how large and how small the blocks may be, how thoroughly motion and coding modes are searched and which early exits the search may take. The presets bundle these settings into ten speed steps.

Requirements

The kvazaar binary; the encoder is only offered when Hybrid finds it. Hybrid feeds Kvazaar YUV 4:2:0 with 8 or 10 bit; other chroma formats are converted before encoding. The output is a raw HEVC stream that is muxed into mkv, mp4/mov or m2ts/ts afterwards.

Settings

The option column shows the kvazaar option a control ends up as. With Minimize command line on (the default), options that equal Kvazaar's defaults or the detected preset are not written.

Base

Kvazaar Base tab
Kvazaar Base tab

General

Control kvazaar option Range / values Hybrid default Meaning
Encoding mode --qp, --bitrate constant quantizer (1-pass), average bitrate (1-pass) constant quantizer (1-pass) Rate control mode, see above. The row below the list changes with the mode.
Quantization strength --qp 0 – 51 22 Quantizer of the constant quantizer mode. Lower values keep more detail and give bigger files; a step of 6 roughly doubles or halves the size. Only available in constant quantizer mode.
Lossless --lossless / --no-lossless on/off off Lossless coding. It only takes effect with Quantization strength 0; with any other quantizer --no-lossless is written. Expect very large files.
Bitrate (kbit/s) --bitrate 16 – 245760 1500 Target bit rate of the average bitrate mode. Kvazaar's --bitrate counts in bits per second, so Hybrid writes the value times 1000. Only shown in average bitrate mode.
Target size (MiB), Target mode – 0.2 MiB and up; custom, 1/4 CD … 1 BD 50 off, 700, custom File size target as on other encoder tabs. It needs a 2-pass mode, which Kvazaar does not have in Hybrid, so these controls stay locked and Target mode is kept on custom.

Deblocking

Control kvazaar option Range / values Hybrid default Meaning
Deblocking --deblock / --no-deblock on/off on The in-loop deblocking filter of HEVC, which smooths the edges between blocks. Switching it off also locks the three controls of the group; SAO keeps its last value and is still written.
Threshold, Strength --deblock <beta:tc> -6 – 6 each 0 / 0 Threshold (beta) shifts how many edges are treated as blocking, Strength (tc) how strongly they are filtered. Negative values keep more detail, positive values smooth more.
SAO --sao off, band, edge, full full Sample adaptive offset, a second in-loop filter that corrects banding (band offset) and ringing at edges (edge offset). full uses both. The option is written whether Deblocking is on or off; the list sits inside the Deblocking group, so set it before switching deblocking off.

Compatibility Restrictions

Control kvazaar option Range / values Hybrid default Meaning
Level --level 6.2, 6.1, 6.0, 5.2, 5.1, 5.0, 4.1, 4.0, 3.1, 3.0, 2.1, 2.0, 1.0 6.2 HEVC level that is written into the stream. Kvazaar stops with an error when frame size, frame rate or bit rate exceed the limits of the level. Lower it only when a player demands a certain level.
BitDepth --input-bitdepth 8-bit, 10-bit 8-bit Bit depth Hybrid delivers to the encoder; a source with another depth is converted first. Kvazaar encodes with the lowest bit depth of its build that holds the input (kvazaar --version lists them), which gives the Main or Main 10 profile.
Tier --high-tier High, Main High Tier of the level. The High tier allows higher bit rates and exists from level 4.0 on; below that the control is locked on Main.

Presets

Control kvazaar option Range / values Hybrid default Meaning
Preset --preset ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo medium Kvazaar's speed steps. Selecting an entry changes nothing; the arrow button next to it sets the controls of the other sub-tabs to the values of the preset. medium equals Kvazaar's defaults. --preset itself is only written by Minimize command line.

Quantization

Kvazaar Quantization tab
Kvazaar Quantization tab
Control kvazaar option Range / values Hybrid default Meaning
Rate distortion optimization --rdoq / --no-rdoq on/off on Rate-distortion optimized quantization: every coefficient is weighed against the bits it costs. A clear gain for moderate time. When it is off, Skip RDOQ for 4x4 blocks is locked and --rdoq-skip is not written; --rd, --mv-rdo and --intra-rdo-et do not depend on it.
RDO-Level --rd 0 – 5 (six entries) Skip intra if inter is good enough. (0) Thoroughness of the mode search. 0 skips the intra search when inter prediction is good enough, 1 adds a rough intra search, 2 to 4 compare a growing number of candidates by their real cost, 5 tries all intra modes. Higher levels are slower.
CABAC fast residual cost --fast-residual-cost 0 – 50 0 Below this quantizer the cost of the residual coefficients is estimated instead of computed with the entropy coder. 0 switches the shortcut off; the fastest presets use 28.
Skip RDOQ for 4x4 blocks --rdoq-skip / --no-rdoq-skip on/off off Leaves the smallest transform blocks out of the optimized quantization, which saves some time.
Intra RDO opt --intra-rdo-et / --no-intra-rdo-et on/off off Early exit for the intra search: modes are only checked until one is found whose residual is zero.
AQ for 360° with erp --erp-aqp / --no-erp-aqp on/off off Adaptive quantizer for 360° video in equirectangular projection: the stretched areas near the poles get fewer bits. Only for such material.
Custom matrix, Matrix File --cqmfile file empty File with custom quantization matrices. Only available with Scaling list mode custom.
Scaling list mode --scaling-list off, custom, default off Whether quantization scaling lists are used: none, HEVC's default lists, or the custom ones from Custom matrix. custom without a matrix file is not written, because Kvazaar refuses it.

Motion

Kvazaar Motion tab
Kvazaar Motion tab
Control kvazaar option Range / values Hybrid default Meaning
Constrain movement vectors --mv-constraint none, frametile, frametilemargin none Keeps motion vectors inside the tile a block belongs to, with or without a safety margin. Only of use for streams whose tiles have to be decodable on their own.
Motion partitioning: symmetric --smp / --no-smp on/off off Allows inter blocks to be split into two equal halves (2N×N, N×2N). Small gain, more search time.
Motion partitioning: asymmetric --amp / --no-amp on/off off Also allows unequal splits (1:3). Slower again; helps mostly at hard edges.
MV RDO --mv-rdo / --no-mv-rdo on/off off Computes the cost of motion vectors exactly instead of estimating it.
Motion Estimation --me hexbs, tz, full, full8, full16, full32, full64, dia hexbs Search pattern for whole-pixel motion: hexagon, test zone, full search (with a fixed range of 8 – 64 pixels) or diamond. hexbs is fast and good enough for most material; the full searches are very slow.
ME Steps --me-steps 0 – 64 0 Limit for the number of search steps of hexbs and dia. 0 means no limit and is written as -1. Locked for the other search methods.
Subpixel ME --subme Integer motion estimation only (0), + 1/2-pixel horizontal and vertical (1), + 1/2-pixel diagonal (2), + 1/4-pixel horizontal and vertical (3), + 1/4-pixel diagonal (4) + 1/4-pixel diagonal How far the motion search is refined below whole pixels. The full refinement costs little and should only be reduced for very fast encodes.
Full intra search --full-intra-search / --no-full-intra-search on/off off Tests all intra directions already in the rough search instead of a selection.
Transform Skip --transform-skip / --no-transform-skip on/off off Lets the encoder try 4×4 blocks without a transform. Useful for screen content with sharp text and graphics.
Bi-prediction --bipred / --no-bipred on/off on Lets a block be predicted from two references at once. Better compression, more search time.
Inter / Intra prediction unit size (from-to) --pu-depth-inter, --pu-depth-intra 64x64, 32x32, 16x16, 8x8 (intra also 4x4) inter 64x64 – 8x8, intra 32x32 – 4x4 Largest and smallest block size the search may use for inter and for intra prediction (depth 0 = 64×64, every step halves the size). A narrower range is the quickest way to speed up the encoder. The first pair sets the inter range, the second pair the intra range.
Transform split --tr-depth-intra 0 – 4 0 How many times the transform of an intra block may be split further.
TeMoVec prediction --tmvp / --no-tmvp on/off on Temporal motion vector prediction: motion vectors may be predicted from the co-located block of a reference frame.
ME early termination --me-early-termination off, on, sensitive on Whether the motion search may stop as soon as a good match is found. sensitive stops even earlier and is what the fast presets use.
CU split termination --cu-split-termination off, zero zero zero stops splitting a block further once its residual is zero.
Early skip --early-skip / --no-early-skip on/off on Tries the merge candidates first and ends the search for a block when it can be coded as skipped.
Max merge --max-merge 1 – 5 5 Number of merge candidates that are tested.
Implicit residual DPCM --implicit-rdpcm / --no-implicit-rdpcm on/off off A prediction of the residual that Kvazaar only supports for lossless coding; it is only written with Lossless on and quantizer 0.
Region of interest, ROI File --roi file empty File with a map of quantizer offsets that gives parts of the picture more or fewer bits. The map may have any size and is scaled to the video. Works in both encoding modes.

Frames

Kvazaar Frames tab
Kvazaar Frames tab
Control kvazaar option Range / values Hybrid default Meaning
Maximum number of reference frames --ref 1 – 15 4 How many already coded frames a frame may refer to. More references cost encoding time and decoder memory and rarely help beyond 4 – 6.
Intra period --period 0 – 5000 64 Distance between intra pictures, i.e. the points a player can seek to. 0 makes only the first picture intra, 1 makes every picture intra.
Open GOP --open-gop / --no-open-gop on/off on With an open GOP, pictures may refer across the intra picture, which saves bits. Switch it off when the stream is to be cut or joined at intra pictures.
GOP structure --gop text 16 Structure of the pictures between two anchors: 0 disables it, 8 and 16 are B-frame pyramids of that length, lp-g8d4t2 and similar describe a low-delay structure (g = length, d = number of layers, t = temporal scaling).

VUI

Kvazaar VUI tab
Kvazaar VUI tab

The Video Usability Information tells the player how the decoded video is to be shown. It only sets flags; the picture is not converted. A value is written when its check box is set.

Control kvazaar option Range / values Hybrid default Meaning
Overscan --overscan undef, show, crop off, undef Whether the edge of the picture may be cut off by overscan.
Video format --videoformat undef, component, pal, ntsc, secam, mac off, undef Original video system.
Color range --range limited, full on, limited Value range of the video (tv/pc). The value follows the range of the video that reaches the encoder.
Color primaries, from input --colorprim undef, bt709, bt470m, bt470bg, smpte170m, smpte240m, film, bt2020 off, undef, from input on Color primaries. With from input the value is taken from the source and the list is locked.
Transfer characteristics, from input --transfer undef, bt709, bt470m, bt470bg, linear, log100, log316, smpte170m, smpte240m, iec61966-2-4, iec61966-2-1, bt1361e, bt2020-10, bt2020-12 off, undef, from input on Transfer function (gamma). from input as above.
Color matrix, from input --colormatrix undef, bt709, fcc, bt470bg, smpte170m, smpte240m, GBR, YCgCo, bt2020nc, bt2020c on, undef, from input on Matrix for the YUV ↔ RGB conversion. With from input Hybrid sets it from the video that reaches the encoder.
Chroma sample location --chromaloc 0 – 5 off, 0 Position of the chroma samples relative to luma.

The pixel aspect ratio is always written (--sar) and comes from Crop/Resize.

Signaling

Kvazaar Signaling tab
Kvazaar Signaling tab
Control kvazaar option Range / values Hybrid default Meaning
Info SEI --info / --no-info on/off on Writes an SEI message with the encoder name and version into the stream.
VPS Period --vps-period 0 – 256 0 How often the video parameter set is repeated: 0 sends it only with the first frame, N with every Nth intra frame. Repeating helps when a stream is joined in the middle.
QP at CU level --set-qp-in-cu on/off off Signals the quantizer per coding unit and leaves the picture and slice level values at zero. Only needed for special bitstream processing.
Access Unit Delimiters --aud / --no-aud on/off off Writes access unit delimiters; some transport streams and players need them.
Sign hiding --signhide / --no-signhide on/off off Hides the sign of one coefficient per group in the parity of the others, which saves bits. The slow presets switch it on.

Misc

Kvazaar Misc tab
Kvazaar Misc tab
Control kvazaar option Range / values Hybrid default Meaning
Minimize command line --preset on/off on Shortens the call: Hybrid looks for the preset that matches the settings best, writes it as --preset and drops every option that equals the preset or Kvazaar's defaults.
Calculate PSNR --psnr / --no-psnr on/off on Lets Kvazaar compute the PSNR of every frame for its log. It does not change the output; switching it off saves a little time.
Threads --threads -1 – 64 -1 Number of encoding threads. -1 is written as auto, 0 does everything in the main thread.
Wavefront parallel processing --wpp / --no-wpp on/off on Encodes the rows of a frame in parallel, each a little behind the row above. This is what lets Kvazaar use many cores; the cost in compression is small.
Frame-level parallelism --owf -1 – 64 -1 How many additional frames are encoded at the same time (N means N+1 frames). -1 is written as auto. More frames need more memory.

The Configuration row below the tabs saves, loads and deletes named sets of all Kvazaar settings.

Example

Constant quantizer 22, level 6.2 in the High tier, 8 bit, on a 10-bit YUV 4:2:0 source (640x352, 25 fps) with Minimize command line on. All other controls match the preset medium, so only the preset is written:

vspipe "encodingTempSynthSkript.vpy" - --outputindex 0 -c y4m --progress | kvazaar --preset medium -i - --input-res 640x352 --input-fps 25/1 --input-format P420 --input-file-format y4m --input-bitdepth 8 --level 6.2 --high-tier --qp 22 --sar 1:1 --range tv --colormatrix bt470bg -o "video.265"

How Hybrid calls it

  • The filter script (Vapoursynth or AviSynth) is piped into kvazaar as y4m; without a script ffmpeg decodes the source and pipes the video.
  • The script delivers YUV 4:2:0 in the bit depth chosen on the Base tab; the 10-bit source of the example is converted to 8 bit there.
  • Frame size, frame rate, input format and bit depth are always passed (--input-res, --input-fps, --input-format P420, --input-file-format y4m, --input-bitdepth).
  • --level is always written, --high-tier with tier High.
  • The preset list is not passed on as selected. Its button sets the single controls, and Hybrid builds the call from the controls; --preset only appears through Minimize command line. With it off every option is written out.
  • Kvazaar writes a raw HEVC stream (.265); Hybrid muxes it into the chosen container in a separate job.

Background

Block sizes

HEVC codes a frame in 64×64 units that can be split in four again and again. The prediction unit sizes on the Motion tab limit this tree from both ends: a smaller upper size and a larger lower size mean fewer combinations to test. The fast presets do exactly that (for example intra only 16×16 – 8×8), the slow ones allow the full range and add the symmetric and asymmetric partitions.

GOP structure

The default 16 codes the pictures between two anchors as a pyramid of B-frames, which compresses best but needs the decoder to reorder pictures. The low-delay structures (lp-…) only refer to earlier pictures and are meant for live transmission.

Sources