Skip to content

10 bit colors to numpy #1713

@johan-sightic

Description

@johan-sightic

Hi!
I'm reading frames from a mp4 HEVC video in yuv422p10le format, i.e. 10bit color depth, to numpy.
I get a ndarray with dtype uint16 which I expected but I thought there would only be at most 2^10=1024 different unique values in the frame, but I get about 60000 different values. Is this expected? What am I missing?
This is my code:

import av
import numpy as np

# Read hevc video in yuv422p10le format
with av.open("video.mp4") as container:
    frame = next(container.decode(video=0))
    np_frame = frame.to_ndarray(format="rgb48")
    print(container.streams.video[0].pix_fmt)  # >>> yuv422p10le
    print(np_frame.dtype)  # >>> uint16
    print(np.unique(np_frame))  # >>> [    0     1     2 ... 65498 65527 65535]
    print(len(np.unique(np_frame)))  # >>> 58702 (expected <= 1024 differnte values for yuv422p10le)

Thanks!

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