Configure VC-2 Slice Size and Wavelets in FFmpeg
This article provides a practical guide on how to configure the slice size and wavelet parameters when using the VC-2 (Dirac Pro) video encoder in FFmpeg. You will learn the exact command-line options required to adjust wavelet depth, wavelet type, and slice dimensions to optimize your video encoding workflow for low latency, compression efficiency, or computational speed.
Understanding VC-2 in FFmpeg
VC-2 (standardized as SMPTE 2042-1) is a lightweight, low-latency
video codec designed primarily for production, archival, and IP
transmission. In FFmpeg, the native VC-2 encoder is invoked using the
-c:v vc2 flag.
Because VC-2 is wavelet-based and divides frames into independent slices, configuring the wavelets and slice sizes directly impacts the compression ratio, image quality, and processing speed.
Configuring Wavelet Parameters
Wavelets are the mathematical functions used by VC-2 to decompose video frames into different frequency subbands. You can configure both the type of wavelet and the recursion depth.
1. Wavelet Type
(-wavelet_type)
FFmpeg allows you to choose the wavelet transform filter. The two
most common types are: * 5_3 (Le Gall
5/3): A lower-complexity, integer-to-integer transform. It is
ideal for lossless compression and fast processing. *
9_7 (Deslauriers-Dubuc 9/7): The default
transform. It offers superior compression efficiency and visual quality
for lossy compression but is computationally heavier.
To set the wavelet type, use the -wavelet_type option
with either the string name or its corresponding integer index:
ffmpeg -i input.mp4 -c:v vc2 -wavelet_type 5_3 output.mov2. Wavelet Depth
(-wavelet_depth)
The wavelet depth defines how many times the wavelet transform is recursively applied to the image. A higher depth generally improves compression efficiency for large resolutions but increases computation time.
The value typically ranges from 1 to 5 (the default
is 4). You can set it using the -wavelet_depth option:
ffmpeg -i input.mp4 -c:v vc2 -wavelet_depth 5 output.movConfiguring Slice Size
VC-2 processes video frames by dividing them into a grid of independent rectangular regions called slices. Adjusting slice dimensions is crucial for parallel processing and low-latency transmission.
To define the slice size, you must specify both the width and height
of the slices in pixels using the following options: *
-slice_width: The width of each slice. *
-slice_height: The height of each slice.
Constraints on Slice Dimensions
When defining slice sizes, keep the following rules in mind: 1. The slice width and height must evenly divide the frame’s width and height. 2. The slice dimensions must be multiples of the wavelet decomposition factor. For a wavelet depth of \(D\), the slice dimensions should ideally be divisible by \(2^D\) (for example, if depth is 4, slice dimensions should be multiples of 16).
Example Configuration
To encode a 1920x1080 video with a slice size of 120x60 pixels:
ffmpeg -i input.mp4 -c:v vc2 -slice_width 120 -slice_height 60 output.movComplete Configuration Example
Below is a complete FFmpeg command that combines custom wavelet
settings and slice configurations. This command encodes an input video
using the high-quality 9_7 wavelet, a depth of 4, and a
custom slice size of 192x108:
ffmpeg -i input.mp4 -c:v vc2 -wavelet_type 9_7 -wavelet_depth 4 -slice_width 192 -slice_height 108 output.mov