PyAV icon indicating copy to clipboard operation
PyAV copied to clipboard

Not all frames read or crash when processing a webm file

Open laggykiller opened this issue 5 months ago • 8 comments

Overview

I am trying to process the following file:

026.webm

The webm file should contain 152 frames, however pyav can only read 23 frames:

import av
from av.codec.context import CodecContext

in_f = '026.webm'
frames = []

context = CodecContext.create('libvpx-vp9', 'r')

with av.open(in_f) as container:
    for packet in container.demux(video=0):
        for frame in context.decode(packet):
            frames.append(frame)

print(len(frames))

Moreover, the following code cause crash:

import av
from av.codec.context import CodecContext

in_f = '026.webm'
frames = []

with av.open(in_f) as container:
    context = container.streams.video[0].codec_context # Crash here

The following code also cause crash:

import av
from av.codec.context import CodecContext

in_f = '026.webm'
frames = []

context = CodecContext.create('libvpx-vp9', 'r')

with av.open(in_f) as container:
    for packet in container.demux(video=0):
        for frame in context.decode(packet):
            frame_nd = frame.to_ndarray(format='rgba') # Crash here
            frames.append(frame_nd)

The crash message on Linux:

malloc(): corrupted top size
Aborted (core dumped)

Note that the problem of not reading all frames is present on Windows, MacOS (arm64) and Arch Linux. The crash occurs on Windows and Arch Linux only, the crash does not occur on macOS arm64.

Using ffmpeg on command line is able to demux and convert the webm file normally.

Expected behavior

All frames of webm file successfully are read without crash

Actual behavior

Not all frames of webm file are successfully read or/and crash

Versions

Tested on Windows, MacOS arm64 Sonoma, Arch Linux.

Both av and pyav (Contains newer version of pyav) wheels from pypi were tested

Research

I have done the following:

laggykiller avatar Jan 30 '24 19:01 laggykiller