uvg266 VVC Encoder

repository·master·Indexed 43 days ago

https://github.com/ultravideo/uvg266

An open-source Versatile Video Coding (VVC) encoder designed for high-performance video compression research and application. It supports Linux and Windows, featuring a wide range of CLI parameters for rate control, GOP structure, and compression tools, as well as encoding presets ranging from ultrafast to placebo.

Tokens
8.6K
Snippets
25
Records
38
Agent score
53%

What's inside uvg266

  1. Overview of uvg266

    master
    uvg266 is an open-source VVC (Versatile Video Coding) encoder licensed under the 3-clause BSD license. It is currently under active development with ongoing improvements to encoding speed and Rate-Distortion (RD) quality. It supports Linux and Windows platforms.
  2. What is ThreadWrapper

    master
    ThreadWrapper is a utility that wraps pthread functions to ensure they call C++ standard functions instead. This is specifically designed to provide compatibility for the Kvazaar open-source HEVC encoder. Currently, it only implements the subset of functions required by Kvazaar, though it is designed to be extensible by contributors.
  3. Understand the compressed cost data format

    master

    The extracted block costs are stored in a compressed format sorted by block QP. Because the datasets are extremely large (often exceeding workstation RAM), they are designed to be processed with $O(1)$ memory complexity rather than being memory-mapped.

    Each entry in the compressed file follows this structure:

    Size (B)Description
    4size: Coeff group size, in int16's
    4ccc: Coeff group's coding cost
    size * 2coeffs: Coeff group data
  4. Understand LP-GOP (Low-Delay GOP) syntax

    master

    The uvg266 encoder supports a specific syntax for Low-Delay GOPs to control temporal scaling. The syntax follows the pattern lp-g(num)d(num)t(num):

    • g: GOP length.
    • d: Number of GOP layers.
    • t: Number of references to skip for temporal scaling (e.g., t4 means only every fourth picture needs to be decoded).

    Example: lp-g8d4t1 defines a GOP with length 8, 4 layers, and a temporal skip factor of 1.

    # Syntax: lp-g<gop_length>d<layers>t<temporal_skip>
    # Example: lp-g8d4t1
  5. Integrate the uvg266 library

    master

    The core API is defined in uvg266.h.

    Windows Static Linking: When using the static uvg266 library on Windows, you must define the UVG_STATIC_LIB macro.

    Dependencies: You can use pkg-config to obtain the necessary linker and compiler flags for integration.

  6. Extract block costs using extract_rdcosts.py

    master

    To extract block costs, you must first build Kvazaar as usual. Then, configure the extract_rdcosts.py script by editing the parameters at the beginning of the file—specifically the number of CPU cores to use and the list of video sequences you wish to encode.

    Running extract_rdcosts.py will use Kvazaar to encode each sequence and extract the measured costs for the quantized blocks. The resulting data is stored in a compressed format, sorted by block QP.

    # Edit extract_rdcosts.py parameters (cores and sequences) then run:
    python extract_rdcosts.py
  7. Run unit tests

    master

    The project uses the greatest unit testing framework.

    Setup: Before running tests, you must initialize and update the submodules:

    git submodule init
    git submodule update

    Execution:

    • Linux: Run make test.
    • Windows: The Visual Studio project links unit tests against the actual .lib file used by the encoder.
    git submodule init
    git submodule update
    make test
  8. Basic usage of uvg266 VVC encoder

    master

    To encode a video using uvg266, you must provide an input file and an output filename. If the input resolution is not part of the filename or if you are using a pipe, you must explicitly specify the resolution using --input-res.

    By default, the encoder expects 8-bit yuv420p or 10-bit yuv420p10le input. You can override these using --input-format and --input-bitdepth.

    uvg266 --input BQMall_832x480_60.yuv --output out.vvc
    
    # If resolution is not in filename:
    uvg266 --input input.yuv --input-res 1920x1080 -o out.vvc
  9. Build uvg266 using CMake

    master

    To compile uvg266 from source using CMake, follow these steps. On Ubuntu, ensure build-essential and cmake are installed.

    1. Configure the build:
      cmake -B build -S .
    2. Build the project:
      cmake --build build --parallel
    3. Install (optional):
      sudo cmake --install build

    Visual Studio users can open the CMakeLists.txt directly, or use the CMake-CLI to generate Visual Studio project files.

    cmake -B build -S .
    cmake --build build --parallel
    sudo cmake --install build
  10. Calculate per-QP average costs with rdcost_do_avg.py

    master

    After running the regression, use rdcost_do_avg.py to calculate the average costs per QP across all processed sequences. For each QP, the script takes the results for that QP from every sequence and calculates their average.

    This averaged data is intended to be used to populate the default_fast_coeff_cost_wts table located in src/fast_coeff_cost.h.

    python rdcost_do_avg.py
  11. Build and run the RD cost analysis tools

    master

    To analyze costs via linear regression, you must first compile the two C tools. Once compiled, you can run the regression in parallel using run_filter.py.

    # Build the tools
    gcc filter_rdcosts.c -O2 -o frcosts_matrix
    gcc ols_2ndpart.c -O2 -o ols_2ndpart
    
    # Run the regression in parallel
    python run_filter.py
  12. Use Region of Interest (ROI) files with Kvazaar

    master

    You can use the --roi switch in Kvazaar to specify a text file that defines regions of interest for encoding. This allows you to assign different quantization parameter (QP) offsets to specific areas of a frame, controlling the bit distribution and quality across the image.

    ROI File Format

    The ROI file is a simple text file structured as follows:

    1. Header Row: Contains two integers representing the number of columns and rows the frame is divided into.
    2. Data Row: Contains a single row of integers. The number of entries must equal columns * rows. Each entry represents the delta QP value assigned to that specific region.

    Example Configuration

    The following example divides a frame into a 2x2 grid. The top two regions are assigned a delta QP of 5 (lower quality/higher compression), while the bottom two regions are assigned 0 (standard quality/no offset).

    2 2
    5 5 0 0