[FFmpeg-devel] Reading Frames in File Order
modmaker at google.com
Thu Jul 20 21:35:19 EEST 2017
I am writing a program that will use libavformat to demux media
segments. I will need to parse media segments that may appear in any
order and produce playable regions of content. For example, think
YouTube streaming; there are regions of buffered content and seeking
can produce media segments that are out of order.
I need to have libavformat give me the frames in the order they are
given to it. If I append a segment in the past, I expect to get
those frames next. It is fine if the frames given to me are entirely
out of order, I can handle it.
I am implementing this by creating a custom AVIOContext that reads
from an internal buffer. Since we can't parse the media segments, we
will just give the data to libavformat in the order we get it. This
context doesn't support seeking.
Currently, if I append a segment in the past, I get a few errors. I
have a trivial patch to fix a bug that causes problems. This would
not change any behavior, just fix a bug in the reordering frame logic.
The bigger problem is that av_read_frame reads frames in DTS order.
So since the libavforat "playhead time" is in the future, I won't ever
see the frames. If I try to seek, I get errors since my AVIOContext
doesn't support seeking.
What I want is a way to have av_read_frame (or a new method) return
the frames in the order they appear in the (virtual) file.
I would be happy to implement this feature. I wanted to get the
developer's opinions about whether this would be allowed and how
best to implement it (i.e. a new flag somewhere or a new method
similar to av_read_frame).
More information about the ffmpeg-devel