[x265] [PATCH] Add rateontrol support
Anusuya Kumarasamy
anusuya.kumarasamy at multicorewareinc.com
Mon Sep 9 08:34:13 UTC 2024
>From f6b409512b165e2cb397bfad5ec8c5f883129e28 Mon Sep 17 00:00:00 2001
From: AnusuyaKumarasamy <anusuya.kumarasamy at multicorewareinc.com>
Date: Wed, 21 Aug 2024 09:40:23 +0530
Subject: [PATCH 3/7] Add rateontrol support
---
source/common/param.cpp | 3 --
source/encoder/frameencoder.cpp | 50 ++++++++++++++++++++++++++-------
2 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/source/common/param.cpp b/source/common/param.cpp
index aad31b515..72561a9cf 100755
--- a/source/common/param.cpp
+++ b/source/common/param.cpp
@@ -1959,14 +1959,11 @@ int x265_check_params(x265_param* param)
if (param->bEnableAlpha)
{
CHECK((param->internalCsp != X265_CSP_I420), "Alpha encode
supported only with i420a colorspace");
- CHECK((param->rc.rateControlMode != X265_RC_CQP), "Alpha encode
supported only with CQP mode");
}
#endif
#if ENABLE_MULTIVIEW
CHECK((param->numViews > 2), "Multi-View Encoding currently support
only 2 views");
CHECK((param->numViews > 1) && (param->internalBitDepth != 8),
"BitDepthConstraint must be 8 for Multiview main profile");
- CHECK((param->numViews > 1) && (param->rc.rateControlMode !=
X265_RC_CQP && param->rc.rateControlMode != X265_RC_ABR),
- "Multiview encode supported only with CQP and ABR modes");
#endif
#if ENABLE_SCC_EXT
CHECK(!!param->bEnableSCC&& param->rdLevel != 6, "Enabling scc
extension in x265 requires rdlevel of 6 ");
diff --git a/source/encoder/frameencoder.cpp
b/source/encoder/frameencoder.cpp
index 296ca4581..09ed0b9f7 100644
--- a/source/encoder/frameencoder.cpp
+++ b/source/encoder/frameencoder.cpp
@@ -621,10 +621,18 @@ void FrameEncoder::compressFrame(int layer)
ncu = m_top->m_rateControl->m_ncu * 4;
else
ncu = m_top->m_rateControl->m_ncu;
- for (int i = 0; i < ncu; i++)
+ if (m_param->numViews > 1)
{
- m_frame[layer]->m_lowres.qpCuTreeOffset[i] =
m_frame[0]->m_lowres.qpCuTreeOffset[i];
- m_frame[layer]->m_lowres.qpAqOffset[i] =
m_frame[0]->m_lowres.qpAqOffset[i];
+ for (int i = 0; i < ncu; i++)
+ {
+ m_frame[layer]->m_lowres.qpCuTreeOffset[i] =
m_frame[0]->m_lowres.qpCuTreeOffset[i];
+ m_frame[layer]->m_lowres.qpAqOffset[i] =
m_frame[0]->m_lowres.qpAqOffset[i];
+ }
+ }
+ else if (m_param->numScalableLayers > 1)
+ {
+ memset(m_frame[layer]->m_lowres.qpCuTreeOffset, 0,
sizeof(double)*ncu);
+ memset(m_frame[layer]->m_lowres.qpAqOffset, 0, sizeof(double)*
ncu);
}
m_frame[layer]->m_encData->m_avgQpAq =
m_frame[0]->m_encData->m_avgQpAq;
@@ -645,14 +653,24 @@ void FrameEncoder::compressFrame(int layer)
double* pcCuTree0 = pcAQLayer0->dCuTreeOffset;
double* pcQP1 = pcAQLayer1->dQpOffset;
double* pcCuTree1 = pcAQLayer1->dCuTreeOffset;
- for (uint32_t y = 0; y <
m_frame[0]->m_fencPic->m_picHeight; y += aqPartHeight)
+ if (m_param->numViews > 1)
{
- for (uint32_t x = 0; x <
m_frame[0]->m_fencPic->m_picWidth; x += aqPartWidth, pcQP0++, pcCuTree0++,
pcQP1++, pcCuTree1++)
+ for (uint32_t y = 0; y <
m_frame[0]->m_fencPic->m_picHeight; y += aqPartHeight)
{
- *pcQP1 = *pcQP0;
- *pcCuTree1 = *pcCuTree0;
+ for (uint32_t x = 0; x <
m_frame[0]->m_fencPic->m_picWidth; x += aqPartWidth, pcQP0++, pcCuTree0++,
pcQP1++, pcCuTree1++)
+ {
+ *pcQP1 = *pcQP0;
+ *pcCuTree1 = *pcCuTree0;
+ }
}
}
+ else if (m_param->numScalableLayers > 1)
+ {
+ int numAQPartInWidth =
(m_frame[0]->m_fencPic->m_picWidth + aqPartWidth - 1) / aqPartWidth;
+ int numAQPartInHeight =
(m_frame[0]->m_fencPic->m_picHeight + aqPartHeight - 1) / aqPartHeight;
+ memset(m_frame[layer]->m_lowres.pAQLayer[d].dQpOffset,
0.0, sizeof(double)*numAQPartInWidth* numAQPartInHeight);
+
memset(m_frame[layer]->m_lowres.pAQLayer[d].dCuTreeOffset, 0.0,
sizeof(double)* numAQPartInWidth* numAQPartInHeight);
+ }
}
}
}
@@ -1213,9 +1231,21 @@ void FrameEncoder::compressFrame(int layer)
/* rateControlEnd may also block for earlier frames to call
rateControlUpdateStats */
if (!layer && m_top->m_rateControl->rateControlEnd(m_frame[layer],
m_accessUnitBits[layer], &m_rce, &filler) < 0)
m_top->m_aborted = true;
-#if ENABLE_ALPHA || ENABLE_MULTIVIEW
- if (!layer && m_frame[layer+1])
- m_frame[1]->m_encData->m_avgQpAq =
m_frame[layer]->m_encData->m_avgQpAq;
+
+#if ENABLE_ALPHA
+ if (layer && m_param->numScalableLayers > 1)
+ m_frame[layer]->m_encData->m_avgQpAq =
m_frame[layer]->m_encData->m_avgQpRc;
+#endif
+#if ENABLE_MULTIVIEW
+ if (layer && m_param->numViews > 1)
+ {
+ double avgQpAq = 0;
+ for (uint32_t i = 0; i < slice->m_sps->numCuInHeight; i++)
+ avgQpAq += m_frame[layer]->m_encData->m_rowStat[i].sumQpAq;
+
+ avgQpAq /= (slice->m_sps->numCUsInFrame *
m_param->num4x4Partitions);
+ m_frame[layer]->m_encData->m_avgQpAq = avgQpAq;
+ }
#endif
if (filler > 0)
--
2.36.0.windows.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20240909/4101e715/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Add-rateontrol-support.patch
Type: application/octet-stream
Size: 5509 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20240909/4101e715/attachment.obj>
More information about the x265-devel
mailing list