[x264-devel] commit: Fix intra refresh behavior with I-frames (Jason Garrett-Glaser )

git at videolan.org git at videolan.org
Mon May 17 18:39:44 CEST 2010


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Sat May  8 11:58:22 2010 -0700| [29b379cc3499541e72007131909d45a8c472f2b5] | committer: Jason Garrett-Glaser 

Fix intra refresh behavior with I-frames
Intra refresh still allows I-frames (for scenecuts/etc).
Now I-frames count as a full refresh, as opposed to instantly triggering a refresh.

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

 common/frame.h    |    1 +
 encoder/encoder.c |   28 +++++++++++++++++-----------
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/common/frame.h b/common/frame.h
index 357929e..e2766ad 100644
--- a/common/frame.h
+++ b/common/frame.h
@@ -142,6 +142,7 @@ typedef struct x264_frame
     float   f_pir_position;
     int     i_pir_start_col;
     int     i_pir_end_col;
+    int     i_frames_since_pir;
 } x264_frame_t;
 
 /* synchronized frame list */
diff --git a/encoder/encoder.c b/encoder/encoder.c
index 7ad4295..7c5a64f 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -2375,25 +2375,31 @@ int     x264_encoder_encode( x264_t *h,
     h->i_nal_type = i_nal_type;
     h->i_nal_ref_idc = i_nal_ref_idc;
 
-    if( h->param.b_intra_refresh && h->fenc->i_type == X264_TYPE_P )
+    if( h->param.b_intra_refresh )
     {
-        int pocdiff = (h->fdec->i_poc - h->fref0[0]->i_poc)/2;
-        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( IS_X264_TYPE_I( h->fenc->i_type ) )
+        {
+            h->fdec->i_frames_since_pir = 0;
+            /* PIR is currently only supported with ref == 1, so any intra frame effectively refreshes
+             * the whole frame and counts as an intra refresh. */
+            h->fdec->f_pir_position = h->sps->i_mb_width;
+        }
+        else if( h->fenc->i_type == X264_TYPE_P )
         {
+            int pocdiff = (h->fdec->i_poc - h->fref0[0]->i_poc)/2;
+            float increment = X264_MAX( ((float)h->sps->i_mb_width-1) / h->param.i_keyint_max, 1 );
             h->fdec->f_pir_position = h->fref0[0]->f_pir_position;
-            if( h->fdec->f_pir_position+0.5 >= max_position )
+            h->fdec->i_frames_since_pir = h->fref0[0]->i_frames_since_pir + pocdiff;
+            if( h->fdec->i_frames_since_pir >= h->param.i_keyint_max )
             {
                 h->fdec->f_pir_position = 0;
+                h->fdec->i_frames_since_pir = 0;
                 h->fenc->b_keyframe = 1;
             }
+            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 = h->fdec->f_pir_position+0.5;
         }
-        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 = h->fdec->f_pir_position+0.5;
     }
 
     if( h->fenc->b_keyframe )



More information about the x264-devel mailing list