[Libav-user] flushing internal buffers using custom I/O

Selmeci, Tamás tselmeci at open-st.eu
Fri Apr 10 15:31:41 CEST 2015

On Fri, 2015-04-10 at 14:06 +0200, Selmeci, Tamás wrote:
> What I need is to avoid
> getting incomplete frames from the demultiplexer - how can I flush/reset
> the demultiplexer itself without reopening the stream?

Well, now I've got something which shows pretty good signs doing that I
exactly want (not tested too much yet).

- the remaining number of bytes of the old MPEG-TS is known. This is the
amount that haven't yet been consumed by the custom I/O callback
- I keep on executing av_frame_read(...) (and drop the frames) until
this amount falls to 0;
- at this point there are still a lot of bytes in ffmpeg's caches, that
form incomplete frame(s);
- I keep on executing av_frame_read(...) until the returned frame's size
== 0 and stream_index == 0. This also generates callbacks on custom I/O
callback, the custom I/O callback function memsets the buffer to 0
(returns with fake data);
- the new MPEG-TS is being fed;

This appears to flush the internal caches.

Selmeci Tamás

More information about the Libav-user mailing list