[x264-devel] commit: Fix CFR ratecontrol with timebase != 1/fps (Anton Mitrofanov )

git at videolan.org git at videolan.org
Tue Sep 28 15:38:21 CEST 2010


x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Sat Sep 25 15:55:32 2010 -0700| [3d0d9cda1d39239e9f388fe1fce29c9212d0273c] | committer: Jason Garrett-Glaser 

Fix CFR ratecontrol with timebase != 1/fps
Fixes VBV + DTS compression, among other things.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=3d0d9cda1d39239e9f388fe1fce29c9212d0273c
---

 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 2b679a0..3570776 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 0d87908..d08cf02 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 f74f096..5bd2af7 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 71f5f55..ab5ae2e 100644
--- 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 */



More information about the x264-devel mailing list