]> git.sesse.net Git - x264/commitdiff
Fix CFR ratecontrol with timebase != 1/fps
authorAnton Mitrofanov <BugMaster@narod.ru>
Sat, 25 Sep 2010 22:55:32 +0000 (15:55 -0700)
committerFiona Glaser <fiona@x264.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 beffda8bff0a990de5ea38cd9924a02a4032eed1..e53a450c6141d884102daea1bd84b8e4714cf8ac 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 f1ff9d7ac380fa677e4425d747dc585fc51ef07f..9138ddccd6cc4a81027e5c9743f7440e9891b846 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 3bb3a0d007bfb0212d9b48c7c423ac76ddf806cc..272c4538eebcafc0738a7412e4d5af4e1d078d80 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 73e0bbad0e5605c9cdb731241a75b3d11a751e61..ef85b9fb976124b3e4dc121f850c7cf76fd2da3d 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 */