VCEEnc

repository·master·Indexed 42 days ago

https://github.com/rigaya/vceenc

A tool for investigating the performance and image quality of AMD hardware encoders (VCE/VCN). It includes VCEEncC, a command-line interface for transcoding, and an AviUtl plugin. Supports H.264/AVC, HEVC, and AV1 encoding with CQP, CBR, and VBR modes, alongside a wide array of VPP filters for video pre-processing.

Tokens
33.8K
Snippets
107
Records
158
Agent score
54%

What's inside VCEEnc

  1. Overview of VCEEnc

    master

    VCEEnc is a tool designed to investigate the performance and image quality of AMD's hardware encoder (VCE/VCN). It is provided in two forms:

    1. VCEEncC.exe: A standalone command-line version used for transcoding tasks.
    2. VCEEnc.auo: An output plugin specifically for AviUtl.

    Core Capabilities

    • Encoding: Supports H.264/AVC, HEVC, and AV1 using VCE/VCN.
    • Encode Modes: Supports CQP (fixed quantization), CBR (Constant bitrate), and VBR (Variable bitrate).
    • Advanced Settings: Allows configuration of codec profile, level, SAR, colormatrix, maxbitrate, GOP length, and more.
  2. Features of VCEEnc and VCEEncC

    master

    Common Features (VCEEnc & VCEEncC)

    • Encoding via VCE: Supports H.264/AVC and HEVC (Polaris and later).
    • Encoding Modes: CQP (Constant QP), CBR (Constant Bitrate), VBR (Variable Bitrate).
    • Parameters: Level/Profile specification, Max Bitrate, Max GOP length, SAR ratio, Color Matrix, Reference distance, and B-frame count.

    VCEEnc (AviUtl Plugin) Specifics

    • Audio encoding.
    • Muxing audio and chapters.
    • Automatic field shift support.

    VCEEncC (CLI) Specifics

    • Input Formats: Supports avs, vpy, y4m, raw, etc.
    • Hardware Decoding: H.264, HEVC, MPEG2, VP9, VC-1.
    • Hardware Resizing.
    • Audio: Extraction from source files and audio encoding.
    • Muxing: Supports multiple containers like mp4, mkv, ts.
    • Metrics: Calculates SSIM/PSNR of encoding results.
    • GPU-Accelerated Filtering (OpenCL):
      • Deinterlacing: afs (Auto Field Shift), nnedi.
      • Subtitle burning.
      • Color space conversion: hdr2sdr.
      • Resizing: spline16, spline36, spline64, lanczos2, lanczos3, lanczos4.
      • Rotation / Inversion.
      • Padding (Black bars).
      • Banding reduction.
      • Denoising: knn (K-nearest neighbor), pmd (Regularized PMD method).
      • Detail enhancement: unsharp, edgelevel (Edge level adjustment), warpsharp.
  3. How GPU auto-selection works in VCEEncC

    master

    When multiple GPUs capable of VCE/VCN are present, VCEEncC automatically selects the optimal GPU based on the following logic:

    1. Capability Check: It filters GPUs that support the specified codec, profile, and level, as well as 10-bit depth and hardware decoding (if --avhw is specified).
    2. Feature Prioritization: Among capable GPUs, it prioritizes those that support B-frames (if specified) and --pa (pre-analysis).
    3. Efficiency Selection: If multiple GPUs meet the above criteria, it selects the one with the lowest Video Engine (VE) utilization or lowest GPU utilization to maximize encoding speed.

    Note: VE/GPU utilization is measured at the start of encoding. Because there is a delay of several seconds in reporting, starting multiple encodes simultaneously may cause them to be assigned to the same GPU. To manually select a GPU, use the --device option.

  4. How VPP filters are applied

    master

    VPP (Video Post-Processing) options allow you to add filter processing before encoding. The order of application for VPP filters is fixed and does not depend on the order they are specified on the command line. The filters are applied in the following sequence:

    1. --vpp-colorspace
    2. --vpp-libplacebo-tonemapping
    3. --vpp-rff
    4. --vpp-delogo
    5. --vpp-afs
    6. --vpp-nnedi
    7. --vpp-bwdif
    8. --vpp-yadif
    9. --vpp-rtgmc
    10. --vpp-rtgmc-bob
    11. --vpp-rtgmc-search-prefilter
    12. --vpp-rtgmc-edi
    13. --vpp-rtgmc-retouch
    14. --vpp-rtgmc-shimmer-repair
    15. --vpp-rtgmc-primitive
    16. --vpp-degrain
    17. --vpp-kfm
    18. --vpp-decomb
    19. --vpp-ivtc
    20. --vpp-transform/rotate
    21. --vpp-decimate
    22. --vpp-mpdecimate
    23. --vpp-select-every
    24. --vpp-convolution3d
    25. --vpp-smooth
    26. --vpp-denoise-dct
    27. --vpp-bm3d
    28. --vpp-fft3d
    29. --vpp-msmooth
    30. --vpp-knn
    31. --vpp-nlmeans
    32. --vpp-pmd
    33. --vpp-hqdn3d
    34. --vpp-anime4k-shader
    35. --vpp-onnx
    36. --vpp-onnx-deint
    37. --vpp-rife-ov
    38. --vpp-descale
    39. --vpp-subburn
    40. --vpp-libplacebo-shader
    41. --vpp-resize
    42. --vpp-unsharp
    43. --vpp-vinverse
    44. --vpp-chromashift
    45. --vpp-deblock
    46. --vpp-deflicker
    47. --vpp-stab
    48. --vpp-colorfix
    49. --vpp-dehalo
    50. --vpp-finedehalo
    51. --vpp-hqdering
    52. --vpp-edgelevel
    53. --vpp-msharpen
    54. --vpp-cas
    55. --vpp-warpsharp
    56. --vpp-detailsharpen
    57. --vpp-maa
    58. --vpp-softlight
    59. --vpp-curves
    60. --vpp-tweak
    61. --vpp-deband
    62. --vpp-libplacebo-deband
    63. --vpp-padding
    64. --vpp-tweak (Note: listed twice in source)
  5. Configure Dolby Vision profile and RPU metadata

    master

    VCEEnc supports advanced Dolby Vision features for HEVC and AV1 encoding.

    • Copying from input: You can copy the Dolby Vision profile or RPU metadata directly from the input file using the copy keyword.
    • Profiles: Supported profiles include 10.0, 10.1, 10.2, and 10.4 (added in 8.31).
    • RPU Metadata: You can specify an RPU file or use copy to extract it from the input. You can also use --dhdr10-info and --dolby-vision-rpu together.
    • Compatibility: When using --dolby-vision-rpu copy, if the input is Dolby Vision profile 7, it will automatically convert to profile 8 using libdovi.
    --dolby-vision-profile copy
    --dolby-vision-rpu copy
  6. Use VPP (Video Post-Processing) filters

    master

    VCEEnc includes a wide range of Video Post-Processing (VPP) filters for enhancement, upscaling, and correction. Key filters added in recent versions include:

    • Upscaling/Resizing: --vpp-nnedi-upscale, --vpp-resize (supports dpid and area interpolation), and --vpp-rife-ov (arbitrary frame-rate conversion).
    • Denoising/Degraining: --vpp-bm3d, --vpp-degrain, --vpp-hqdn3d, --vpp-rtgmc, and --vpp-knn (supports temporal radius).
    • Sharpening/Detail: --vpp-cas (chroma support), --vpp-msharpen, and --vpp-hqdering.
    • Correction/Cleanup: --vpp-dehaze, --vpp-clahe, --vpp-guidedfilter, --vpp-deblock (supports grid spacing), --vpp-deband, and --vpp-lenscorrection (vignette correction).
    • Specialized: --vpp-anime4k-shader, --vpp-v360 (for 360 video), and --vpp-fft3d.
  7. How GPU selection works in multi-GPU environments

    master

    In environments with multiple VCE/VCN compatible GPUs, VCEEncC automatically selects a GPU based on the following logic:

    1. Compatibility Check: It selects GPUs that support the requested Codec, Profile, and Level. It also checks for support of 10bit depth and HW decoding if those options are specified.
    2. Feature Preference: It prefers GPUs that support B frames.
    3. Utilization Optimization: If multiple GPUs meet the above criteria, it prefers the GPU with the lowest Video Engine (VE) utilization and then the lowest GPU core utilization. This is intended to improve throughput by distributing tasks.

    Manual Selection: Use the --device option to manually specify which GPU to use.

    Note: Utilization checks occur during the initialization phase. If multiple tasks are started simultaneously, they might target the same GPU before the utilization values are updated.

    # Example of manual device selection (exact syntax depends on VCEEncC_Options.en.md)
    # VCEEncC --device <device_id> ...
  8. Use VPP filters for deinterlacing, denoising, and more

    master

    VCEEnc provides a wide range of Video Pre-Processing (VPP) filters. Key categories include:

    • Deinterlacing: --vpp-kfm, --vpp-degrain, --vpp-rtgmc, --vpp-bwdif, --vpp-ivtc.
    • Denoising: --vpp-deblock, --vpp-deflicker, --vpp-dehalo, --vpp-finedehalo, --vpp-hqdering, --vpp-stab, --vpp-hqdn3d, --vpp-msmooth.
    • Other: --vpp-colorfix, --vpp-chromashift, --vpp-vinverse, --vpp-cas, --vpp-descale, --vpp-msharpen, --vpp-maa.
    • Advanced (v9.08): --vpp-anime4k-shader, --vpp-onnx (requires models.json registry).
  9. How GPU automatic selection works in VCEEncC

    master

    In multi-GPU environments, VCEEncC automatically selects the optimal GPU based on your specified options. If you want to bypass automatic selection, use the --device option to specify a GPU manually.

    Selection Logic:

    1. Capability Check: The tool selects GPUs that support the requested codec, profile, level, bit depth (e.g., 10-bit), and hardware decoding (if avhw is specified).
    2. Feature Prioritization: If multiple GPUs are capable, it prioritizes those that support:
      • B-frames (if B-frames are requested).
      • Pre-analysis (if --pa is specified).
    3. Efficiency Check: If multiple GPUs meet the above criteria, it selects the one with the lowest Video Engine (VE) utilization and lowest overall GPU utilization to maximize encoding speed and efficiency.

    Warning: VE/GPU utilization is measured at the start of encoding. Because there is a slight delay in reporting, starting multiple encoding processes almost simultaneously may cause them to be assigned to the same GPU.

  10. VCEEncC Command Line Examples

    master

    VCEEncC provides various command-line patterns for different encoding workflows, including hardware decoding, Avisynth/VapourSynth integration, and piping with FFmpeg.

    Common Workflows

    • Hardware Decoding: Use hardware acceleration for decoding input to speed up the pipeline.
    • Scripting Integration: Supports .avs (Avisynth) and .vpy (VapourSynth) files. These can also be loaded via VFW.
    • Piping:
      • Pipe raw video/audio from FFmpeg into VCEEncC.
      • Pipe both video and audio from FFmpeg.
      • Pipe the filtered output of VCEEncC back into FFmpeg.
    • Stream Copying: Options are available to copy as much audio, subtitles, and metadata as possible from the input file to the output.
  11. Configure ONNX Runtime for VCEEnc Windows builds

    master

    If you need --vpp-onnx support, you must manually prepare the ONNX Runtime DirectML directory. This involves downloading the NuGet package, extracting it, and moving the necessary headers and libraries to a directory defined by the ONNXRUNTIME_DIR environment variable.

    For x64 VCEEncC builds, onnxruntime.dll and onnxruntime_providers_shared.dll are automatically copied from %ONNXRUNTIME_DIR%\lib to the output directory.

    set ONNXRUNTIME_DIR=F:\VisualStudio2022\Projects\onnxruntime
    if not exist "%ONNXRUNTIME_DIR%" mkdir "%ONNXRUNTIME_DIR%"
    if not exist "%ONNXRUNTIME_DIR%\include" mkdir "%ONNXRUNTIME_DIR%\include"
    if not exist "%ONNXRUNTIME_DIR%\lib" mkdir "%ONNXRUNTIME_DIR%\lib"
    
    curl -L -o onnxruntime-directml.nupkg https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime.directml/1.23.0/microsoft.ml.onnxruntime.directml.1.23.0.nupkg
    7z x -oonnxruntime-directml -y onnxruntime-directml.nupkg
    
    xcopy /e /i /y onnxruntime-directml\build\native\include "%ONNXRUNTIME_DIR%\include"
    copy /y onnxruntime-directml\runtimes\win-x64\native\onnxruntime.dll "%ONNXRUNTIME_DIR%\lib\"
    copy /y onnxruntime-directml\runtimes\win-x64\native\onnxruntime.lib "%ONNXRUNTIME_DIR%\lib\"
    copy /y onnxruntime-directml\runtimes\win-x64\native\onnxruntime_providers_shared.dll "%ONNXRUNTIME_DIR%\lib\"
    
    setx ONNXRUNTIME_DIR "%ONNXRUNTIME_DIR%"