Skip to content

HDR (10-bit) frames cannot be converted to images correctly since av==16.0.0. #2192

@nagadomi

Description

@nagadomi

Since 16.0.0, frame data cannot be converted to images correctly with code like the following.

import av
import numpy as np
from PIL import Image


input_file = "tmp/test_videos/Hybrid HDR10 with Dolby Vision Sample.mkv" # from https://kodi.wiki/view/Samples
output_file = f"{av.__version__}_out.png"
skip_frame = 10


with av.open(input_file, mode="r") as container:
    for packet in container.demux(video=0):
        for frame in packet.decode():
            skip_frame -= 1
            if skip_frame <= 0:
                frame = frame.to_ndarray(format="rgb48le")
                frame_float = frame / 65535.0
                # Save as 8-bit for debugging.
                frame_uint8 = np.clip(frame_float * 255.0, 0, 255).astype(np.uint8)
                image = Image.fromarray(frame_uint8)
                image.save(output_file)
                print("save", output_file)
                break
        if skip_frame <= 0:
            break

15.1.0
Image
16.0.0 and 16.1.0
Image

If the issue is related to the reformat or to_ndarray, it may already be fixed in the latest code, but I have not tested it.

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