You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
frame.to_ndarray(format='rgba') can cause a crash #1269
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
None of my media players would play anything beyond 23 frames. I even tried playing 026.webm using ffplay from the latest commit in master (9949c1dd78) and it still only played 23 frames.
Since PyAV uses ffmpeg as its source of truth, iterating over 23 frames is the correct behavior.
I can verify those crashes on Windows, but since it appears that ffmpeg library is crashing, rather than PyAV itself, I don't think there is anything we can do.
That command, ffmpeg -i 026.webm frames/%03d.png is implemented I believe in ffmpeg.c which is separate from the library (libavcodec, libavformat, etc). That means that ffmpeg commands are not really comparable with PyAV.
When I ran that command, I did get 152 frames, however, each of those frames are repeated 5-8 times. When I run the equivalent for PyAV, it only makes the 23 unique frames. I believe that PyAV has the correct behavior here.
If ffmpeg 5.1 or ffmpeg 6.0 cli crash when running on this input, then there is certainly nothing PyAV can do, at least until PyAV drops support for ffmpeg 5.x.
If the cli or better yet, a C program demonstrate that it can do the equivalent without crashing, then there may be something PyAV can do, although answering what will be difficult.
Got it. Should we report the crash in Windows and Linux to ffmpeg? I am not sure how to report though as the problem is within the library, not the command itself.
After some testing, I think the crash in second case occurs in this line in av/video/frame.pyx. It calls useful_array, and crash at this line. The reshape(-1) had caused the crash. I think this mean the reformat() in this line is not returning correct rgba array back, and the crash is NOT occuring in ffmpeg. Would adding support for yuva420p solve the problem?
I am currently experiencing the same problem. A crash occurs while translating yuva to rgba. The first frame is converted without a problem, but it crashes immediately on the next frame. State management issue in codec context?
To pinpoint the error, it's reformatting YUVA420P format to RGBA frames, then one frame of that reformat gets garbage collected, and then the next YUVA420P reformat back to RGBA frames crashes. In other words, it seems that the YUVA420P to RGBA converted frames are not being freed properly (or duplicate freed). I'm not sure if this is exactly the same issue.
Below is the code to reproduce this.
from av import VideoFrame
import gc
frame = VideoFrame(width=642, height=640, format="yuva420p")
a = frame.reformat(format="rgba")
del a
gc.collect()
a = frame.reformat(format="rgba") # crashed
This problem does not occur when the width of the VideoFrame is divided by 16.
from av import VideoFrame
import gc
frame = VideoFrame(width=656, height=640, format="yuva420p")
a = frame.reformat(format="rgba")
del a
gc.collect()
a = frame.reformat(format="rgba") # not crashed
I don't have any knowledge of video encoding and decoding, so I can't fix this, but I've tried to reproduce the error in more detail because I'd like to see this resolved.
After playing around with different build environments, I found that the issue occurs when SSSE3 is enabled (building with the --disable-ssse3 option does not cause this issue).
changed the title [-]Not all frames read or crash when processing a webm file[/-][+]`frame.to_ndarray(format='rgba')` can cause a crash[/+]on Jul 25, 2024
Activity
[-]The FOO does not BAR.[/-][+]Not all frames read or crash when processing a webm file[/+]WyattBlue commentedon Jan 30, 2024
None of my media players would play anything beyond 23 frames. I even tried playing 026.webm using ffplay from the latest commit in master (9949c1dd78) and it still only played 23 frames.
Since PyAV uses ffmpeg as its source of truth, iterating over 23 frames is the correct behavior.
I can verify those crashes on Windows, but since it appears that ffmpeg library is crashing, rather than PyAV itself, I don't think there is anything we can do.
laggykiller commentedon Jan 31, 2024
Actually I counted the number of frames by
ffmpeg -i 026.webm frames/%03d.pngand it shows 152 frames.I checked again using
ffmpeg -i 026.webm test.webmand it shows 23 frames.The code I given should iterate all frames, including non-keyframes, right?
But it does not crash if I invoke ffmpeg from command line, so could this mean a problem with how pyav is binding to ffmpeg?
WyattBlue commentedon Jan 31, 2024
That command,
ffmpeg -i 026.webm frames/%03d.pngis implemented I believe in ffmpeg.c which is separate from the library (libavcodec, libavformat, etc). That means that ffmpeg commands are not really comparable with PyAV.When I ran that command, I did get 152 frames, however, each of those frames are repeated 5-8 times. When I run the equivalent for PyAV, it only makes the 23 unique frames. I believe that PyAV has the correct behavior here.
If ffmpeg 5.1 or ffmpeg 6.0 cli crash when running on this input, then there is certainly nothing PyAV can do, at least until PyAV drops support for ffmpeg 5.x.
If the cli or better yet, a C program demonstrate that it can do the equivalent without crashing, then there may be something PyAV can do, although answering what will be difficult.
laggykiller commentedon Jan 31, 2024
Got it. Should we report the crash in Windows and Linux to ffmpeg? I am not sure how to report though as the problem is within the library, not the command itself.
laggykiller commentedon Jan 31, 2024
I end up with this working code:
Reference: https://stackoverflow.com/questions/72308308/converting-yuv-to-rgb-in-python-coefficients-work-with-array-dont-work-with-n
After some testing, I think the crash in second case occurs in this line in
av/video/frame.pyx. It callsuseful_array, and crash at this line. Thereshape(-1)had caused the crash. I think this mean thereformat()in this line is not returning correct rgba array back, and the crash is NOT occuring in ffmpeg. Would adding support foryuva420psolve the problem?caffeinism commentedon Feb 1, 2024
I am currently experiencing the same problem. A crash occurs while translating yuva to rgba. The first frame is converted without a problem, but it crashes immediately on the next frame. State management issue in codec context?
caffeinism commentedon Feb 4, 2024
To pinpoint the error, it's reformatting YUVA420P format to RGBA frames, then one frame of that reformat gets garbage collected, and then the next YUVA420P reformat back to RGBA frames crashes. In other words, it seems that the YUVA420P to RGBA converted frames are not being freed properly (or duplicate freed). I'm not sure if this is exactly the same issue.
Below is the code to reproduce this.
This problem does not occur when the width of the VideoFrame is divided by 16.
I don't have any knowledge of video encoding and decoding, so I can't fix this, but I've tried to reproduce the error in more detail because I'd like to see this resolved.
caffeinism commentedon Feb 5, 2024
After playing around with different build environments, I found that the issue occurs when SSSE3 is enabled (building with the --disable-ssse3 option does not cause this issue).
I googled it and found the following issues.
https://trac.ffmpeg.org/ticket/9254
If this issue is not directly reflected in FFMPEG, it seems that the only way to avoid the error is to add appropriate padding.
[-]Not all frames read or crash when processing a webm file[/-][+]`frame.to_ndarray(format='rgba')` can cause a crash[/+]