[x264-devel] [PATCH] frame_num increment in non-refererence frames
Loïc Le Loarer
lll+vlc at m4x.org
Fri May 12 18:19:48 CEST 2006
Hi,
x264 is current producing invalid streams when B frames are used because
frame_num are not correctly incremented. According to paragraph 7.4.3,
frame_num must not be equal to PrevRefFrameNum (except in special cases
when fields are used), so the frame_num must be incremented after a
reference picture but not after a non reference picture.
If I and P pictures are reference and B pictures are not reference, the
following order should be seen :
I P B B P B P P B P ...
0 1 2 2 2 3 3 4 5 5 ...
while x264 is producing :
I P B B P B P P B P ...
0 1 1 1 2 2 3 4 4 5 ...
I have made a patch which seems to correct this but I'm not enterely
sure it is really correct as I don't know the code well enough. Can you
take a look at this ?
Best regards.
--
Loïc
"heaven is not a place, it's a feeling"
-------------- next part --------------
Index: encoder/encoder.c
===================================================================
--- encoder/encoder.c (revision 523)
+++ encoder/encoder.c (working copy)
@@ -864,14 +864,14 @@
/* ------------------------ Create slice header ----------------------- */
if( i_nal_type == NAL_SLICE_IDR )
{
- x264_slice_header_init( h, &h->sh, h->sps, h->pps, i_slice_type, h->i_idr_pic_id, h->i_frame_num - 1, i_global_qp );
+ x264_slice_header_init( h, &h->sh, h->sps, h->pps, i_slice_type, h->i_idr_pic_id, h->i_frame_num, i_global_qp );
/* increment id */
h->i_idr_pic_id = ( h->i_idr_pic_id + 1 ) % 65536;
}
else
{
- x264_slice_header_init( h, &h->sh, h->sps, h->pps, i_slice_type, -1, h->i_frame_num - 1, i_global_qp );
+ x264_slice_header_init( h, &h->sh, h->sps, h->pps, i_slice_type, -1, h->i_frame_num, i_global_qp );
/* always set the real higher num of ref frame used */
h->sh.b_num_ref_idx_override = 1;
@@ -1292,12 +1292,12 @@
if( i_slice_type == SLICE_TYPE_B )
x264_macroblock_bipred_init( h );
+ /* ------------------------ Create slice header ----------------------- */
+ x264_slice_init( h, i_nal_type, i_slice_type, i_global_qp );
+
if( h->fenc->b_kept_as_ref )
h->i_frame_num++;
- /* ------------------------ Create slice header ----------------------- */
- x264_slice_init( h, i_nal_type, i_slice_type, i_global_qp );
-
/* ---------------------- Write the bitstream -------------------------- */
/* Init bitstream context */
h->out.i_nal = 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.videolan.org/pipermail/x264-devel/attachments/20060512/8bae0e87/attachment.pgp
More information about the x264-devel
mailing list