beetbox / audioread

cross-library (GStreamer + Core Audio + MAD + FFmpeg) audio decoding for Python
MIT License
481 stars 108 forks source link

ffdec hangs on wait #130

Closed mightbecharles closed 1 year ago

mightbecharles commented 1 year ago

I am using Librosa-0.9.2 on a project and encountered this issue with audioread-3.0.0.

Librosa calls available_backends(), which calls ffdec.available()

available() seems to hang indefinitely. But changing proc.wait() to proc.communicate() seems to fix the issue for my use case.

I saw in #113 that communicate() wasn't ideal, so maybe there's something else worth looking into?

sampsyo commented 1 year ago

Ah, this is a really good catch. While communicate() would be a problem for reading the actual output data from a "proper" invocation of ffmpeg, it actually seems like exactly the right thing for the ffdec.available() case.

In short, the problem with wait(), as currently written, is that the subprocess may fill up its output buffers—at which point it hangs, waiting for us (audioread) to consume something from those pipes. We're waiting for the ffmpeg process to exit, so that's a classic deadlock scenario.

I think we should use your change! Any chance you could submit a very small PR to this effect?

mightbecharles commented 1 year ago

@sampsyo Thanks, let me know if there are any problems!