[x264-devel] Use IDR frames at scenecuts

Andreas Rheinhardt andreas.rheinhardt at googlemail.com
Wed Feb 21 23:53:50 CET 2018


In open-gop mode the current implementation uses IDR frames only for
forced IDR frames and the first frame. This is suboptimal because
a non IDR I keyframe has higher overhead (the SEI and several MMCOs
in the next frame) than an IDR frame.
Furthermore an IDR frame provides better stitchability.
Therefore I propose the following change (disclaimer: I have not read
the whole x264 source code, but only the part I deemed relevant for
this patch. It worked well in my tests and so I believe this not to
introduce any bugs, but you should nevertheless thoroughly vet it.):

---
 encoder/slicetype.c | 7 ++++++-
 x264.c              | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/encoder/slicetype.c b/encoder/slicetype.c
index 46589690..697238fa 100644
--- a/encoder/slicetype.c
+++ b/encoder/slicetype.c
@@ -1515,7 +1515,12 @@ void x264_slicetype_analyse( x264_t *h, int
intra_minigop )
         h->param.i_scenecut_threshold && scenecut( h, &a, frames, 0,
1, 1, orig_num_frames, i_max_search ) )
     {
         if( frames[1]->i_type == X264_TYPE_AUTO )
-            frames[1]->i_type = X264_TYPE_I;
+        {
+            if( frames[1]->i_frame - h->lookahead->i_last_keyframe >=
h->param.i_keyint_min )
+                frames[1]->i_type = X264_TYPE_IDR;
+            else
+                frames[1]->i_type = X264_TYPE_I;
+        }
         return;
     }

diff --git a/x264.c b/x264.c
index 7688b60d..5155c979 100644
--- a/x264.c
+++ b/x264.c
@@ -686,7 +686,7 @@ static void help( x264_param_t *defaults, int longhelp )
         "                                  - strict: Strictly
hierarchical pyramid\n"
         "                                  - normal: Non-strict (not
Blu-ray compatible)\n",
         strtable_lookup( x264_b_pyramid_names, defaults->i_bframe_pyramid ) );
-    H1( "      --open-gop              Use recovery points to close GOPs\n"
+    H1( "      --open-gop              Allow usage of recovery points
to close GOPs\n"
         "                              Only available with b-frames\n" );
     H1( "      --no-cabac              Disable CABAC\n" );
     H1( "  -r, --ref <integer>         Number of reference frames
[%d]\n", defaults->i_frame_reference );


More information about the x264-devel mailing list