D Richard Felker III
2003-12-20 11:34:10 UTC
I'm working on mplayer g2, and trying to work out the horrible
nightmare of pts with B-frames in avi files. From what I can gather,
B-frames in avi files seem to be stored in codec order, meaning that
their frame numbers within the avi file do _not_ represent their
display order. This is very troubling, since it makes it nearly
impossible to get a correct timestamp after seeking!
So far, I've only come across one way to accurately determine frame
numbers in display order: the display-order frame number of a
reference frame (I/P) is the coded-order frame number of the next
reference frame, minus 1. However, I'm concerned that there's no way
to see where the next reference frame is before lavc decodes the
current one.
There's a related problem with B-frames in MPlayer, the notorious
glitch-after-seeking bug. In case you're not familiar with it, MPlayer
will show a bogus blocky mix of the scene before the seek and the new
scene after the seek for a few frames after seeking, when playing
files with B-frames. I'll explain the cause:
Suppose after seeking, the next 4 frames (coded order) are IBBP. The
two B-frames actually belong before the I-frame, and should not be
shown after seeking. But the decoder (lavc or libmpeg2) has no way of
knowing this, and thinks the two B-frames belong between the pre-seek
reference frame and the new I-frame. Thus, broken output.
The only real fix I can think of for this problem, is to provide a
method for the caller to notify lavc that a seek has taken place, and
to "flush the buffers". After such a notification, all B-frames should
be dropped until the second reference frame is found.
If in addition to this, the first reference frame after the seek (the
I-frame) is not decoded until the second reference frame is found,
then it becomes possible to obtain an accurate frame number in avi
files! The (display-order) frame number of the I-frame you seek to is
exactly the (coded-order) frame number of the frame that causes it to
be decoded, minus 1.
Could someone who understands these issues comment? Maybe other
methods of dealing with these problems are already known and I'm just
ignorant. Feel free to flame if that's the case. :)
Rich
P.S. Maybe what I just said can be emulated with hurry_up flag and
wrappers...?
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
nightmare of pts with B-frames in avi files. From what I can gather,
B-frames in avi files seem to be stored in codec order, meaning that
their frame numbers within the avi file do _not_ represent their
display order. This is very troubling, since it makes it nearly
impossible to get a correct timestamp after seeking!
So far, I've only come across one way to accurately determine frame
numbers in display order: the display-order frame number of a
reference frame (I/P) is the coded-order frame number of the next
reference frame, minus 1. However, I'm concerned that there's no way
to see where the next reference frame is before lavc decodes the
current one.
There's a related problem with B-frames in MPlayer, the notorious
glitch-after-seeking bug. In case you're not familiar with it, MPlayer
will show a bogus blocky mix of the scene before the seek and the new
scene after the seek for a few frames after seeking, when playing
files with B-frames. I'll explain the cause:
Suppose after seeking, the next 4 frames (coded order) are IBBP. The
two B-frames actually belong before the I-frame, and should not be
shown after seeking. But the decoder (lavc or libmpeg2) has no way of
knowing this, and thinks the two B-frames belong between the pre-seek
reference frame and the new I-frame. Thus, broken output.
The only real fix I can think of for this problem, is to provide a
method for the caller to notify lavc that a seek has taken place, and
to "flush the buffers". After such a notification, all B-frames should
be dropped until the second reference frame is found.
If in addition to this, the first reference frame after the seek (the
I-frame) is not decoded until the second reference frame is found,
then it becomes possible to obtain an accurate frame number in avi
files! The (display-order) frame number of the I-frame you seek to is
exactly the (coded-order) frame number of the frame that causes it to
be decoded, minus 1.
Could someone who understands these issues comment? Maybe other
methods of dealing with these problems are already known and I'm just
ignorant. Feel free to flame if that's the case. :)
Rich
P.S. Maybe what I just said can be emulated with hurry_up flag and
wrappers...?
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click