[FFmpeg-devel] [BUG] h264 picture reordering fails

Haruhiko Yamagata h.yamagata
Mon Jun 8 14:15:01 CEST 2009

 >On Sat, May 30, 2009 at 07:34:32PM +0900, Haruhiko Yamagata wrote:
>> I found picture reordering fails in
>> http://x264.nl/h.264.samples/premiere-paff.ts
>> Outputted pictures have POC {-4, -2, 4, 0, 2, 6}.
>> Are negative POCs allowed?
>> If yes, zero as POC is valid as well.
>> But, in h264.c decode_frame,
>>            for(i=1; h->delayed_pic[i] && (h->delayed_pic[i]->poc && 
>> !h->delayed_pic[i]->key_frame); i++)
>> This code assume poc zero is special. The case above is not supported.
>> If I comment out /* h->delayed_pic[i]->poc && */, then it works for the 
>> sample.
>> This is just a bug report, but if you give me a hint, I'm willing to work 
>> on this.
>is has_b_frames set to the correct value?
>about POCs, IIRC the spec requires POC=0 to be true and only true for
>IDR pictures, but i might misremember (would have to check the spec)
>What i do know is that the POC or frame number == 0 rules in the spec
>are not followed by some encoders.
A new patch attached.
In flush_dpb, I set a big number in prev_poc_msb.

We want to avoid POC=0 unless it is a real IDR.
For that purpose, we have to avoid negative POC unless it is a B-frame that reference an IDR frame.

>        if     (h->poc_lsb < h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb/2)
>            h->poc_msb = h->prev_poc_msb + max_poc_lsb;
>        else if(h->poc_lsb > h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb/2)
>            h->poc_msb = h->prev_poc_msb - max_poc_lsb;
>        else
>            h->poc_msb = h->prev_poc_msb;

In the code above (init_poc), just after seeking to a GDR frame, second case may be true and poc_msb
will be unintentionally negative if prev_poc_msb is 0.

So my intention is to avoid negative POC unless we get a real IDR
If the entry point is a GDR, poc_msb is unknown. In flush_dpb, sps.log2_max_poc_lsb is 
also unknown. So I just set a number that is big enough. Please review.

Best regards,
Haruhiko Yamagata
-------------- next part --------------
A non-text attachment was scrubbed...
Name: set_prev_poc_msb_a_big_number_on_flush_dpb.patch
Type: application/octet-stream
Size: 432 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090608/0aea69d3/attachment.obj>

More information about the ffmpeg-devel mailing list