[x265] [PATCH] slicetype: fix bugs in scenecut and slicetype decision

deepthi at multicorewareinc.com deepthi at multicorewareinc.com
Tue Oct 6 13:36:39 CEST 2015


# HG changeset patch
# User Deepthi Nandakumar <deepthi at multicorewareinc.com>
# Date 1444115344 -19800
#      Tue Oct 06 12:39:04 2015 +0530
# Branch stable
# Node ID aaf7fe7452b5c46e564d32ff52f2730a79ebaea1
# Parent  98ac099a766fc3eb6333fd5676b87a5933e1e3d0
slicetype: fix bugs in scenecut and slicetype decision

The default value of bScenecut had changed to false (instead of true) and this
was not accounted for correctly.

diff -r 98ac099a766f -r aaf7fe7452b5 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Tue Sep 29 14:14:24 2015 +0530
+++ b/source/encoder/slicetype.cpp	Tue Oct 06 12:39:04 2015 +0530
@@ -1259,7 +1259,7 @@
     {
         bool isScenecut = scenecut(frames, 0, 1, true, origNumFrames);
         /* When scenecut threshold is set, use scenecut detection for I frame placements */
-        if (!m_param->scenecutThreshold && isScenecut)
+        if (m_param->scenecutThreshold && isScenecut)
         {
             frames[1]->sliceType = X265_TYPE_I;
             return;
@@ -1402,7 +1402,7 @@
         origmaxp1 += m_param->bframes;
         int maxp1 = X265_MIN(origmaxp1, numFrames);
         bool fluctuate = false;
-        bool noScenecuts = false;
+        bool scenecutFound = false;
         int64_t avgSatdCost = 0;
         if (frames[0]->costEst[1][0] > -1)
             avgSatdCost = frames[0]->costEst[1][0];
@@ -1412,23 +1412,11 @@
          * and not considered a scenecut. */
         for (int cp1 = p1; cp1 <= maxp1; cp1++)
         {
-            if (!scenecutInternal(frames, p0, cp1, false))
+            if (scenecutInternal(frames, p0, cp1, false))
             {
-                /* Any frame in between p0 and cur_p1 cannot be a real scenecut. */
-                for (int i = cp1; i > p0; i--)
-                {
-                    frames[i]->bScenecut = false;
-                    noScenecuts = false;
-                }
+                frames[cp1]->bScenecut = true;
+                scenecutFound = true;
             }
-            else if (scenecutInternal(frames, cp1 - 1, cp1, false))
-            {
-                /* If current frame is a Scenecut from p0 frame as well as Scenecut from
-                 * preceeding frame, mark it as a Scenecut */
-                frames[cp1]->bScenecut = true;
-                noScenecuts = true;
-            }
-
             /* compute average satdcost of all the frames in the mini-gop to confirm 
              * whether there is any great fluctuation among them to rule out false positives */
             X265_CHECK(frames[cp1]->costEst[cp1 - p0][0]!= -1, "costEst is not done \n");
@@ -1440,32 +1428,30 @@
          * This could denote the beginning or ending of scene transitions.
          * During a scene transition(fade in/fade outs), if fluctuate remains false,
          * then the scene had completed its transition or stabilized */
-        if (noScenecuts)
+        if (scenecutFound)
         {
             fluctuate = false;
             avgSatdCost /= cnt;
-            for (int i= p1 ; i <= maxp1; i++)
+            for (int i = p1; i <= maxp1; i++)
             {
                 if (fabs((double)(frames[i]->costEst[i - p0][0] - avgSatdCost)) > 0.1 * avgSatdCost)
                 {
                     fluctuate = true;
-                    if (!m_isSceneTransition && frames[i]->bScenecut)
+                    if (frames[i]->bScenecut)
                     {
-                        m_isSceneTransition = true;
-                        /* just mark the first scenechange in the scene transition as a scenecut. */
+                        /* just mark the first scenechange in the scene transition as a scenecut */
                         for (int j = i + 1; j <= maxp1; j++)
                             frames[j]->bScenecut = false;
+                        frames[i]->bScenecut = true;
                         break;
                     }
                 }
-                frames[i]->bScenecut = false;
             }
         }
-        if (!fluctuate && !noScenecuts)
-            m_isSceneTransition = false; /* Signal end of scene transitioning */
+        if (fluctuate && scenecutFound)
+            m_isSceneTransition = !m_isSceneTransition;
     }
 
-    /* Ignore frames that are part of a flash, i.e. cannot be real scenecuts */
     if (!frames[p1]->bScenecut)
         return false;
     return scenecutInternal(frames, p0, p1, bRealScenecut);


More information about the x265-devel mailing list