spdl.io.create_reference_video_frame

create_reference_video_frame(array: UintArray, pix_fmt: str, frame_rate: tuple[int, int], pts: int) VideoFrames[source]

Create an VideoFrame object which refers to the given array/tensor.

This function should be used when the media data processed in Python should be further processed by filter graph, and/or encoded.

Note

The resulting frame object references the memory region owned by the input array and keeps a reference to the original array to prevent it from being garbage collected. The original data will remain alive as long as the frame object is alive.

Parameters:
  • array – 3D or 4D array or tensor. The dtype and channel layout must match what is provided to sample_fmt.

  • pix_fmt

    The image format. The valid values and corresponding shape is as follow.

    • "rgb24", "bgr24": Interleaved RGB/BGR in shape of (N, H, W, C==3).

    • "gray8", "gray16": Grayscale image of 8bit unsigned integer or 16 bit signed integer in shape of (N, H, W).

    • "yuv444p": Planar YUV format in shape of (N, C==3, H, W).

  • frame_rate – The frame rate of the video expressed asfraction. (numerator, denominator).

  • pts – The time of the first video frame, in the discrete time unit of frame rate. Usually it is the number of frames previously processed.

Returns:

Frames object that references the memory region of the input data.