Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: common/common.c
- ===================================================================
- --- common/common_orig.c
- +++ common/common.c
- @@ -693,6 +693,8 @@
- p->i_slice_max_mbs = atoi(value);
- OPT("slices")
- p->i_slice_count = atoi(value);
- + OPT("open-gop")
- + p->b_open_gop = atobool(value);
- OPT("cabac")
- p->b_cabac = atobool(value);
- OPT("cabac-idc")
- @@ -1225,9 +1227,9 @@
- s += sprintf( s, " bframes=%d", p->i_bframe );
- if( p->i_bframe )
- {
- - s += sprintf( s, " b_pyramid=%d b_adapt=%d b_bias=%d direct=%d wpredb=%d",
- + s += sprintf( s, " b_pyramid=%d b_adapt=%d b_bias=%d direct=%d wpredb=%d open_gop=%d",
- p->i_bframe_pyramid, p->i_bframe_adaptive, p->i_bframe_bias,
- - p->analyse.i_direct_mv_pred, p->analyse.b_weighted_bipred );
- + p->analyse.i_direct_mv_pred, p->analyse.b_weighted_bipred, p->b_open_gop );
- }
- s += sprintf( s, " wpredp=%d", p->analyse.i_weighted_pred > 0 ? p->analyse.i_weighted_pred : 0 );
- Index: common/common.h
- ===================================================================
- --- common/common_orig.h
- +++ common/common.h
- @@ -297,6 +297,7 @@
- volatile uint8_t b_exit_thread;
- uint8_t b_thread_active;
- uint8_t b_analyse_keyframe;
- + int i_last_idr;
- int i_last_keyframe;
- int i_slicetype_length;
- x264_frame_t *last_nonb;
- @@ -441,6 +442,8 @@
- x264_frame_t *reference[16+2];
- int i_last_keyframe; /* Frame number of the last keyframe */
- + int i_last_idr; /* Frame number of the last IDR (not RP)*/
- + int i_poc_last_open_gop; /* Stores poc of last i frame before pruning else -1*/
- int i_input; /* Number of input frames already accepted */
- Index: encoder/encoder.c
- ===================================================================
- --- encoder/encoder_orig.c
- +++ encoder/encoder.c
- @@ -566,6 +566,7 @@
- h->param.i_bframe_adaptive = X264_B_ADAPT_NONE;
- h->param.analyse.i_direct_mv_pred = 0;
- h->param.analyse.b_weighted_bipred = 0;
- + h->param.b_open_gop = 0;
- }
- if( h->param.b_intra_refresh && h->param.i_bframe_pyramid == X264_B_PYRAMID_NORMAL )
- {
- @@ -577,6 +578,11 @@
- x264_log( h, X264_LOG_WARNING, "ref > 1 + intra-refresh is not supported\n" );
- h->param.i_frame_reference = 1;
- }
- + if( h->param.b_intra_refresh && h->param.b_open_gop )
- + {
- + x264_log( h, X264_LOG_WARNING, "intra-refresh nullifies open gop\n" );
- + h->param.b_open_gop = 0;
- + }
- if( h->param.i_keyint_min == X264_KEYINT_MIN_AUTO )
- h->param.i_keyint_min = h->param.i_keyint_max / 10;
- h->param.i_keyint_min = x264_clip3( h->param.i_keyint_min, 1, h->param.i_keyint_max/2+1 );
- @@ -944,9 +950,11 @@
- h->frames.b_have_lowres |= h->param.rc.b_stat_read && h->param.rc.i_vbv_buffer_size > 0;
- h->frames.b_have_sub8x8_esa = !!(h->param.analyse.inter & X264_ANALYSE_PSUB8x8);
- - h->frames.i_last_keyframe = - h->param.i_keyint_max;
- + h->frames.i_last_idr =
- + h->frames.i_last_keyframe = - h->param.i_keyint_max;
- h->frames.i_input = 0;
- h->frames.i_largest_pts = h->frames.i_second_largest_pts = -1;
- + h->frames.i_poc_last_open_gop = -1;
- CHECKED_MALLOCZERO( h->frames.unused[0], (h->frames.i_delay + 3) * sizeof(x264_frame_t *) );
- /* Allocate room for max refs plus a few extra just in case. */
- @@ -1658,9 +1666,11 @@
- static inline void x264_reference_hierarchy_reset( x264_t *h )
- {
- int ref;
- - int b_hasdelayframe = 0;
- - if( !h->param.i_bframe_pyramid )
- - return;
- + uint8_t b_hasdelayframe = 0;
- +
- + /* This function must handle b-pyramid and clear frames for open-gop */
- + if( h->param.i_bframe_pyramid != X264_B_PYRAMID_STRICT && !b_hasdelayframe && h->frames.i_poc_last_open_gop == -1 )
- + return;
- /* look for delay frames -- chain must only contain frames that are disposable */
- for( int i = 0; h->frames.current[i] && IS_DISPOSABLE( h->frames.current[i]->i_type ); i++ )
- @@ -1674,20 +1684,24 @@
- * dpb during a BREF decode when pyramid == STRICT */
- for( ref = 0; h->frames.reference[ref]; ref++ )
- {
- - if( h->param.i_bframe_pyramid == X264_B_PYRAMID_STRICT
- + if( ( h->param.i_bframe_pyramid == X264_B_PYRAMID_STRICT
- && h->frames.reference[ref]->i_type == X264_TYPE_BREF )
- + || ( h->frames.i_poc_last_open_gop >= 0
- + && h->frames.i_poc_last_open_gop != h->frames.reference[ref]->i_poc
- + && h->sh.i_type != SLICE_TYPE_B ) )
- {
- int diff = h->i_frame_num - h->frames.reference[ref]->i_frame_num;
- h->sh.mmco[h->sh.i_mmco_command_count].i_difference_of_pic_nums = diff;
- h->sh.mmco[h->sh.i_mmco_command_count++].i_poc = h->frames.reference[ref]->i_poc;
- - x264_frame_push_unused( h, x264_frame_pop( h->frames.reference ) );
- + x264_frame_push_unused( h, x264_frame_shift( &h->frames.reference[ref] ) );
- h->b_ref_reorder[0] = 1;
- - break;
- + ref--;
- }
- }
- - /* Prepare to room in the dpb for the delayed display time of the later b-frame's */
- - h->sh.i_mmco_remove_from_end = X264_MAX( ref + 2 - h->frames.i_max_dpb, 0 );
- + /* Prepare room in the dpb for the delayed display time of the later b-frame's */
- + if( h->param.i_bframe_pyramid )
- + h->sh.i_mmco_remove_from_end = X264_MAX( ref + 2 - h->frames.i_max_dpb, 0 );
- }
- static inline void x264_slice_init( x264_t *h, int i_nal_type, int i_global_qp )
- @@ -2268,17 +2282,22 @@
- if( h->fenc->b_keyframe )
- {
- h->frames.i_last_keyframe = h->fenc->i_frame;
- - if( h->fenc->i_type == X264_TYPE_IDR )
- + if( IS_X264_TYPE_IDR( h->fenc->i_type, h->param.b_open_gop ) )
- + {
- h->i_frame_num = 0;
- + h->frames.i_last_idr = h->fenc->i_frame;
- + }
- }
- h->sh.i_mmco_command_count =
- h->sh.i_mmco_remove_from_end = 0;
- h->b_ref_reorder[0] =
- h->b_ref_reorder[1] = 0;
- + h->fdec->i_poc =
- + h->fenc->i_poc = 2 * ( h->fenc->i_frame - X264_MAX( h->frames.i_last_idr, 0 ) );
- /* ------------------- Setup frame context ----------------------------- */
- /* 5: Init data dependent of frame type */
- - if( h->fenc->i_type == X264_TYPE_IDR )
- + if( IS_X264_TYPE_IDR( h->fenc->i_type, h->param.b_open_gop ) )
- {
- /* reset ref pictures */
- i_nal_type = NAL_SLICE_IDR;
- @@ -2286,12 +2305,14 @@
- h->sh.i_type = SLICE_TYPE_I;
- x264_reference_reset( h );
- }
- - else if( h->fenc->i_type == X264_TYPE_I )
- + else if( IS_X264_TYPE_RP( h->fenc->i_type, h->param.b_open_gop ) )
- {
- i_nal_type = NAL_SLICE;
- i_nal_ref_idc = NAL_PRIORITY_HIGH; /* Not completely true but for now it is (as all I/P are kept as ref)*/
- h->sh.i_type = SLICE_TYPE_I;
- x264_reference_hierarchy_reset( h );
- + if( h->param.b_open_gop )
- + h->frames.i_poc_last_open_gop = h->fenc->b_keyframe ? h->fenc->i_poc : -1;
- }
- else if( h->fenc->i_type == X264_TYPE_P )
- {
- @@ -2299,6 +2320,7 @@
- i_nal_ref_idc = NAL_PRIORITY_HIGH; /* Not completely true but for now it is (as all I/P are kept as ref)*/
- h->sh.i_type = SLICE_TYPE_P;
- x264_reference_hierarchy_reset( h );
- + h->frames.i_poc_last_open_gop = -1;
- }
- else if( h->fenc->i_type == X264_TYPE_BREF )
- {
- @@ -2314,8 +2336,6 @@
- h->sh.i_type = SLICE_TYPE_B;
- }
- - h->fdec->i_poc =
- - h->fenc->i_poc = 2 * (h->fenc->i_frame - h->frames.i_last_keyframe);
- h->fdec->i_type = h->fenc->i_type;
- h->fdec->i_frame = h->fenc->i_frame;
- h->fenc->b_kept_as_ref =
- Index: encoder/ratecontrol.c
- ===================================================================
- --- encoder/ratecontrol_orig.c
- +++ encoder/ratecontrol.c
- @@ -674,6 +674,7 @@
- CMP_OPT_FIRST_PASS( "b_pyramid", h->param.i_bframe_pyramid );
- CMP_OPT_FIRST_PASS( "intra_refresh", h->param.b_intra_refresh );
- CMP_OPT_FIRST_PASS( "keyint", h->param.i_keyint_max );
- + CMP_OPT_FIRST_PASS( "open_gop", h->param.b_open_gop );
- if( strstr( opts, "qp=0" ) && h->param.rc.i_rc_method == X264_RC_ABR )
- x264_log( h, X264_LOG_WARNING, "1st pass was lossless, bitrate prediction will be inaccurate\n" );
- Index: encoder/slicetype.c
- ===================================================================
- --- encoder/slicetype_orig.c
- +++ encoder/slicetype.c
- @@ -1085,7 +1085,6 @@
- orig_num_frames = num_frames = h->param.b_intra_refresh ? framecnt : X264_MIN( framecnt, keyint_limit );
- x264_lowres_context_init( h, &a );
- - idr_frame_type = frames[1]->i_frame - h->lookahead->i_last_keyframe >= h->param.i_keyint_min ? X264_TYPE_IDR : X264_TYPE_I;
- /* This is important psy-wise: if we have a non-scenecut keyframe,
- * there will be significant visual artifacts if the frames just before
- @@ -1097,12 +1096,12 @@
- {
- frames[1]->i_type = X264_TYPE_P;
- if( h->param.i_scenecut_threshold && scenecut( h, &a, frames, 0, 1, 1, orig_num_frames ) )
- - frames[1]->i_type = idr_frame_type;
- + frames[1]->i_type = X264_TYPE_I;
- return;
- }
- else if( num_frames == 0 )
- {
- - frames[1]->i_type = idr_frame_type;
- + frames[1]->i_type = X264_TYPE_I;
- return;
- }
- @@ -1111,7 +1110,7 @@
- int reset_start;
- if( h->param.i_scenecut_threshold && scenecut( h, &a, frames, 0, 1, 1, orig_num_frames ) )
- {
- - frames[1]->i_type = idr_frame_type;
- + frames[1]->i_type = X264_TYPE_I;
- return;
- }
- @@ -1219,9 +1218,7 @@
- {
- if( ((j-keyint_limit) % h->param.i_keyint_max) == 0 )
- {
- - if( j && h->param.i_keyint_max > 1 )
- - frames[j]->i_type = X264_TYPE_P;
- - frames[j+1]->i_type = X264_TYPE_IDR;
- + frames[j+1]->i_type = X264_TYPE_I;
- reset_start = X264_MIN( reset_start, j+2 );
- }
- }
- @@ -1311,12 +1308,23 @@
- /* Limit GOP size */
- if( (!h->param.b_intra_refresh || frm->i_frame == 0) && frm->i_frame - h->lookahead->i_last_keyframe >= h->param.i_keyint_max )
- {
- - if( frm->i_type == X264_TYPE_AUTO )
- - frm->i_type = X264_TYPE_IDR;
- - if( frm->i_type != X264_TYPE_IDR )
- + if( frm->i_type == X264_TYPE_AUTO || frm->i_type == X264_TYPE_I )
- + frm->i_type = h->param.b_open_gop && h->lookahead->i_last_keyframe >= 0 ? X264_TYPE_I : X264_TYPE_IDR;
- + if( frm->i_type != X264_TYPE_IDR && frm->i_type != X264_TYPE_I && frm->i_type != X264_TYPE_KEYFRAME )
- x264_log( h, X264_LOG_WARNING, "specified frame type (%d) is not compatible with keyframe interval\n", frm->i_type );
- }
- - if( frm->i_type == X264_TYPE_IDR )
- + if( frm->i_type == X264_TYPE_I && frm->i_frame - h->lookahead->i_last_keyframe >= h->param.i_keyint_min )
- + {
- + if( h->param.b_open_gop )
- + {
- + h->lookahead->i_last_keyframe = frm->i_frame;
- + frm->b_keyframe = 1;
- + }
- + else
- + frm->i_type = X264_TYPE_IDR;
- + }
- + // 'close' gop if type is IDR or RP for seeking
- + if( frm->i_type == X264_TYPE_IDR || frm->i_type == X264_TYPE_KEYFRAME )
- {
- /* Close GOP */
- h->lookahead->i_last_keyframe = frm->i_frame;
- Index: x264.c
- ===================================================================
- --- x264_orig.c
- +++ x264.c
- @@ -380,6 +380,8 @@
- " - strict: Strictly hierarchical pyramid\n"
- " - normal: Non-strict (not Blu-ray compatible)\n",
- strtable_lookup( x264_b_pyramid_names, defaults->i_bframe_pyramid ) );
- + H1( " --open-gop Use non IDR i-frames w/ recovery point SEI to\n"
- + " close GOPs; Only available with b-frames\n" );
- H1( " --no-cabac Disable CABAC\n" );
- H1( " -r, --ref <integer> Number of reference frames [%d]\n", defaults->i_frame_reference );
- H1( " --no-deblock Disable loop filter\n" );
- @@ -622,6 +624,7 @@
- { "no-b-adapt", no_argument, NULL, 0 },
- { "b-bias", required_argument, NULL, 0 },
- { "b-pyramid", required_argument, NULL, 0 },
- + { "open-gop", no_argument, NULL, 0 },
- { "min-keyint", required_argument, NULL, 'i' },
- { "keyint", required_argument, NULL, 'I' },
- { "intra-refresh", no_argument, NULL, 0 },
- @@ -1287,6 +1290,7 @@
- pic->i_qpplus1 = qp+1;
- if ( type == 'I' ) pic->i_type = X264_TYPE_IDR;
- else if( type == 'i' ) pic->i_type = X264_TYPE_I;
- + else if( type == 'K' ) pic->i_type = X264_TYPE_KEYFRAME;
- else if( type == 'P' ) pic->i_type = X264_TYPE_P;
- else if( type == 'B' ) pic->i_type = X264_TYPE_BREF;
- else if( type == 'b' ) pic->i_type = X264_TYPE_B;
- Index: x264.h
- ===================================================================
- --- x264_orig.h
- +++ x264.h
- @@ -136,7 +136,10 @@
- #define X264_TYPE_P 0x0003
- #define X264_TYPE_BREF 0x0004 /* Non-disposable B-frame */
- #define X264_TYPE_B 0x0005
- -#define IS_X264_TYPE_I(x) ((x)==X264_TYPE_I || (x)==X264_TYPE_IDR)
- +#define X264_TYPE_KEYFRAME 0x0006 /* IDR or I depending on b_open_gop option */
- +#define IS_X264_TYPE_I(x) ((x)==X264_TYPE_I || (x)==X264_TYPE_IDR || (x)==X264_TYPE_KEYFRAME)
- +#define IS_X264_TYPE_IDR(x,isopengop) ((x)==X264_TYPE_IDR || (x)==X264_TYPE_KEYFRAME && !(isopengop))
- +#define IS_X264_TYPE_RP(x,isopengop) ((x)==X264_TYPE_I || (x)==X264_TYPE_KEYFRAME && (isopengop))
- #define IS_X264_TYPE_B(x) ((x)==X264_TYPE_B || (x)==X264_TYPE_BREF)
- /* Log level */
- @@ -222,6 +225,7 @@
- int i_bframe_adaptive;
- int i_bframe_bias;
- int i_bframe_pyramid; /* Keep some B-frames as references: 0=off, 1=strict hierarchical, 2=normal */
- + int b_open_gop;
- int b_deblocking_filter;
- int i_deblocking_filter_alphac0; /* [-6, 6] -6 light filter, 6 strong */
Advertisement
Add Comment
Please, Sign In to add comment