Skip to content

Add YUV420P Support to CudaDeviceInterface in TorchCodec #815

@mrezabayat

Description

@mrezabayat

Currently, CudaDeviceInterface::convertAVFrameToFrameOutput only supports CUDA AVFrames in NV12 format for GPU color conversion using NPP (nppiNV12ToRGB_* functions). If a decoded frame is in planar YUV420P format (e.g., from certain hardware decoders or non-8-bit content), the function raises an error due to the AV_PIX_FMT_NV12 check.

This limitation prevents GPU-accelerated color conversion for common formats like YUV420P, even though CUDA/NPP supports planar formats through functions like nppiYUV420ToRGB_*.

Proposed Change:

Extend convertAVFrameToFrameOutput to detect and handle AV_PIX_FMT_YUV420P in addition to NV12.

Implement the YUV420P → RGB conversion path using NPP (nppiYUV420ToRGB_8u_P3C3R_Ctx or _709CSC variants for BT.709).

Maintain the same caching logic for NppStreamContext and memory handling as in the NV12 path.

Benefits:

Broader format support for CUDA-based decoding pipelines.

Reduced need to fall back to CPU for planar YUV420P → RGB conversion, improving performance.

Improved interoperability with decoders that output YUV420P by default.

Motivation, pitch

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions