Skip to content

efficient way to read complete stream? #682

@allefeld

Description

@allefeld

I'm trying to read a complete audio stream from a video file into a numpy array:

container = av.open(videoFile)
audioStream = container.streams.audio[audioIndex]
audio = []
for frame in container.decode(audioStream):
    audio.append(frame.to_ndarray())
audio = np.hstack(audio)

Is this the correct way, or is it possible to do it in a more efficient way?
I thought about preallocating the numpy array, but audioStream.frames is 0 and audioStream.frames is None.

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