A recent change has caused the initial dts in h264 streams returned by av_read_frame to be incorrect. The commit was r20599. The root cause of the problem comes from moving the assignment of s->avctx->pix_fmt from h264.c:decode_init() to decode_slice_header(). This movement has the side effect of making has_codec_parameters() in libavformat/utils.c fail during av_find_stream_info(). This causes try_decode_frame() to be called which ultimately sets st->codec->has_b_frames = 2. This the causes compute_pkt_fields() in libavformat/utils.c to start buffering up multiple pts values in st->pts_buffer. All this happens during the initial call to av_find_stream_info. Then later, when the application calls av_read_frame, the pts values that were buffered during the previous av_find_stream_info are used to set the dts value of the returned packet. This is especially obnoxious when the reader does a seek before av_read_frame. The reason this worked prior to r20599 is that st->codec->has_b_frames would only be set to 0 during av_find_stream_info, so only the first entry of st->pts_buffer would ever be filled in. And this first entry is always replaced on the next iteration.
On Sun, Dec 06, 2009 at 03:26:30PM -0800, John Stebbins wrote:
A recent change has caused the initial dts in h264 streams returned by av_read_frame to be incorrect. The commit was r20599. The root cause of the problem comes from moving the assignment of s->avctx->pix_fmt from h264.c:decode_init() to decode_slice_header(). This movement has the side effect of making has_codec_parameters() in libavformat/utils.c fail during av_find_stream_info(). This causes try_decode_frame() to be called which ultimately sets st->codec->has_b_frames = 2. This the causes compute_pkt_fields() in libavformat/utils.c to start buffering up multiple pts values in st->pts_buffer. All this happens during the initial call to av_find_stream_info. Then later, when the application calls av_read_frame, the pts values that were buffered during the previous av_find_stream_info are used to set the dts value of the returned packet.
This is especially obnoxious when the reader does a seek before av_read_frame.
send a patch that resets pts_buffer in av_read_frame_flush() (assuming its tested & works of course) There may be further bugfixes needed but this one seems obviously missing [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Breaking DRM is a little like attempting to break through a door even though the window is wide open and the only thing in the house is a bunch of things you dont want and which you would get tomorrow for free anyway
On 12/06/2009 07:15 PM, Michael Niedermayer wrote:
On Sun, Dec 06, 2009 at 03:26:30PM -0800, John Stebbins wrote:
A recent change has caused the initial dts in h264 streams returned by av_read_frame to be incorrect. The commit was r20599.
This is especially obnoxious when the reader does a seek before av_read_frame.
send a patch that resets pts_buffer in av_read_frame_flush() (assuming its tested& works of course)
There may be further bugfixes needed but this one seems obviously missing
I thought that something should be resetting pts_buffers, but didn't know where that should be done. So thanks for the pointer. I think that av_read_frame_flush should also be called from av_find_stream_info since pts_buffer is modified during this function. My patch does this. I did some testing, and this patch fixes the problem I saw. But as you noted, there seems to be more bugs. I'm now seeing the dts start out ok. But it looks like st->codec->has_b_frames starts out at 2, changes to 0 on the second packet, then changes to 2 again a bit later. When it changes back to 2, dts once again gets the wrong value for a sequence of several packets. It appears that the change in delay screws up the ordering in pts_buffers.
On 12/06/2009 10:30 PM, John Stebbins wrote:
... as you noted, there seems to be more bugs. I'm now seeing the dts start out ok. But it looks like st->codec->has_b_frames starts out at 2, changes to 0 on the second packet, then changes to 2 again a bit later. When it changes back to 2, dts once again gets the wrong value for a sequence of several packets. It appears that the change in delay screws up the ordering in pts_buffers.
This was a brainfart. After I stepped away from the code for a few minutes, I realized I had been looking at 2 different streams. The dts being returned for the video stream looks as it should.
On Sun, Dec 06, 2009 at 10:30:29PM -0800, John Stebbins wrote:
On 12/06/2009 07:15 PM, Michael Niedermayer wrote:
On Sun, Dec 06, 2009 at 03:26:30PM -0800, John Stebbins wrote:
A recent change has caused the initial dts in h264 streams returned by av_read_frame to be incorrect. The commit was r20599.
This is especially obnoxious when the reader does a seek before av_read_frame.
send a patch that resets pts_buffer in av_read_frame_flush() (assuming its tested& works of course)
There may be further bugfixes needed but this one seems obviously missing
I thought that something should be resetting pts_buffers, but didn't know where that should be done. So thanks for the pointer. I think that av_read_frame_flush should also be called from av_find_stream_info since pts_buffer is modified during this function. My patch does this.
I did some testing, and this patch fixes the problem I saw. But as you noted, there seems to be more bugs. I'm now seeing the dts start out ok. But it looks like st->codec->has_b_frames starts out at 2, changes to 0 on the second packet, then changes to 2 again a bit later. When it changes back to 2, dts once again gets the wrong value for a sequence of several packets. It appears that the change in delay screws up the ordering in pts_buffers.
utils.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) f01ca2d0a99d9a66c38ed549c0e32a09118f4b56 initial_dts.diff Index: libavformat/utils.c =================================================================== --- libavformat/utils.c (revision 20757) +++ libavformat/utils.c (working copy) @@ -1177,7 +1177,7 @@ void av_read_frame_flush(AVFormatContext *s) { AVStream *st; - int i; + int i, j;
flush_packet_queue(s);
@@ -1200,6 +1200,9 @@ st->cur_len = 0;
st->probe_packets = MAX_PROBE_PACKETS; + + for(j=0; j<MAX_REORDER_DELAY+1; j++) + st->pts_buffer[j]= AV_NOPTS_VALUE; } }
2 hunks above ok (if tested), (and maybe with FF_ARRAY_ELEMS()) remaining hunk looks wrong [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I hate to see young programmers poisoned by the kind of thinking Ulrich Drepper puts forward since it is simply too narrow -- Roman Shaposhnik
Hi! Michael Niedermayer <michaelni <at> gmx.at> writes:
--- libavformat/utils.c (revision 20757) +++ libavformat/utils.c (working copy) @@ -1177,7 +1177,7 @@ void av_read_frame_flush(AVFormatContext *s) { AVStream *st; - int i; + int i, j;
flush_packet_queue(s);
@@ -1200,6 +1200,9 @@ st->cur_len = 0;
st->probe_packets = MAX_PROBE_PACKETS; + + for(j=0; j<MAX_REORDER_DELAY+1; j++) + st->pts_buffer[j]= AV_NOPTS_VALUE; } }
2 hunks above ok (if tested), (and maybe with FF_ARRAY_ELEMS())
I believe you over-estimate the number of people on this list who are a) able to understand what they should test before applying this and b) apply other people's patches at all. I will happily apply both hunks if you want (and I think we will find out soon if they do any harm), but I have no idea what to test. Carl Eugen PS: Could you look at the regression issue 1550 (sample in incoming/issue1550)? And could one of the H264 experts look at issue 1585? I suspect an important issue, but maybe it is just a broken sample.
On Wed, Dec 09, 2009 at 12:07:54AM +0000, Carl Eugen Hoyos wrote:
Hi!
Michael Niedermayer <michaelni <at> gmx.at> writes:
--- libavformat/utils.c (revision 20757) +++ libavformat/utils.c (working copy) @@ -1177,7 +1177,7 @@ void av_read_frame_flush(AVFormatContext *s) { AVStream *st; - int i; + int i, j;
flush_packet_queue(s);
@@ -1200,6 +1200,9 @@ st->cur_len = 0;
st->probe_packets = MAX_PROBE_PACKETS; + + for(j=0; j<MAX_REORDER_DELAY+1; j++) + st->pts_buffer[j]= AV_NOPTS_VALUE; } }
2 hunks above ok (if tested), (and maybe with FF_ARRAY_ELEMS())
I believe you over-estimate the number of people on this list who are a) able to understand what they should test before applying this and
regression tests & timestamps after seeking h264
b) apply other people's patches at all.
I will happily apply both hunks if you want (and I think we will find out soon if they do any harm), but I have no idea what to test.
Carl Eugen
PS: Could you look at the regression issue 1550 (sample in incoming/issue1550)? And could one of the H264 experts look at issue 1585? I suspect an important issue, but maybe it is just a broken sample.
ill try to look at 1550 [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I do not agree with what you have to say, but I'll defend to the death your right to say it. -- Voltaire
Michael Niedermayer <michaelni <at> gmx.at> writes:
2 hunks above ok (if tested), (and maybe with FF_ARRAY_ELEMS())
I believe you over-estimate the number of people on this list who are a) able to understand what they should test before applying this and
regression tests & timestamps after seeking h264
Applied after running regression tests and seek_test on a h264 file. [...]
PS: Could you look at the regression issue 1550 (sample in incoming/issue1550)? And could one of the H264 experts look at issue 1585? I suspect an important issue, but maybe it is just a broken sample.
ill try to look at 1550
Thank you for the very fast fix! Carl Eugen
participants (4)
-
cehoyos@ag.or.at -
jstebbins@jetheaddev.com -
michaelni@gmx.at -
stebbins@jetheaddev.com