Skip to content

VideoFrame color properties are lost when HWAccel(is_hw_owned=False) #2231

@nagadomi

Description

@nagadomi

When HWAccel(is_hw_owned=False) is used, all color properties such as colorspace become UNSPECIFIED (2 or 0).

import av
from av.codec.hwaccel import HWAccel
from av.datasets import fate as fate_suite


def print_frame_color_props(file_path, hwaccel):
    if hwaccel is None:
        s = "hwaccel=None"
    else:
        s = f"hwaccel=HWAccel(is_hw_owned={hwaccel.is_hw_owned})"
    print(f"* {s}")

    with av.open(file_path, mode="r", hwaccel=hwaccel) as container:
        for frame in container.decode(video=0):
            print(
                "  "
                f"colorspace={frame.colorspace}, "
                f"color_primaries={frame.color_primaries}, "
                f"color_trc={frame.color_trc}, "
                f"color_range={frame.color_range}"
            )
            return


file_path = fate_suite("hevc/hdr10_plus_h265_sample.hevc")
print_frame_color_props(file_path, hwaccel=None)
print_frame_color_props(
    file_path,
    hwaccel=HWAccel(
        device_type="cuda", is_hw_owned=True, allow_software_fallback=False
    ),
)
print_frame_color_props(
    file_path,
    hwaccel=HWAccel(
        device_type="cuda", is_hw_owned=False, allow_software_fallback=False
    ),
)
* hwaccel=None
  colorspace=9, color_primaries=9, color_trc=16, color_range=1
* hwaccel=HWAccel(is_hw_owned=True)
  colorspace=9, color_primaries=9, color_trc=16, color_range=1
* hwaccel=HWAccel(is_hw_owned=False)
  colorspace=2, color_primaries=2, color_trc=2, color_range=0

The exact conditions are unclear, but this may also be related to #2230.

EDIT: For now, I am considering restoring it from stream.colorspace and similar fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions