[FFmpeg-devel] Bink demuxer/av_add_index_entry

Daniel Verkamp daniel
Fri Dec 19 08:18:16 CET 2008


I've been working recently on Bink demuxing and audio decoding, based
on an updated patch from Peter Ross (original thread is at

I notice that at
it is recommended to use av_add_index_entry, but I am unsure how this
should work exactly; the doxygen is fairly sparse...

Some background: the Bink file format has an index right after the
header with one entry per frame giving the offset into the file where
that frame starts. Each frame contains audio data (if any) followed by
video data.  The audio data in each frame begins with a field giving
the size of that data, after which starts the video, so it is not
possible to know where the video for a given frame starts until
reading the beginning of that frame.

So the questions:

- Should av_add_index_entry be called only for the first audio stream
(or if there is no audio, for the video stream)?

- What should size be? Size of the audio data if calling this on the
audio stream (not known until reading each frame)?  Size of the whole
audio/video frame data (knowable at index reading time by looking at
the next index entry)? 0?  The most useful would be size of the whole
frame data (size of video data = size of whole frame - size of audio),
but this seems counterintuitive since this does not really apply to
the single audio stream.

- What timestamp should be used? For video, the demuxer is using a
time base where the frame number is the PTS, but I am not certain how
this should work for audio.  Assuming I want to look up the size of
the whole frame in read_packet, the simplest would be to look it up by
frame number.

- How does the demuxer look up/use these index entries later (in the
demuxer's read_packet)?

- What is the keyframe flag used for, demuxer internal use only?  Bink
video doesn't seem to have any such thing as a key frame at first
glance (only the very first frame), and audio is windowed with the
previous frame.

- Same for distance, what is it used for? Can it just be set to 0
(some demuxers seem to do this)?

Sorry for all the questions; I've attempted to answer them myself by
looking at the current callers for av_add_index_entry, but none of
them seemed particularly enlightening.

-- Daniel Verkamp

More information about the ffmpeg-devel mailing list