VCEEnc

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

VCEEnc encodes H.264, H.265 and AV1 on the video encoder that is built into AMD graphics cards and processors. The encoding runs on the GPU, so it is much faster than a software encoder and hardly loads the CPU, at the price of a lower compression at the same quality. Hybrid drives rigaya's command line encoder VCEEncC.

Base → Video: VCEEnc, then the VCEEnc tab

What it does

VCEEncC hands the frames to AMD's encoder interface (AMF); the hardware does motion search, transform and entropy coding. Compared with x264 or x265 there are few options: the codec, the rate control, the size of the GOP, the number of reference and B-frames and a handful of switches. The rate control modes are:

  • variable bitrate and average bitrate: one pass towards a bit rate, with a ceiling for the peaks. This is the usual choice.
  • constant bitrate: the bit rate is held as constant as possible; meant for streaming.
  • constant quantizer: fixed quantizers for I-, P- and B-frames. The size results from the content; useful for tests and when quality matters more than size.

There is no 2-pass mode. A file size can still be aimed at: Hybrid computes the bit rate from the size, but a single pass only hits it roughly.

Requirements

  • An AMD graphics card or processor with hardware encoder and a current driver.
  • H.264 works on practically all of them, H.265 needs a newer generation, AV1 the Radeon RX 7000 series or newer.
  • 10-bit output exists for H.265 and AV1 only; the color format is always 4:2:0.

Which features are offered depends on what the GPU reports. Hybrid asks VCEEncC for the features of the installed hardware (--check-features) and adjusts the tab to the answer for the selected codec: the highest number of reference frames, whether B-frames and interlaced encoding are available, and the highest level. A control that is locked on one machine can therefore be available on another.

Settings

The option column shows the VCEEncC option a control ends up as.

Base

VCEEnc Base tab
VCEEnc Base tab
Control VCEEncC option Range / values Hybrid default Meaning
Codec --codec h264, h265, av1 h264 Video format of the output. H.264 plays everywhere, H.265 and AV1 compress better and allow 10 bit. With AV1 the controls that only exist for H.264/H.265 are locked: references, long term references, adaptive quantization, pre-analysis, motion vector precision, slices and skip frames; the VBV buffer is locked as well.
Encoding mode --cqp, --cbr, --vbr constant quantizer, constant bitrate, average bitrate, variable bitrate variable bitrate Rate control mode, see above. average bitrate and variable bitrate both become --vbr. The mode decides whether the bit rate controls or the quantizer controls are shown.
Target mode – custom, 1/4 CD … 1 BD 50 custom Common media sizes for Target size. With custom the size is entered by hand.
Target size (MiB) bit rate of the mode 0.2 MiB and up off, 700 Aim at a file size instead of a bit rate; Hybrid computes the video bit rate from the size, the length and the size of audio and other streams. With one pass the result is only close to the target.
Bitrate (kbit/s) --vbr, --cbr 16 – 245760 on, 1500 Target bit rate of the bit rate modes.
Filler --filler on/off off Pads the stream with filler data when the content needs less than the bit rate, so that the rate is really constant. Only available in constant bitrate mode.
Max Bitrate (kBit/s) --max-bitrate 1 – 625000 20000 Ceiling for the peaks of the bit rate. Only available in the average bitrate and variable bitrate modes; in constant bitrate mode it follows the bit rate. Hybrid adjusts the value when the bit rate, the profile or the level changes.
VBV max buffer (kBit/s) --vbv-bufsize H.264: 0 – 720000; H.265: 0 – 2400000 20000 Size of the decoder buffer the rate control plans with. A large buffer lets the bit rate swing further and helps difficult scenes, a small one keeps the stream within what a limited decoder or a transmission can take. H.264 and H.265 keep separate values; Hybrid sets the value when the level changes. Locked and not written for AV1.
Quantizer --cqp 1 – 51 20 One quantizer for all frame types; lower is better and bigger. Shown in constant quantizer mode, available with split off.
split --cqp I:P:B on/off on Use one quantizer per frame type instead of a single value.
(I / P / B quantizer) --cqp I:P:B 1 – 51 each 20 / 23 / 25 Quantizers of I-, P- and B-frames. The usual order is I below P below B, because more frames depend on I- and P-frames. Available with split on.
Profile@Level (H.264) --profile, --level auto, baseline, main, high; 1 – 5.2, auto main / auto Profile and level the stream is limited to. high compresses best; baseline and main are for old players. With level auto the encoder picks the level from frame size, frame rate and bit rate. Hybrid does not check the other settings against the choice. The profile and level lists end at the highest profile and level the GPU reports.
Profile/Level/Tier (H.265) --profile, --level, --tier auto, main, main10; 1.0 – 6.2, auto; main, high main10 / auto / main The same for H.265. main10 gives 10-bit output, main 8 bit. The high tier raises the bit rate limit of a level and is meant for professional use.
Profile@Level (AV1) – auto auto Shown with codec av1; both lists are locked and the encoder chooses profile and level itself.
Preset --preset fast, balanced, slow, slower balanced Speed against quality preset of the hardware encoder. The slower presets compress somewhat better; the difference is much smaller than between the presets of a software encoder.
Output bit-depth --output-depth 8-bit, 10-bit 8-bit Bit depth of the output. H.264 is always 8 bit; with H.265 it follows the profile (main10 → 10 bit) and is locked; with AV1 it can be chosen. Written for H.265 and AV1. The filter script delivers this depth.
Sampling – i420 i420 Display only: the chroma format of the output, always 4:2:0.

General

Control VCEEncC option Range / values Hybrid default Meaning
Maximum number of references --ref 0 – 16 2 How many earlier frames a frame may refer to. More can help with animation and repeating content and costs speed. The upper end is what the GPU reports for the codec. Locked for AV1.
Max number of long term references --ltr 0 – 16 0 Number of long term reference frames, which stay available far beyond the normal reference window; 0 leaves it to the encoder. Locked for AV1.
Adaptive quantization --vbaq on/off off Variance based adaptive quantization: moves bits from strongly textured areas, where artifacts are hard to see, to flat areas. Locked in constant quantizer mode and for AV1.
Maximum number of consecutive b-frames --bframes 0 – 3 0 Upper limit of B-frames in a row. B-frames improve compression. Only available when the GPU reports B-frame support for the codec; otherwise it stays at 0.
B-Pyramid --b-pyramid on/off off Lets B-frames be references for other B-frames. Only available with at least one B-frame.

Misc

VCEEnc Misc tab
VCEEnc Misc tab
Control VCEEncC option Range / values Hybrid default Meaning
Gop size max --gop-len 0 – 10000 0 Longest distance between key frames. 0 leaves it to the encoder. Long GOPs save bits, short ones make seeking faster; ten times the frame rate is a common value.
Interlaced encoding --tff / --bff on/off off Encode the output as interlaced. The field order comes from the video that reaches the encoder. Only available when the GPU reports interlaced encoding for the codec; not used for AV1.
Pre-Analysis --pa none, on none Analyses the frames before encoding (scene changes, static scenes, content adaptive quantization, lookahead) and distributes the bits better. Costs speed. Locked in constant quantizer mode and for AV1.
Motion vector precision --motion-est quarter pixel, half pixel, full pixel quarter pixel Precision of the motion search (q-pel, half-pel, full-pel). Quarter pixel is the best, full pixel the fastest. An option for H.264 and H.265; locked for AV1.
Slices --slices 1 – 8 1 Number of slices each frame is split into. More slices limit the damage of a transmission error and cost a little compression. Locked for AV1.
Skip frames --skip-frame on/off off Allows the encoder to skip a frame when the bit rate limit would be broken otherwise. Keeps the rate at the price of stutter; for files it is rarely wanted. Locked for AV1.
enforce HRD --enforce-hrd on/off off Forces the stream to keep to the buffer model (Hypothetical Reference Decoder) of the standard; for hardware players and streaming.
No too small warning – on/off off No warning when the computed file size is below 1 MB.

B-Frames Offset

Only available with at least one B-frame.

Control VCEEncC option Range / values Hybrid default Meaning
Reference --bref-deltaqp 0 – 50 0 Quantizer offset for B-frames that other frames refer to (B-Pyramid). 0 leaves it to the encoder.
Non-Reference --b-deltaqp 0 – 50 0 Quantizer offset for B-frames nothing refers to. A higher value saves bits there, which costs the least because no other frame builds on them. 0 leaves it to the encoder.

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

Example

H.264, variable bitrate with 1500 kbit/s and a maximum of 20000 kbit/s, profile main, level auto, preset balanced, 2 reference frames on a 10-bit YUV 4:2:0 source (640x352, 25 fps):

vspipe "encodingTempSynthSkript.vpy" - --outputindex 0 -c y4m --progress | VCEEnc --y4m -i - --codec h264 --vbr 1500 --max-bitrate 20000 --ref 2 --preset balanced --motion-est q-pel --profile Main --level auto --vbv-bufsize 20000 --slices 1 --sar 1:1 --fps 25.000 --output-file "video.264"

How Hybrid calls it

  • The filter script (Vapoursynth or AviSynth) is piped into VCEEncC as y4m; without a script ffmpeg decodes the source and pipes it.
  • The script delivers the bit depth of the output; the 10-bit source of the example is converted to 8 bit there, because H.264 is encoded with 8 bit.
  • --codec, the rate control option and --preset are always written; --motion-est, --ref, profile, level, --vbv-bufsize and --slices for H.264 and H.265; --output-depth for H.265 and AV1. constant bitrate writes --cbr (with --filler when enabled) and sets --max-bitrate to the bit rate.
  • --gop-len, --ltr, --bframes and the B-frame offsets are only written when they are not 0; B-Pyramid and the offsets only together with B-frames.
  • The pixel aspect ratio (--sar) and the frame rate (--fps) come from Crop/Resize and the output frame rate.
  • VCEEncC writes a raw stream; Hybrid muxes it into the chosen container in a separate job.
  • The filtering, decoding, audio and muxing features of VCEEncC are not used.

Background

Hardware or software encoder

A hardware encoder is built for speed and low power use and has to make its decisions in a fixed amount of time. At the same bit rate x264, x265 or SVT-AV1 give better quality with their slower presets; at high bit rates the difference gets small. VCEEnc is the right choice when time matters more than the last bit of compression, e.g. for recordings, previews or large amounts of material.

Quality based encoding

There is no CRF mode on this tab. For a roughly constant quality use constant quantizer; values around 20 – 26 for I-frames are a reasonable start, and the P- and B-frame values a few steps above.

Sources