[x264-devel] commit: Allow longer keyints with intra refresh (Jason Garrett-Glaser )

git version control git at videolan.org
Mon Feb 15 10:10:45 CET 2010


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Wed Feb 10 13:44:28 2010 -0800| [b3225125169210ee8982be05f3b90e3de0bdd95c] | committer: Jason Garrett-Glaser 

Allow longer keyints with intra refresh
If a long keyint is specified (longer than macroblock width-1), the refresh will simply not occur all the time.
In other words, a refresh will take place, and then x264 will wait until keyint is over to start another refresh.

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

 encoder/encoder.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 0ca6694..d43a758 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -599,8 +599,6 @@ static int x264_validate_parameters( x264_t *h )
         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.i_keyint_max = X264_MIN( h->param.i_keyint_max, (h->param.i_width+15)/16 - 1 );
     h->param.i_keyint_min = x264_clip3( h->param.i_keyint_min, 1, h->param.i_keyint_max/2+1 );
     h->param.rc.i_lookahead = x264_clip3( h->param.rc.i_lookahead, 0, X264_LOOKAHEAD_MAX );
     {
@@ -2307,22 +2305,22 @@ int     x264_encoder_encode( x264_t *h,
     if( h->param.b_intra_refresh && h->fenc->i_type == X264_TYPE_P )
     {
         int pocdiff = (h->fdec->i_poc - h->fref0[0]->i_poc)/2;
-        float increment = ((float)h->sps->i_mb_width-1) / h->param.i_keyint_max;
+        float increment = X264_MAX( ((float)h->sps->i_mb_width-1) / h->param.i_keyint_max, 1 );
+        int max_position = (int)(increment * h->param.i_keyint_max);
         if( IS_X264_TYPE_I( h->fref0[0]->i_type ) )
             h->fdec->f_pir_position = 0;
         else
         {
-            if( h->fref0[0]->i_pir_end_col == h->sps->i_mb_width - 1 )
+            h->fdec->f_pir_position = h->fref0[0]->f_pir_position;
+            if( h->fdec->f_pir_position+0.5 >= max_position )
             {
                 h->fdec->f_pir_position = 0;
                 h->fenc->b_keyframe = 1;
             }
-            else
-                h->fdec->f_pir_position = h->fref0[0]->f_pir_position;
         }
         h->fdec->i_pir_start_col = h->fdec->f_pir_position+0.5;
         h->fdec->f_pir_position += increment * pocdiff;
-        h->fdec->i_pir_end_col = X264_MIN( h->fdec->f_pir_position+0.5, h->sps->i_mb_width-1 );
+        h->fdec->i_pir_end_col = h->fdec->f_pir_position+0.5;
     }
 
     /* Write SPS and PPS */
@@ -2358,8 +2356,9 @@ int     x264_encoder_encode( x264_t *h,
 
         if( h->fenc->i_type != X264_TYPE_IDR )
         {
+            int time_to_recovery = X264_MIN( h->sps->i_mb_width - 1, h->param.i_keyint_max ) + h->param.i_bframe;
             x264_nal_start( h, NAL_SEI, NAL_PRIORITY_DISPOSABLE );
-            x264_sei_recovery_point_write( h, &h->out.bs, h->param.i_keyint_max );
+            x264_sei_recovery_point_write( h, &h->out.bs, time_to_recovery );
             x264_nal_end( h );
             overhead += h->out.nal[h->out.i_nal-1].i_payload + NALU_OVERHEAD;
         }



More information about the x264-devel mailing list