Fix CFR ratecontrol with timebase != 1/fps
authorAnton Mitrofanov <BugMaster@narod.ru>
Sat, 25 Sep 2010 22:55:32 +0000 (15:55 -0700)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Tue, 28 Sep 2010 13:36:35 +0000 (06:36 -0700)
Fixes VBV + DTS compression, among other things.

encoder/encoder.c
encoder/slicetype.c
x264.c
x264.h

index 2b679a0..3570776 100644 (file)
@@ -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;
index 0d87908..d08cf02 100644 (file)
@@ -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 f74f096..5bd2af7 100644 (file)
--- 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 71f5f55..ab5ae2e 100644 (file)
--- a/x264.h
+++ b/x264.h
@@ -39,7 +39,7 @@
 
 #include <stdarg.h>
 
-#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 */