spdl.io.create_reference_audio_frame

create_reference_audio_frame(array: UintArray, sample_fmt: str, sample_rate: int, pts: int) AudioFrames[source]

Create an AudioFrame 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 – 2D array or tensor. The dtype and channel layout must match what is provided to sample_fmt.

  • sample_fmt

    The format of sample. The valid values and corresponding data type is as follow.

    • "u8", "u8p" : 8-bit unsigned integer.

    • "s16", "s16p" : 16-bit signed integer.

    • "s32", "s32p" : 32-bit signed integer.

    • "s64", "s64p" : 64-bit signed integer.

    • "flt", "fltp" : 32-bit floating-point.

    • "dbl", "dblp" : 64-bit floating-point.

    The suffix "p" means planar format (channel-first), the input array is interpreted as (num_channels, num_frames). Otherwise it is interpreted as packed format (channel-last), i.e. (num_frames, num_channels).

  • sample_rate – The sample rate of the audio

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

Returns:

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