[FFmpeg-devel] av_read_frame() question about blocking

Philip Prindeville philipp_subx at redfish-solutions.com
Wed Apr 25 04:46:08 EEST 2018


I was reading the documentation and it wasn’t clear what happens in the following case.

I’ve set up a network connection, and data is being delivered asynchronously to a buffer (a sort of elastic FIFO).

I’ve set up avio_alloc_context() to read from that FIFO.

I’ve done an avformat_open_input() on the context.

So, here’s the question.  I’m in a loop checking to see if the FIFO is empty or not.  If it’s not empty, then I try to do an av_read_frame() on it.  I don’t know if there will be enough data for a complete frame or not, just that there is *some* data in the FIFO.

What happens when there isn’t enough data?  What if data is trickling in and it’s going to take multiple calls to the read_packet function to get a complete frame/packet?

It looks like it’s internally going to keep making multiple calls to the read_packet function until it’s acquired enough.

Is that correct?

And even if the FIFO could tell me how much data it holds, that wouldn’t do any good it seems, because I don’t think av_read_frame() knows how much data it needs until *after* it’s seen it.  Also true?

I ask because I never want to have av_read_frame() (or anything it calls) block.  I have other stuff that needs to happen while enough data is being accumulated to process as a packet-full.

How to accomplish this?



More information about the ffmpeg-devel mailing list