Use dec_ref_pic_marking SEIs to repeat B-ref referencing information.
Don't allow B-frames to reference frames outside their minigop.
SEI_USER_DATA_REGISTERED = 4,
SEI_USER_DATA_UNREGISTERED = 5,
SEI_RECOVERY_POINT = 6,
+ SEI_DEC_REF_PIC_MARKING = 7,
SEI_FRAME_PACKING = 45,
};
/* Slice header */
x264_slice_header_t sh;
+ /* Slice header backup, for SEI_DEC_REF_PIC_MARKING */
+ int b_sh_backup;
+ x264_slice_header_t sh_backup;
+
/* cabac context */
x264_cabac_t cabac;
h->i_ref[0] = X264_MIN( h->i_ref[0], h->frames.i_max_ref0 );
h->i_ref[0] = X264_MIN( h->i_ref[0], h->param.i_frame_reference ); // if reconfig() has lowered the limit
+ /* For Blu-ray compliance, don't reference frames outside of the minigop. */
+ if( IS_X264_TYPE_B( h->fenc->i_type ) && h->param.b_bluray_compat )
+ h->i_ref[0] = X264_MIN( h->i_ref[0], IS_X264_TYPE_B( h->fref[0][0]->i_type ) + 1 );
+
/* add duplicates */
if( h->fenc->i_type == X264_TYPE_P )
{
}
}
+ if( h->fenc->i_type == X264_TYPE_BREF && h->param.b_bluray_compat && h->sh.i_mmco_command_count )
+ {
+ h->b_sh_backup = 1;
+ h->sh_backup = h->sh;
+ }
+
h->fdec->i_frame_num = h->sh.i_frame_num;
if( h->sps->i_poc_type == 0 )
overhead += h->out.nal[h->out.i_nal-1].i_payload + NALU_OVERHEAD - (h->param.b_annexb && h->out.i_nal-1);
}
+ /* As required by Blu-ray. */
+ if( !IS_X264_TYPE_B( h->fenc->i_type ) && h->b_sh_backup )
+ {
+ h->b_sh_backup = 0;
+ x264_nal_start( h, NAL_SEI, NAL_PRIORITY_DISPOSABLE );
+ x264_sei_dec_ref_pic_marking_write( h, &h->out.bs );
+ if( x264_nal_end( h ) )
+ return -1;
+ overhead += h->out.nal[h->out.i_nal-1].i_payload + NALU_OVERHEAD - (h->param.b_annexb && h->out.i_nal-1);
+ }
+
if( h->fenc->b_keyframe && h->param.b_intra_refresh )
h->i_cpb_delay_pir_offset = h->fenc->i_cpb_delay;
bs_flush( &q );
x264_sei_write( s, tmp_buf, bs_pos( &q ) / 8, SEI_RECOVERY_POINT );
-
}
int x264_sei_version_write( x264_t *h, bs_t *s )
bs_flush( s );
}
+void x264_sei_dec_ref_pic_marking_write( x264_t *h, bs_t *s )
+{
+ x264_slice_header_t *sh = &h->sh_backup;
+ bs_t q;
+ uint8_t tmp_buf[100];
+ bs_init( &q, tmp_buf, 100 );
+
+ bs_realign( &q );
+
+ /* We currently only use this for repeating B-refs, as required by Blu-ray. */
+ bs_write1( &q, 0 ); //original_idr_flag
+ bs_write_ue( &q, sh->i_frame_num ); //original_frame_num
+ if( !h->sps->b_frame_mbs_only )
+ bs_write1( &q, 0 ); //original_field_pic_flag
+
+ bs_write1( &q, sh->i_mmco_command_count > 0 );
+ if( sh->i_mmco_command_count > 0 )
+ {
+ for( int i = 0; i < sh->i_mmco_command_count; i++ )
+ {
+ bs_write_ue( &q, 1 );
+ bs_write_ue( &q, sh->mmco[i].i_difference_of_pic_nums - 1 );
+ }
+ bs_write_ue( &q, 0 );
+ }
+
+ bs_align_10( &q );
+ bs_flush( &q );
+
+ x264_sei_write( s, tmp_buf, bs_pos( &q ) / 8, SEI_DEC_REF_PIC_MARKING );
+}
+
const x264_level_t x264_levels[] =
{
{ 10, 1485, 99, 152064, 64, 175, 64, 64, 0, 2, 0, 0, 1 },
int x264_validate_levels( x264_t *h, int verbose );
void x264_sei_buffering_period_write( x264_t *h, bs_t *s );
void x264_sei_pic_timing_write( x264_t *h, bs_t *s );
+void x264_sei_dec_ref_pic_marking_write( x264_t *h, bs_t *s );
void x264_sei_frame_packing_write( x264_t *h, bs_t *s );
void x264_sei_write( bs_t *s, uint8_t *payload, int payload_size, int payload_type );
void x264_filler_write( x264_t *h, bs_t *s, int filler );