[x264-devel] commit: Improve flash detection's behavior near the end of the video ( Jason Garrett-Glaser )

git at videolan.org git at videolan.org
Wed Nov 10 10:12:35 CET 2010


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Sat Nov  6 17:47:27 2010 -0700| [601c0e38ef957ecca3792521beb335113ba49e3b] | committer: Jason Garrett-Glaser 

Improve flash detection's behavior near the end of the video
Flash detection catches situations like AAAABBCCDDDD, where A,B,C,D are frames in different scenes.
x264 would place a keyframe on the first "D".
However, if the video ended on the last "C", x264 would place a keyframe on the first "C", even though C classifies as a flash.
This change fixes this issue.

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

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

diff --git a/encoder/slicetype.c b/encoder/slicetype.c
index 91a8525..2d4a0f0 100644
--- a/encoder/slicetype.c
+++ b/encoder/slicetype.c
@@ -1037,14 +1037,14 @@ static int scenecut( x264_t *h, x264_mb_analysis_t *a, x264_frame_t **frames, in
     /* Only do analysis during a normal scenecut check. */
     if( real_scenecut && h->param.i_bframe )
     {
-        int maxp1 = p0 + 1;
+        int origmaxp1 = p0 + 1;
         /* Look ahead to avoid coding short flashes as scenecuts. */
         if( h->param.i_bframe_adaptive == X264_B_ADAPT_TRELLIS )
             /* Don't analyse any more frames than the trellis would have covered. */
-            maxp1 += h->param.i_bframe;
+            origmaxp1 += h->param.i_bframe;
         else
-            maxp1++;
-        maxp1 = X264_MIN( maxp1, num_frames );
+            origmaxp1++;
+        int maxp1 = X264_MIN( origmaxp1, num_frames );
 
         /* Where A and B are scenes: AAAAAABBBAAAAAA
          * If BBB is shorter than (maxp1-p0), it is detected as a flash
@@ -1058,9 +1058,10 @@ static int scenecut( x264_t *h, x264_mb_analysis_t *a, x264_frame_t **frames, in
         /* Where A-F are scenes: AAAAABBCCDDEEFFFFFF
          * If each of BB ... EE are shorter than (maxp1-p0), they are
          * detected as flashes and not considered scenecuts.
-         * Instead, the first F frame becomes a scenecut. */
-        for( int curp0 = p0; curp0 < maxp1; curp0++ )
-            if( scenecut_internal( h, a, frames, curp0, maxp1, 0 ) )
+         * Instead, the first F frame becomes a scenecut.
+         * If the video ends before F, no frame becomes a scenecut. */
+        for( int curp0 = p0; curp0 <= maxp1; curp0++ )
+            if( maxp1 != origmaxp1 || (curp0 < maxp1 && scenecut_internal( h, a, frames, curp0, maxp1, 0 )) )
                 /* If cur_p0 is the p0 of a scenecut, it cannot be the p1 of a scenecut. */
                     frames[curp0]->b_scenecut = 0;
     }



More information about the x264-devel mailing list