From 3d0d9cda1d39239e9f388fe1fce29c9212d0273c Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Sat, 25 Sep 2010 15:55:32 -0700 Subject: [PATCH] Fix CFR ratecontrol with timebase != 1/fps Fixes VBV + DTS compression, among other things. --- encoder/encoder.c | 2 +- encoder/slicetype.c | 4 ++-- x264.c | 1 + x264.h | 6 ++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/encoder/encoder.c b/encoder/encoder.c index 2b679a0f..3570776e 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -626,7 +626,7 @@ static int x264_validate_parameters( x264_t *h ) h->param.rc.i_lookahead = X264_MIN( h->param.rc.i_lookahead, X264_MAX( h->param.i_keyint_max, bufsize*fps ) ); } - if( !h->param.i_timebase_num || !h->param.i_timebase_den ) + if( !h->param.i_timebase_num || !h->param.i_timebase_den || !(h->param.b_vfr_input || h->param.b_pulldown) ) { h->param.i_timebase_num = h->param.i_fps_den; h->param.i_timebase_den = h->param.i_fps_num; diff --git a/encoder/slicetype.c b/encoder/slicetype.c index 0d879088..d08cf02f 100644 --- a/encoder/slicetype.c +++ b/encoder/slicetype.c @@ -1260,12 +1260,12 @@ void x264_slicetype_decide( x264_t *h ) if( h->param.b_vfr_input ) { if( lookahead_size-- > 1 ) - h->lookahead->next.list[i]->i_duration = 2 * (h->lookahead->next.list[i+1]->i_pts - h->lookahead->next.list[i]->i_pts); + h->lookahead->next.list[i]->i_duration = 2 * (h->lookahead->next.list[i+1]->i_pts - h->lookahead->next.list[i]->i_pts) * h->i_dts_compress_multiplier; else h->lookahead->next.list[i]->i_duration = h->i_prev_duration; } else - h->lookahead->next.list[i]->i_duration = delta_tfi_divisor[h->lookahead->next.list[i]->i_pic_struct]; + h->lookahead->next.list[i]->i_duration = delta_tfi_divisor[h->lookahead->next.list[i]->i_pic_struct] * h->i_dts_compress_multiplier; h->i_prev_duration = h->lookahead->next.list[i]->i_duration; if( h->lookahead->next.list[i]->i_frame > h->i_disp_fields_last_frame && lookahead_size > 0 ) diff --git a/x264.c b/x264.c index f74f0967..5bd2af7f 100644 --- a/x264.c +++ b/x264.c @@ -1595,6 +1595,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) /* set up pulldown */ if( opt->i_pulldown && !param->b_vfr_input ) { + param->b_pulldown = 1; param->b_pic_struct = 1; pulldown = &pulldown_values[opt->i_pulldown]; param->i_timebase_num = param->i_fps_den; diff --git a/x264.h b/x264.h index 71f5f555..ab5ae2e9 100644 --- a/x264.h +++ b/x264.h @@ -39,7 +39,7 @@ #include -#define X264_BUILD 105 +#define X264_BUILD 106 /* x264_t: * opaque handler for encoder */ @@ -383,7 +383,9 @@ typedef struct x264_param_t int b_annexb; /* if set, place start codes (4 bytes) before NAL units, * otherwise place size (4 bytes) before NAL units. */ int i_sps_id; /* SPS and PPS id number */ - int b_vfr_input; /* VFR input */ + int b_vfr_input; /* VFR input. If 1, use timebase and timestamps for ratecontrol purposes. + * If 0, use fps only. */ + int b_pulldown; /* use explicity set timebase for CFR */ uint32_t i_fps_num; uint32_t i_fps_den; uint32_t i_timebase_num; /* Timebase numerator */ -- 2.47.3