[x265] [PATCH]Add: aq-mode 5
Niranjan Bala
niranjan at multicorewareinc.com
Thu Feb 27 09:57:36 CET 2020
# HG changeset patch
# User Niranjan <niranjan at multicorewareinc.com>
# Date 1582528901 -19800
# Mon Feb 24 12:51:41 2020 +0530
# Node ID 1a47c3802fa38bdb4606e3d8203b73b4474d1ce6
# Parent 30eb4de83092bddcb4497a47bc9d2211dfb69cfc
Add: aq-mode 5
This patch does the following:
Add AQ mode 5 which is suitable for frames with dark edge content.
diff -r 30eb4de83092 -r 1a47c3802fa3 doc/reST/cli.rst
--- a/doc/reST/cli.rst Wed Jan 29 12:19:07 2020 +0530
+++ b/doc/reST/cli.rst Mon Feb 24 12:51:41 2020 +0530
@@ -1703,7 +1703,7 @@
ignored. Slower presets will generally achieve better compression
efficiency (and generate smaller bitstreams). Default disabled.
-.. option:: --aq-mode <0|1|2|3|4>
+.. option:: --aq-mode <0|1|2|3|4|5>
Adaptive Quantization operating mode. Raise or lower per-block
quantization based on complexity analysis of the source image. The
@@ -1711,13 +1711,15 @@
the tendency of the encoder to spend too many bits on complex areas
and not enough in flat areas.
- 0. disabled
- 1. AQ enabled
- 2. AQ enabled with auto-variance **(default)**
+ 0. disabled.
+ 1. Uniform AQ.
+ 2. AQ enabled with auto-variance **(default)**.
3. AQ enabled with auto-variance and bias to dark scenes. This is
recommended for 8-bit encodes or low-bitrate 10-bit encodes, to
prevent color banding/blocking.
4. AQ enabled with auto-variance and edge information.
+ 5. Same as AQ mode 3, but uses edge density instead of auto-variance.
+ i.e, AQ with bias towards dark scenes which have high edge density.
.. option:: --aq-strength <float>
diff -r 30eb4de83092 -r 1a47c3802fa3 source/common/frame.cpp
--- a/source/common/frame.cpp Wed Jan 29 12:19:07 2020 +0530
+++ b/source/common/frame.cpp Mon Feb 24 12:51:41 2020 +0530
@@ -103,7 +103,7 @@
CHECKED_MALLOC_ZERO(m_classifyCount, uint32_t, size);
}
- if (param->rc.aqMode == X265_AQ_EDGE || (param->rc.zonefileCount &&
param->rc.aqMode != 0))
+ if (param->rc.aqMode == X265_AQ_EDGE || param->rc.aqMode ==
X265_AQ_EDGE_BIASED || (param->rc.zonefileCount && param->rc.aqMode != 0))
{
uint32_t numCuInWidth = (param->sourceWidth + param->maxCUSize -
1) / param->maxCUSize;
uint32_t numCuInHeight = (param->sourceHeight + param->maxCUSize -
1) / param->maxCUSize;
@@ -276,12 +276,9 @@
X265_FREE_ZERO(m_classifyCount);
}
- if (m_param->rc.aqMode == X265_AQ_EDGE || (m_param->rc.zonefileCount
&& m_param->rc.aqMode != 0))
- {
X265_FREE(m_edgePic);
X265_FREE(m_gaussianPic);
X265_FREE(m_thetaPic);
- }
if (m_param->enableRecursionSkip >= EDGE_BASED_RSKIP)
{
diff -r 30eb4de83092 -r 1a47c3802fa3 source/common/param.cpp
--- a/source/common/param.cpp Wed Jan 29 12:19:07 2020 +0530
+++ b/source/common/param.cpp Mon Feb 24 12:51:41 2020 +0530
@@ -1619,7 +1619,7 @@
"Lookahead depth must be less than 256");
CHECK(param->lookaheadSlices > 16 || param->lookaheadSlices < 0,
"Lookahead slices must between 0 and 16");
- CHECK(param->rc.aqMode < X265_AQ_NONE || X265_AQ_EDGE <
param->rc.aqMode,
+ CHECK(param->rc.aqMode < X265_AQ_NONE || param->rc.aqMode >
X265_AQ_EDGE_BIASED,
"Aq-Mode is out of range");
CHECK(param->rc.aqStrength < 0 || param->rc.aqStrength > 3,
"Aq-Strength is out of range");
diff -r 30eb4de83092 -r 1a47c3802fa3 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp Wed Jan 29 12:19:07 2020 +0530
+++ b/source/encoder/slicetype.cpp Mon Feb 24 12:51:41 2020 +0530
@@ -516,7 +516,7 @@
double bias_strength = 0.f;
double strength = 0.f;
- if (param->rc.aqMode == X265_AQ_EDGE)
+ if (param->rc.aqMode == X265_AQ_EDGE || param->rc.aqMode
== X265_AQ_EDGE_BIASED)
edgeFilter(curFrame, param);
if (param->rc.aqMode == X265_AQ_EDGE &&
!param->bHistBasedSceneCut && param->enableRecursionSkip >=
EDGE_BASED_RSKIP)
@@ -526,7 +526,8 @@
curFrame->m_fencPic->m_stride,
curFrame->m_fencPic->m_picWidth, curFrame->m_fencPic->m_picHeight,
SHIFT_TO_BITPLANE);
}
- if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE ||
param->rc.aqMode == X265_AQ_AUTO_VARIANCE_BIASED || param->rc.aqMode ==
X265_AQ_EDGE)
+ if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE ||
param->rc.aqMode == X265_AQ_AUTO_VARIANCE_BIASED ||
+ param->rc.aqMode == X265_AQ_EDGE || param->rc.aqMode
== X265_AQ_EDGE_BIASED)
{
double bit_depth_correction = 1.f / (1 << (2 *
(X265_DEPTH - 8)));
for (int blockY = 0; blockY < maxRow; blockY +=
loopIncr)
@@ -535,7 +536,7 @@
{
uint32_t energy, edgeDensity, avgAngle;
energy = acEnergyCu(curFrame, blockX, blockY,
param->internalCsp, param->rc.qgSize);
- if (param->rc.aqMode == X265_AQ_EDGE)
+ if (param->rc.aqMode == X265_AQ_EDGE ||
param->rc.aqMode == X265_AQ_EDGE_BIASED)
{
edgeDensity = edgeDensityCu(curFrame,
avgAngle, blockX, blockY, param->rc.qgSize);
if (edgeDensity)
@@ -594,6 +595,15 @@
else
qp_adj = strength * (qp_adj - avg_adj);
}
+ else if (param->rc.aqMode == X265_AQ_EDGE_BIASED)
+ {
+ inclinedEdge =
curFrame->m_lowres.edgeInclined[blockXY];
+ qp_adj =
curFrame->m_lowres.qpCuTreeOffset[blockXY];
+ if (inclinedEdge && (qp_adj - avg_adj > 0))
+ qp_adj = ((strength + AQ_EDGE_BIAS) *
(qp_adj - avg_adj)) + bias_strength * (1.f - modeTwoConst / (qp_adj *
qp_adj));
+ else
+ qp_adj = strength * (qp_adj - avg_adj) +
bias_strength * (1.f - modeTwoConst / (qp_adj * qp_adj));
+ }
else
{
uint32_t energy = acEnergyCu(curFrame, blockX,
blockY, param->internalCsp, param->rc.qgSize);
diff -r 30eb4de83092 -r 1a47c3802fa3 source/test/regression-tests.txt
--- a/source/test/regression-tests.txt Wed Jan 29 12:19:07 2020 +0530
+++ b/source/test/regression-tests.txt Mon Feb 24 12:51:41 2020 +0530
@@ -170,6 +170,7 @@
crowd_run_1080p50.yuv, --preset fast --ctu 64 --rskip 3
--rskip-edge-threshold 5 --aq-mode 4
crowd_run_1080p50.yuv, --preset slow --ctu 32 --rskip 3
--rskip-edge-threshold 5 --hist-scenecut --hist-threshold 0.1
crowd_run_1080p50.yuv, --preset slower --ctu 16 --rskip 3
--rskip-edge-threshold 5 --hist-scenecut --hist-threshold 0.1 --aq-mode 4
+sintel_trailer_2k_1920x1080_24.yuv, --preset medium --aq-mode 5
# Main12 intraCost overflow bug test
720p50_parkrun_ter.y4m,--preset medium
diff -r 30eb4de83092 -r 1a47c3802fa3 source/x265.h
--- a/source/x265.h Wed Jan 29 12:19:07 2020 +0530
+++ b/source/x265.h Mon Feb 24 12:51:41 2020 +0530
@@ -574,6 +574,8 @@
#define X265_AQ_AUTO_VARIANCE 2
#define X265_AQ_AUTO_VARIANCE_BIASED 3
#define X265_AQ_EDGE 4
+#define X265_AQ_EDGE_BIASED 5
+
#define x265_ADAPT_RD_STRENGTH 4
#define X265_REFINE_INTER_LEVELS 3
/* NOTE! For this release only X265_CSP_I420 and X265_CSP_I444 are
supported */
diff -r 30eb4de83092 -r 1a47c3802fa3 source/x265cli.h
--- a/source/x265cli.h Wed Jan 29 12:19:07 2020 +0530
+++ b/source/x265cli.h Mon Feb 24 12:51:41 2020 +0530
@@ -582,7 +582,14 @@
" - 0 : Disabled.\n"
" - 1 : Store/Load ctu
distortion to/from the file specified in analysis-save/load.\n"
" Default 0 - Disabled\n");
- H0(" --aq-mode <integer> Mode for Adaptive Quantization -
0:none 1:uniform AQ 2:auto variance 3:auto variance with bias to dark
scenes 4:auto variance with edge information. Default %d\n",
param->rc.aqMode);
+ H0(" --aq-mode <integer> Mode for Adaptive Quantization.\n"
+ " - 0 : none.\n"
+ " - 1 : uniform AQ.\n"
+ " - 2 : auto variance.\n"
+ " - 3 : auto variance with bias
to dark scenes.\n"
+ " - 4 : auto variance with edge
density.\n"
+ " - 5 : auto variance with edge
density and bias towards dark scenes.\n"
+ " Default %d\n", param->rc.aqMode);
H0(" --[no-]hevc-aq Mode for HEVC Adaptive
Quantization. Default %s\n", OPT(param->rc.hevcAq));
H0(" --aq-strength <float> Reduces blocking and blurring in
flat and textured areas (0 to 3.0). Default %.2f\n", param->rc.aqStrength);
H0(" --qp-adaptation-range <float> Delta QP range by QP adaptation
based on a psycho-visual model (1.0 to 6.0). Default %.2f\n",
param->rc.qpAdaptationRange);
Thanks & Regards
*Niranjan Kumar B*
Video Codec Engineer
Media & AI Analytics
+91 958 511 1449
<https://multicorewareinc.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20200227/e964e87a/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AQMode5.patch
Type: application/octet-stream
Size: 9318 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20200227/e964e87a/attachment-0001.obj>
More information about the x265-devel
mailing list