[x265] [PATCH] slicetype: respect --bframes count when --b-adapt is 0

Steve Borho steve at borho.org
Thu Sep 19 22:34:25 CEST 2013


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1379622846 18000
#      Thu Sep 19 15:34:06 2013 -0500
# Branch stable
# Node ID 2ba6ec553f218d2b06ad803b87d6ec751fd639f7
# Parent  4c97a202510373b4df6573456ec7f7888c216063
slicetype: respect --bframes count when --b-adapt is 0

--b-adapt 0 --bframes 3  => IPBBBPBBBPBBB
--b-adapt 0 --bframes 4  => IPBBBBPBBBBPBBBB

This is a stop-gap feature until --b-adapt 1 and 2 are fully functional

diff -r 4c97a2025103 -r 2ba6ec553f21 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Thu Sep 19 14:09:28 2013 -0500
+++ b/source/encoder/slicetype.cpp	Thu Sep 19 15:34:06 2013 -0500
@@ -121,10 +121,10 @@
         // Special case for POC 0, send directly to output queue as I slice
         TComPic *pic = inputQueue.popFront();
         pic->m_lowres.sliceType = X265_TYPE_I;
+        pic->m_lowres.bKeyframe = true;
+        lastKeyframe = 0;
         outputQueue.pushBack(pic);
         numDecided++;
-        lastKeyframe = 0;
-        pic->m_lowres.bKeyframe = true;
         frames[0] = &(pic->m_lowres);
         return;
     }
@@ -182,45 +182,54 @@
 
         pic->m_lowres.sliceType = X265_TYPE_I;
         pic->m_lowres.bKeyframe = true;
+        lastKeyframe = pic->m_lowres.frameNum;
         outputQueue.pushBack(pic);
         numDecided++;
     }
     else if (cfg->param.bframes == 0 || inputQueue.size() == 1)
     {
         TComPic *pic = inputQueue.popFront();
-
-        bool forceIntra = (pic->getPOC() % cfg->param.keyframeMax) == 0;
-        pic->m_lowres.sliceType = forceIntra ? X265_TYPE_I : X265_TYPE_P;
-        pic->m_lowres.bKeyframe = forceIntra;
+        if (pic->getPOC() % cfg->param.keyframeMax)
+            pic->m_lowres.sliceType = X265_TYPE_P;
+        else
+        {
+            pic->m_lowres.sliceType = X265_TYPE_I;
+            pic->m_lowres.bKeyframe = true;
+            lastKeyframe = pic->m_lowres.frameNum;
+        }
         outputQueue.pushBack(pic);
         numDecided++;
     }
     else
     {
-        TComPic *picB = inputQueue.popFront();
-        TComPic *picP = inputQueue.popFront();
+        TComPic *list[X265_BFRAME_MAX+1];
+        int j;
+        for (j = 0; j <= cfg->param.bframes && !inputQueue.empty(); j++)
+        {
+            TComPic *pic = inputQueue.popFront();
+            list[j] = pic;
+            if (pic->m_lowres.frameNum >= lastKeyframe + cfg->param.keyframeMax)
+            {
+                pic->m_lowres.sliceType = X265_TYPE_I;
+                pic->m_lowres.bKeyframe = true;
+                lastKeyframe = pic->m_lowres.frameNum;
+                if (j) list[j - 1]->m_lowres.sliceType = X265_TYPE_P;
+                j++;
+                break;
+            }
+        }
 
-        bool forceIntra = (picP->getPOC() % cfg->param.keyframeMax) == 0 || (picB->getPOC() % cfg->param.keyframeMax) == 0;
-        if (forceIntra)
+        TComPic *pic = list[j - 1];
+        if (pic->m_lowres.sliceType == X265_TYPE_AUTO)
+            pic->m_lowres.sliceType = X265_TYPE_P;
+        outputQueue.pushBack(pic);
+        numDecided++;
+        for (int i = 0; i < j - 1; i++)
         {
-            picB->m_lowres.sliceType = (picB->getPOC() % cfg->param.keyframeMax) ? X265_TYPE_P : X265_TYPE_I;
-            picB->m_lowres.bKeyframe = !(picB->getPOC() % cfg->param.keyframeMax);
-            outputQueue.pushBack(picB);
-            numDecided++;
-
-            picP->m_lowres.sliceType = (picP->getPOC() % cfg->param.keyframeMax) ? X265_TYPE_P : X265_TYPE_I;
-            picP->m_lowres.bKeyframe = !(picP->getPOC() % cfg->param.keyframeMax);
-            outputQueue.pushBack(picP);
-            numDecided++;
-        }
-        else
-        {
-            picP->m_lowres.sliceType = X265_TYPE_P;
-            outputQueue.pushBack(picP);
-            numDecided++;
-
-            picB->m_lowres.sliceType = X265_TYPE_B;
-            outputQueue.pushBack(picB);
+            TComPic *pic = list[i];
+            if (pic->m_lowres.sliceType == X265_TYPE_AUTO)
+                pic->m_lowres.sliceType = X265_TYPE_B;
+            outputQueue.pushBack(pic);
             numDecided++;
         }
     }


More information about the x265-devel mailing list