<div dir="ltr">Pushed to default</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 12, 2019 at 5:38 PM Niranjan Bala <<a href="mailto:niranjan@multicorewareinc.com">niranjan@multicorewareinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"># HG changeset patch<br># User Niranjan <<a href="mailto:niranjan@multicorewareinc.com" target="_blank">niranjan@multicorewareinc.com</a>><br># Date 1572519207 -19800<br># Thu Oct 31 16:23:27 2019 +0530<br># Node ID 64ae069fb0b73338090d1f8e1fdd3ae0f6c03605<br># Parent e4fea011918a09e42bfa6d5c295cf0386c0bec7b<br>Enable Boundary Aware Frame Quantizer Selection<br><br>This patch does the following:<br>1)Reduce bits for frames inside the scenecut-window and increase the quality of<br>scenecut I-frames.<br>2)Add options "--scenecut-aware-qp", "--scenecut-window" and "--max-qp-delta" to<br>enable boundary aware frame quantization, to set window size (optional) and to<br>set offset(optional).<br><br>diff -r e4fea011918a -r 64ae069fb0b7 doc/reST/cli.rst<br>--- a/doc/reST/cli.rst Mon Oct 21 14:27:15 2019 +0530<br>+++ b/doc/reST/cli.rst Thu Oct 31 16:23:27 2019 +0530<br>@@ -1898,6 +1898,28 @@<br> <br> **CLI ONLY**<br> <br>+.. option:: --scenecut-aware-qp, --no-scenecut-aware-qp<br>+ <br>+ Enables a ratecontrol algorithm for reducing the bits spent on the inter-frames<br>+ within the :option:`--scenecut-window` after a scenecut by increasing their QP<br>+ without any deterioration in visual quality. It also increases the quality of<br>+ scenecut I-Frames by reducing their QP. Default disabled.<br>+ <br>+.. option:: --scenecut-window <integer><br>+<br>+ The duration(in milliseconds) for which there is a reduction in the bits spent<br>+ on the inter-frames after a scenecut by increasing their QP, when<br>+ :option:`--scenecut-aware-qp` is enabled. Default 500ms.<br>+ <br>+ **Range of values:** 0 to 1000<br>+ <br>+.. option:: --max-qp-delta <integer><br>+<br>+ The offset by which QP is incremented for inter-frames<br>+ when :option:`--scenecut-aware-qp` is enabled. Default 5.<br>+ <br>+ **Range of values:** 0 to 10<br>+<br> Quantization Options<br> ====================<br> <br>diff -r e4fea011918a -r 64ae069fb0b7 source/CMakeLists.txt<br>--- a/source/CMakeLists.txt Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/CMakeLists.txt Thu Oct 31 16:23:27 2019 +0530<br>@@ -29,7 +29,7 @@<br> option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)<br> mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br> # X265_BUILD must be incremented each time the public API is changed<br>-set(X265_BUILD 181)<br>+set(X265_BUILD 182)<br> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265.def.in" target="_blank">x265.def.in</a>"<br> "${PROJECT_BINARY_DIR}/x265.def")<br> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265_config.h.in" target="_blank">x265_config.h.in</a>"<br>diff -r e4fea011918a -r 64ae069fb0b7 source/common/param.cpp<br>--- a/source/common/param.cpp Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/common/param.cpp Thu Oct 31 16:23:27 2019 +0530<br>@@ -175,6 +175,9 @@<br> param->chunkEnd = 0;<br> param->bEnableHRDConcatFlag = 0;<br> param->bEnableFades = 0;<br>+ param->bEnableSceneCutAwareQp = 0;<br>+ param->scenecutWindow = 500;<br>+ param->maxQpDelta = 5;<br> <br> /* Intra Coding Tools */<br> param->bEnableConstrainedIntra = 0;<br>@@ -1294,6 +1297,9 @@<br> p->selectiveSAO = atoi(value);<br> }<br> OPT("fades") p->bEnableFades = atobool(value);<br>+ OPT("scenecut-aware-qp") p->bEnableSceneCutAwareQp = atobool(value);<br>+ OPT("scenecut-window") p->scenecutWindow = atoi(value);<br>+ OPT("max-qp-delta") p->maxQpDelta = atoi(value);<br> OPT("field") p->bField = atobool( value );<br> OPT("cll") p->bEmitCLL = atobool(value);<br> OPT("frame-dup") p->bEnableFrameDuplication = atobool(value);<br>@@ -1703,6 +1709,10 @@<br> }<br> CHECK(param->selectiveSAO < 0 || param->selectiveSAO > 4,<br> "Invalid SAO tune level. Value must be between 0 and 4 (inclusive)");<br>+ CHECK(param->scenecutWindow < 0 || param->scenecutWindow > 1000,<br>+ "Invalid scenecut Window duration. Value must be between 0 and 1000(inclusive)");<br>+ CHECK(param->maxQpDelta < 0 || param->maxQpDelta > 10,<br>+ "Invalid maxQpDelta value. Value must be between 0 and 10 (inclusive)");<br> #if !X86_64<br> CHECK(param->searchMethod == X265_SEA && (param->sourceWidth > 840 || param->sourceHeight > 480),<br> "SEA motion search does not support resolutions greater than 480p in 32 bit build");<br>@@ -2126,6 +2136,9 @@<br> BOOL(p->bEnableSvtHevc, "svt");<br> BOOL(p->bField, "field");<br> s += sprintf(s, " qp-adaptation-range=%.2f", p->rc.qpAdaptationRange);<br>+ BOOL(p->bEnableSceneCutAwareQp, "scenecut-aware-qp");<br>+ if (p->bEnableSceneCutAwareQp)<br>+ s += sprintf(s, " scenecut-window=%d max-qp-delta=%d", p->scenecutWindow, p->maxQpDelta);<br> #undef BOOL<br> return buf;<br> }<br>@@ -2463,6 +2476,9 @@<br> dst->dolbyProfile = src->dolbyProfile;<br> dst->bEnableSvtHevc = src->bEnableSvtHevc;<br> dst->bEnableFades = src->bEnableFades;<br>+ dst->bEnableSceneCutAwareQp = src->bEnableSceneCutAwareQp;<br>+ dst->scenecutWindow = src->scenecutWindow;<br>+ dst->maxQpDelta = src->maxQpDelta;<br> dst->bField = src->bField;<br> <br> #ifdef SVT_HEVC<br>diff -r e4fea011918a -r 64ae069fb0b7 source/encoder/encoder.cpp<br>--- a/source/encoder/encoder.cpp Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/encoder/encoder.cpp Thu Oct 31 16:23:27 2019 +0530<br>@@ -1894,6 +1894,9 @@<br> frameEnc = m_lookahead->getDecidedPicture();<br> if (frameEnc && !pass && (!m_param->chunkEnd || (m_encodedFrameNum < m_param->chunkEnd)))<br> {<br>+ if (m_param->bEnableSceneCutAwareQp && frameEnc->m_lowres.bScenecut)<br>+ m_rateControl->m_lastScenecut = frameEnc->m_poc;<br>+<br> if (m_param->analysisMultiPassRefine || m_param->analysisMultiPassDistortion)<br> {<br> uint32_t widthInCU = (m_param->sourceWidth + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>diff -r e4fea011918a -r 64ae069fb0b7 source/encoder/ratecontrol.cpp<br>--- a/source/encoder/ratecontrol.cpp Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/encoder/ratecontrol.cpp Thu Oct 31 16:23:27 2019 +0530<br>@@ -173,6 +173,8 @@<br> m_lastPredictorReset = 0;<br> m_avgPFrameQp = 0;<br> m_isFirstMiniGop = false;<br>+ m_lastScenecut = -1;<br>+ m_lastScenecutAwareIFrame = -1;<br> if (m_param->rc.rateControlMode == X265_RC_CRF)<br> {<br> m_param->rc.qp = (int)m_param->rc.rfConstant;<br>@@ -1843,6 +1845,16 @@<br> }<br> rce->qpNoVbv = q;<br> }<br>+ /* Scenecut Aware QP offsets*/<br>+ if (m_param->bEnableSceneCutAwareQp)<br>+ {<br>+ double lqmin = m_lmin[m_sliceType];<br>+ double lqmax = m_lmax[m_sliceType];<br>+ qScale = scenecutAwareQp(curFrame, qScale);<br>+ qScale = x265_clip3(lqmin, lqmax, qScale);<br>+ q = x265_qScale2qp(qScale);<br>+ rce->qpNoVbv = q;<br>+ }<br> if (m_isVbv)<br> {<br> lmin = m_lastQScaleFor[P_SLICE] / m_lstep;<br>@@ -2097,6 +2109,15 @@<br> q = tuneQSacleForZone(rce, q);<br> q = x265_clip3(lqmin, lqmax, q);<br> }<br>+ /* Scenecut Aware QP offsets*/<br>+ if (m_param->bEnableSceneCutAwareQp)<br>+ {<br>+ double qmin = m_lmin[m_sliceType];<br>+ double qmax = m_lmax[m_sliceType];<br>+ q = scenecutAwareQp(curFrame, q);<br>+ q = x265_clip3(qmin, qmax, q);<br>+ rce->qpNoVbv = x265_qScale2qp(q);<br>+ }<br> q = clipQscale(curFrame, rce, q);<br> <br> <br>@@ -3120,3 +3141,52 @@<br> buf = strstr(src, "~");<br> }<br> }<br>+<br>+double RateControl::scenecutAwareQp(Frame* curFrame, double q)<br>+{<br>+ uint32_t maxWindowSize = uint32_t((m_param->scenecutWindow / 1000.0) * (m_param->fpsNum / m_param->fpsDenom) + 0.5);<br>+ uint32_t windowSize = maxWindowSize / 3;<br>+ int lastScenecut = m_top->m_rateControl->m_lastScenecut;<br>+ int lastIFrame = m_top->m_rateControl->m_lastScenecutAwareIFrame;<br>+ double maxQpDelta = x265_qp2qScale(double(m_param->maxQpDelta));<br>+ double iSliceDelta = x265_qp2qScale(double(I_SLICE_DELTA));<br>+ double sliceTypeDelta = SLICE_TYPE_DELTA * maxQpDelta;<br>+ double window2Delta = WINDOW2_DELTA * maxQpDelta;<br>+ double window3Delta = WINDOW3_DELTA * maxQpDelta;<br>+<br>+ bool isFrameInsideWindow = curFrame->m_poc > lastScenecut && curFrame->m_poc <= (lastScenecut + int(maxWindowSize));<br>+<br>+ if (isFrameInsideWindow && IS_X265_TYPE_I(curFrame->m_lowres.sliceType))<br>+ {<br>+ m_top->m_rateControl->m_lastScenecutAwareIFrame = curFrame->m_poc;<br>+ }<br>+ else if (isFrameInsideWindow && (curFrame->m_lowres.sliceType == X265_TYPE_P))<br>+ {<br>+ if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut + int(maxWindowSize))<br>+ && curFrame->m_poc > lastIFrame))<br>+ {<br>+ q += maxQpDelta - sliceTypeDelta;<br>+ if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>+ q -= window2Delta;<br>+ else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))<br>+ q -= window3Delta;<br>+ }<br>+ }<br>+ else if (isFrameInsideWindow && IS_X265_TYPE_B(curFrame->m_lowres.sliceType))<br>+ {<br>+ if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut + int(maxWindowSize))<br>+ && curFrame->m_poc > lastIFrame))<br>+ {<br>+ q += maxQpDelta;<br>+ if (curFrame->m_lowres.sliceType == X265_TYPE_B)<br>+ q += sliceTypeDelta;<br>+ if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>+ q -= window2Delta;<br>+ else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))<br>+ q -= window3Delta;<br>+ }<br>+ }<br>+ if (IS_X265_TYPE_I(curFrame->m_lowres.sliceType) && curFrame->m_lowres.bScenecut)<br>+ q = q - iSliceDelta;<br>+ return q;<br>+}<br>diff -r e4fea011918a -r 64ae069fb0b7 source/encoder/ratecontrol.h<br>--- a/source/encoder/ratecontrol.h Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/encoder/ratecontrol.h Thu Oct 31 16:23:27 2019 +0530<br>@@ -46,6 +46,13 @@<br> #define MIN_AMORTIZE_FRACTION 0.2<br> #define CLIP_DURATION(f) x265_clip3(MIN_FRAME_DURATION, MAX_FRAME_DURATION, f)<br> <br>+/*Scenecut Aware QP*/<br>+#define I_SLICE_DELTA 2 /* Subtracted from base QP for the scenecut I frames*/<br>+#define SLICE_TYPE_DELTA 0.3 /* The offset decremented or incremented for P-frames or b-frames respectively*/<br>+#define WINDOW1_DELTA 0 /* The offset for the frames coming in the window-1*/<br>+#define WINDOW2_DELTA 0.3 /* The offset for the frames coming in the window-2*/<br>+#define WINDOW3_DELTA 0.6 /* The offset for the frames coming in the window-3*/<br>+<br> struct Predictor<br> {<br> double coeffMin;<br>@@ -142,6 +149,8 @@<br> bool m_initVbv;<br> int m_lastAbrResetPoc;<br> <br>+ int m_lastScenecut;<br>+ int m_lastScenecutAwareIFrame;<br> double m_rateTolerance;<br> double m_frameDuration; /* current frame duration in seconds */<br> double m_bitrate;<br>@@ -261,6 +270,8 @@<br> int writeRateControlFrameStats(Frame* curFrame, RateControlEntry* rce);<br> bool initPass2();<br> <br>+ double scenecutAwareQp(Frame* curFrame, double q);<br>+<br> protected:<br> <br> static const int s_slidingWindowFrames;<br>diff -r e4fea011918a -r 64ae069fb0b7 source/test/regression-tests.txt<br>--- a/source/test/regression-tests.txt Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/test/regression-tests.txt Thu Oct 31 16:23:27 2019 +0530<br>@@ -158,6 +158,7 @@<br> ducks_take_off_420_1_720p50.y4m,--preset medium --selective-sao 4 --sao --crf 20<br> Traffic_4096x2048_30p.y4m, --preset medium --frame-dup --dup-threshold 60 --hrd --bitrate 10000 --vbv-bufsize 15000 --vbv-maxrate 12000<br> Kimono1_1920x1080_24_400.yuv,--preset superfast --qp 28 --zones 0,139,q=32<br>+Island_960x540_420p_8bit_24fps.yuv,--no-cutree --aq-mode 0 --bitrate 6000 --scenecut-aware-qp<br> <br> # Main12 intraCost overflow bug test<br> 720p50_parkrun_ter.y4m,--preset medium<br>diff -r e4fea011918a -r 64ae069fb0b7 source/x265.h<br>--- a/source/x265.h Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/x265.h Thu Oct 31 16:23:27 2019 +0530<br>@@ -1832,6 +1832,20 @@<br> /*Flag to indicate if rate-control history has to be reset during zone reconfiguration.<br> Default 1 (Enabled). API only. */<br> int bResetZoneConfig;<br>+<br>+ /* Enables a ratecontrol algorithm for reducing the bits spent on the inter-frames<br>+ * within the scenecutWindow after a scenecut by increasing their QP without<br>+ * any deterioration in visual quality. It also increases the quality of scenecut I-Frames by reducing their QP.<br>+ * Default is disabled. */<br>+ int bEnableSceneCutAwareQp;<br>+<br>+ /*The duration(in milliseconds) for which there is a reduction in the bits spent on the inter-frames after a scenecut<br>+ * by increasing their QP, when bEnableSceneCutAwareQp is set. Default is 500ms.*/<br>+ int scenecutWindow;<br>+<br>+ /* The offset by which QP is incremented for inter-frames when bEnableSceneCutAwareQp is set.<br>+ * Default is +5. */<br>+ int maxQpDelta;<br> } x265_param;<br> /* x265_param_alloc:<br> * Allocates an x265_param instance. The returned param structure is not<br>diff -r e4fea011918a -r 64ae069fb0b7 source/x265cli.h<br>--- a/source/x265cli.h Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/x265cli.h Thu Oct 31 16:23:27 2019 +0530<br>@@ -131,6 +131,10 @@<br> { "scenecut-bias", required_argument, NULL, 0 },<br> { "fades", no_argument, NULL, 0 },<br> { "no-fades", no_argument, NULL, 0 },<br>+ { "scenecut-aware-qp", no_argument, NULL, 0 },<br>+ { "no-scenecut-aware-qp", no_argument, NULL, 0 },<br>+ { "scenecut-window",required_argument, NULL, 0 },<br>+ { "max-qp-delta", required_argument, NULL, 0 },<br> { "radl", required_argument, NULL, 0 },<br> { "ctu-info", required_argument, NULL, 0 },<br> { "intra-refresh", no_argument, NULL, 0 },<br>@@ -487,6 +491,9 @@<br> H0(" --scenecut <integer> How aggressively to insert extra I-frames. Default %d\n", param->scenecutThreshold);<br> H1(" --scenecut-bias <0..100.0> Bias for scenecut detection. Default %.2f\n", param->scenecutBias);<br> H0(" --[no-]fades Enable detection and handling of fade-in regions. Default %s\n", OPT(param->bEnableFades));<br>+ H1(" --[no-]scenecut-aware-qp Enable increasing QP for frames inside the scenecut window after scenecut. Default %s\n", OPT(param->bEnableSceneCutAwareQp));<br>+ H1(" --scenecut-window <0..1000> QP incremental duration(in milliseconds) when scenecut-aware-qp is enabled. Default %d\n", param->scenecutWindow);<br>+ H1(" --max-qp-delta <0..10> QP offset to increment with base QP for inter-frames. Default %d\n", param->maxQpDelta);<br> H0(" --radl <integer> Number of RADL pictures allowed in front of IDR. Default %d\n", param->radl);<br> H0(" --intra-refresh Use Periodic Intra Refresh instead of IDR frames\n");<br> H0(" --rc-lookahead <integer> Number of frames for frame-type lookahead (determines encoder latency) Default %d\n", param->lookaheadDepth);<br><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><font color="#0c343d" face="verdana, sans-serif">Thanks & Regards</font><div><font color="#0c343d" face="verdana, sans-serif"><b>Niranjan Kumar B</b></font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Video Codec Engineer </font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Media & AI Analytics</font></div><div><font face="trebuchet ms, sans-serif" color="#0c343d">+91 958 511 1449</font></div><div><a href="https://multicorewareinc.com/" style="color:rgb(17,85,204)" target="_blank"><img src="https://docs.google.com/uc?export=download&id=1kc3RJu9M8bnIf6Xa5rUw2d-eEVUsPBE5&revid=0B7tw9XJBmynaemR1VUpQUi9DVytRVW5SVkRwVTFjb1hBMUcwPQ"></a></div></div></div></div></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 7, 2019 at 12:04 PM Niranjan Bala <<a href="mailto:niranjan@multicorewareinc.com" target="_blank">niranjan@multicorewareinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"># HG changeset patch<br># User Niranjan <<a href="mailto:niranjan@multicorewareinc.com" target="_blank">niranjan@multicorewareinc.com</a>><br># Date 1572519207 -19800<br># Thu Oct 31 16:23:27 2019 +0530<br># Node ID 38865a56650c4bdc15c1c932adf658d1a3174d93<br># Parent e4fea011918a09e42bfa6d5c295cf0386c0bec7b<br>Enable Boundary Aware Frame Quantizer Selection<br><br>This patch does the following:<br>1)Reduce bits for frames inside the scenecut-window.<br>2)Add options "--scenecut-aware-qp", "--scenecut-window" and "--max-qp-delta" to<br>enable boundary aware frame quantization, to set window size (optional) and to<br>set offset(optional).<br><br>diff -r e4fea011918a -r 38865a56650c doc/reST/cli.rst<br>--- a/doc/reST/cli.rst Mon Oct 21 14:27:15 2019 +0530<br>+++ b/doc/reST/cli.rst Thu Oct 31 16:23:27 2019 +0530<br>@@ -1898,6 +1898,27 @@<br> <br> **CLI ONLY**<br> <br>+.. option:: --scenecut-aware-qp, --no-scenecut-aware-qp<br>+ <br>+ Increase QP for inter-frames after a scenecut is detected, for a specified duration,<br>+ which is set by the --scenecut-window. Decrease QP for scenecut I-Frames.<br>+ Default: disabled.<br>+ <br>+.. option:: --scenecut-window <integer><br>+<br>+ The duration(in milliseconds) for which the QP is incremented for inter-frames<br>+ when --scenecut-aware-qp is enabled.<br>+ Default 500ms.<br>+ <br>+ **Range of values:** 0 to 1000<br>+ <br>+.. option:: --max-qp-delta <integer><br>+<br>+ The offset by which QP is incremented for inter-frames<br>+ when --scenecut-aware-qp is enabled. Default 5.<br>+ <br>+ **Range of values:** 0 to 10<br>+<br> Quantization Options<br> ====================<br> <br>diff -r e4fea011918a -r 38865a56650c source/CMakeLists.txt<br>--- a/source/CMakeLists.txt Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/CMakeLists.txt Thu Oct 31 16:23:27 2019 +0530<br>@@ -29,7 +29,7 @@<br> option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)<br> mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br> # X265_BUILD must be incremented each time the public API is changed<br>-set(X265_BUILD 181)<br>+set(X265_BUILD 182)<br> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265.def.in" target="_blank">x265.def.in</a>"<br> "${PROJECT_BINARY_DIR}/x265.def")<br> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265_config.h.in" target="_blank">x265_config.h.in</a>"<br>diff -r e4fea011918a -r 38865a56650c source/common/param.cpp<br>--- a/source/common/param.cpp Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/common/param.cpp Thu Oct 31 16:23:27 2019 +0530<br>@@ -175,6 +175,9 @@<br> param->chunkEnd = 0;<br> param->bEnableHRDConcatFlag = 0;<br> param->bEnableFades = 0;<br>+ param->bEnableSceneCutAwareQp = 0;<br>+ param->scenecutWindow = 500;<br>+ param->maxQpDelta = 5;<br> <br> /* Intra Coding Tools */<br> param->bEnableConstrainedIntra = 0;<br>@@ -1294,6 +1297,9 @@<br> p->selectiveSAO = atoi(value);<br> }<br> OPT("fades") p->bEnableFades = atobool(value);<br>+ OPT("scenecut-aware-qp") p->bEnableSceneCutAwareQp = atobool(value);<br>+ OPT("scenecut-window") p->scenecutWindow = atoi(value);<br>+ OPT("max-qp-delta") p->maxQpDelta = atoi(value);<br> OPT("field") p->bField = atobool( value );<br> OPT("cll") p->bEmitCLL = atobool(value);<br> OPT("frame-dup") p->bEnableFrameDuplication = atobool(value);<br>@@ -1703,6 +1709,10 @@<br> }<br> CHECK(param->selectiveSAO < 0 || param->selectiveSAO > 4,<br> "Invalid SAO tune level. Value must be between 0 and 4 (inclusive)");<br>+ CHECK(param->scenecutWindow < 0 || param->scenecutWindow > 1000,<br>+ "Invalid scenecut Window duration. Value must be between 0 and 1000(inclusive)");<br>+ CHECK(param->maxQpDelta < 0 || param->maxQpDelta > 10,<br>+ "Invalid maxQpDelta value. Value must be between 0 and 10 (inclusive)");<br> #if !X86_64<br> CHECK(param->searchMethod == X265_SEA && (param->sourceWidth > 840 || param->sourceHeight > 480),<br> "SEA motion search does not support resolutions greater than 480p in 32 bit build");<br>@@ -2126,6 +2136,9 @@<br> BOOL(p->bEnableSvtHevc, "svt");<br> BOOL(p->bField, "field");<br> s += sprintf(s, " qp-adaptation-range=%.2f", p->rc.qpAdaptationRange);<br>+ BOOL(p->bEnableSceneCutAwareQp, "scenecut-aware-qp");<br>+ if (p->bEnableSceneCutAwareQp)<br>+ s += sprintf(s, " scenecut-window=%d max-qp-delta=%d", p->scenecutWindow, p->maxQpDelta);<br> #undef BOOL<br> return buf;<br> }<br>@@ -2463,6 +2476,9 @@<br> dst->dolbyProfile = src->dolbyProfile;<br> dst->bEnableSvtHevc = src->bEnableSvtHevc;<br> dst->bEnableFades = src->bEnableFades;<br>+ dst->bEnableSceneCutAwareQp = src->bEnableSceneCutAwareQp;<br>+ dst->scenecutWindow = src->scenecutWindow;<br>+ dst->maxQpDelta = src->maxQpDelta;<br> dst->bField = src->bField;<br> <br> #ifdef SVT_HEVC<br>diff -r e4fea011918a -r 38865a56650c source/encoder/encoder.cpp<br>--- a/source/encoder/encoder.cpp Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/encoder/encoder.cpp Thu Oct 31 16:23:27 2019 +0530<br>@@ -1891,7 +1891,11 @@<br> /* pop a single frame from decided list, then provide to frame encoder<br> * curEncoder is guaranteed to be idle at this point */<br> if (!pass)<br>+ {<br> frameEnc = m_lookahead->getDecidedPicture();<br>+ if (m_param->bEnableSceneCutAwareQp && frameEnc && frameEnc->m_lowres.bScenecut)<br>+ m_rateControl->m_lastScenecut = frameEnc->m_poc;<br>+ }<br> if (frameEnc && !pass && (!m_param->chunkEnd || (m_encodedFrameNum < m_param->chunkEnd)))<br> {<br> if (m_param->analysisMultiPassRefine || m_param->analysisMultiPassDistortion)<br>diff -r e4fea011918a -r 38865a56650c source/encoder/ratecontrol.cpp<br>--- a/source/encoder/ratecontrol.cpp Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/encoder/ratecontrol.cpp Thu Oct 31 16:23:27 2019 +0530<br>@@ -173,6 +173,8 @@<br> m_lastPredictorReset = 0;<br> m_avgPFrameQp = 0;<br> m_isFirstMiniGop = false;<br>+ m_lastScenecut = -1;<br>+ m_lastScenecutAwareIFrame = -1;<br> if (m_param->rc.rateControlMode == X265_RC_CRF)<br> {<br> m_param->rc.qp = (int)m_param->rc.rfConstant;<br>@@ -1843,6 +1845,13 @@<br> }<br> rce->qpNoVbv = q;<br> }<br>+ /* Scenecut Aware QP offsets*/<br>+ if (m_param->bEnableSceneCutAwareQp)<br>+ {<br>+ qScale = scenecutAwareQp(curFrame, qScale);<br>+ q = x265_qScale2qp(qScale);<br>+ rce->qpNoVbv = q;<br>+ }<br> if (m_isVbv)<br> {<br> lmin = m_lastQScaleFor[P_SLICE] / m_lstep;<br>@@ -2097,6 +2106,12 @@<br> q = tuneQSacleForZone(rce, q);<br> q = x265_clip3(lqmin, lqmax, q);<br> }<br>+ /* Scenecut Aware QP offsets*/<br>+ if (m_param->bEnableSceneCutAwareQp)<br>+ {<br>+ q = scenecutAwareQp(curFrame, q);<br>+ rce->qpNoVbv = x265_qScale2qp(q);<br>+ }<br> q = clipQscale(curFrame, rce, q);<br> <br> <br>@@ -3120,3 +3135,52 @@<br> buf = strstr(src, "~");<br> }<br> }<br>+<br>+double RateControl::scenecutAwareQp(Frame* curFrame, double q)<br>+{<br>+ uint32_t maxWindowSize = uint32_t((m_param->scenecutWindow / 1000.0) * (m_param->fpsNum / m_param->fpsDenom) + 0.5);<br>+ uint32_t windowSize = maxWindowSize / 3;<br>+ int lastScenecut = m_top->m_rateControl->m_lastScenecut;<br>+ int lastIFrame = m_top->m_rateControl->m_lastScenecutAwareIFrame;<br>+ double maxQpDelta = x265_qp2qScale(double(m_param->maxQpDelta));<br>+ double iSliceDelta = x265_qp2qScale(double(I_SLICE_DELTA));<br>+ double sliceTypeDelta = SLICE_TYPE_DELTA * maxQpDelta;<br>+ double window2Delta = WINDOW2_DELTA * maxQpDelta;<br>+ double window3Delta = WINDOW3_DELTA * maxQpDelta;<br>+<br>+ bool isFrameInsideWindow = curFrame->m_poc > lastScenecut && curFrame->m_poc <= (lastScenecut + int(maxWindowSize));<br>+<br>+ if (isFrameInsideWindow && IS_X265_TYPE_I(curFrame->m_lowres.sliceType))<br>+ {<br>+ m_top->m_rateControl->m_lastScenecutAwareIFrame = curFrame->m_poc;<br>+ }<br>+ else if (isFrameInsideWindow && (curFrame->m_lowres.sliceType == X265_TYPE_P))<br>+ {<br>+ if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut + int(maxWindowSize))<br>+ && curFrame->m_poc > lastIFrame))<br>+ {<br>+ q += maxQpDelta - sliceTypeDelta;<br>+ if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>+ q -= window2Delta;<br>+ else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))<br>+ q -= window3Delta;<br>+ }<br>+ }<br>+ else if (isFrameInsideWindow && IS_X265_TYPE_B(curFrame->m_lowres.sliceType))<br>+ {<br>+ if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut + int(maxWindowSize))<br>+ && curFrame->m_poc > lastIFrame))<br>+ {<br>+ q += maxQpDelta;<br>+ if (curFrame->m_lowres.sliceType == X265_TYPE_B)<br>+ q += sliceTypeDelta;<br>+ if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>+ q -= window2Delta;<br>+ else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))<br>+ q -= window3Delta;<br>+ }<br>+ }<br>+ if (IS_X265_TYPE_I(curFrame->m_lowres.sliceType) && curFrame->m_lowres.bScenecut)<br>+ q = q - iSliceDelta;<br>+ return q;<br>+}<br>diff -r e4fea011918a -r 38865a56650c source/encoder/ratecontrol.h<br>--- a/source/encoder/ratecontrol.h Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/encoder/ratecontrol.h Thu Oct 31 16:23:27 2019 +0530<br>@@ -46,6 +46,13 @@<br> #define MIN_AMORTIZE_FRACTION 0.2<br> #define CLIP_DURATION(f) x265_clip3(MIN_FRAME_DURATION, MAX_FRAME_DURATION, f)<br> <br>+/*Scenecut Aware QP*/<br>+#define I_SLICE_DELTA 2 /* Subtracted from base QP for the scenecut I frames*/<br>+#define SLICE_TYPE_DELTA 0.3 /* The offset decremented or incremented for P-frames or b-frames respectively*/<br>+#define WINDOW1_DELTA 0 /* The offset for the frames coming in the window-1*/<br>+#define WINDOW2_DELTA 0.3 /* The offset for the frames coming in the window-2*/<br>+#define WINDOW3_DELTA 0.6 /* The offset for the frames coming in the window-3*/<br>+<br> struct Predictor<br> {<br> double coeffMin;<br>@@ -142,6 +149,8 @@<br> bool m_initVbv;<br> int m_lastAbrResetPoc;<br> <br>+ int m_lastScenecut;<br>+ int m_lastScenecutAwareIFrame;<br> double m_rateTolerance;<br> double m_frameDuration; /* current frame duration in seconds */<br> double m_bitrate;<br>@@ -261,6 +270,8 @@<br> int writeRateControlFrameStats(Frame* curFrame, RateControlEntry* rce);<br> bool initPass2();<br> <br>+ double scenecutAwareQp(Frame* curFrame, double q);<br>+<br> protected:<br> <br> static const int s_slidingWindowFrames;<br>diff -r e4fea011918a -r 38865a56650c source/test/regression-tests.txt<br>--- a/source/test/regression-tests.txt Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/test/regression-tests.txt Thu Oct 31 16:23:27 2019 +0530<br>@@ -158,6 +158,7 @@<br> ducks_take_off_420_1_720p50.y4m,--preset medium --selective-sao 4 --sao --crf 20<br> Traffic_4096x2048_30p.y4m, --preset medium --frame-dup --dup-threshold 60 --hrd --bitrate 10000 --vbv-bufsize 15000 --vbv-maxrate 12000<br> Kimono1_1920x1080_24_400.yuv,--preset superfast --qp 28 --zones 0,139,q=32<br>+Island_960x540_420p_8bit_24fps.yuv,--no-cutree --aq-mode 0 --bitrate 6000 --scenecut-aware-qp<br> <br> # Main12 intraCost overflow bug test<br> 720p50_parkrun_ter.y4m,--preset medium<br>diff -r e4fea011918a -r 38865a56650c source/x265.h<br>--- a/source/x265.h Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/x265.h Thu Oct 31 16:23:27 2019 +0530<br>@@ -1832,6 +1832,18 @@<br> /*Flag to indicate if rate-control history has to be reset during zone reconfiguration.<br> Default 1 (Enabled). API only. */<br> int bResetZoneConfig;<br>+<br>+ /* Increase QP for inter-frames after a scenecut is detected, for a specified duration.<br>+ * Default is disabled. */<br>+ int bEnableSceneCutAwareQp;<br>+<br>+ /*The duration(in milliseconds) for which the QP is incremented for inter-frames when bEnableSceneCutAwareQp is set.<br>+ * Default 500ms.*/<br>+ int scenecutWindow;<br>+<br>+ /* The offset by which QP is incremented for inter-frames when bEnableSceneCutAwareQp is set.<br>+ * Default is +5. */<br>+ int maxQpDelta;<br> } x265_param;<br> /* x265_param_alloc:<br> * Allocates an x265_param instance. The returned param structure is not<br>diff -r e4fea011918a -r 38865a56650c source/x265cli.h<br>--- a/source/x265cli.h Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/x265cli.h Thu Oct 31 16:23:27 2019 +0530<br>@@ -131,6 +131,10 @@<br> { "scenecut-bias", required_argument, NULL, 0 },<br> { "fades", no_argument, NULL, 0 },<br> { "no-fades", no_argument, NULL, 0 },<br>+ { "scenecut-aware-qp", no_argument, NULL, 0 },<br>+ { "no-scenecut-aware-qp", no_argument, NULL, 0 },<br>+ { "scenecut-window",required_argument, NULL, 0 },<br>+ { "max-qp-delta", required_argument, NULL, 0 },<br> { "radl", required_argument, NULL, 0 },<br> { "ctu-info", required_argument, NULL, 0 },<br> { "intra-refresh", no_argument, NULL, 0 },<br>@@ -487,6 +491,9 @@<br> H0(" --scenecut <integer> How aggressively to insert extra I-frames. Default %d\n", param->scenecutThreshold);<br> H1(" --scenecut-bias <0..100.0> Bias for scenecut detection. Default %.2f\n", param->scenecutBias);<br> H0(" --[no-]fades Enable detection and handling of fade-in regions. Default %s\n", OPT(param->bEnableFades));<br>+ H1(" --[no-]scenecut-aware-qp Enable increasing QP for frames inside the scenecut window after scenecut. Default %s\n", OPT(param->bEnableSceneCutAwareQp));<br>+ H1(" --scenecut-window <0..1000> QP incremental duration(in milliseconds) when scenecut-aware-qp is enabled. Default %d\n", param->scenecutWindow);<br>+ H1(" --max-qp-delta <0..10> QP offset to increment with base QP for inter-frames. Default %d\n", param->maxQpDelta);<br> H0(" --radl <integer> Number of RADL pictures allowed in front of IDR. Default %d\n", param->radl);<br> H0(" --intra-refresh Use Periodic Intra Refresh instead of IDR frames\n");<br> H0(" --rc-lookahead <integer> Number of frames for frame-type lookahead (determines encoder latency) Default %d\n", param->lookaheadDepth);<br><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><font color="#0c343d" face="verdana, sans-serif">Thanks & Regards</font><div><font color="#0c343d" face="verdana, sans-serif"><b>Niranjan Kumar B</b></font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Video Codec Engineer </font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Media & AI Analytics</font></div><div><font face="trebuchet ms, sans-serif" color="#0c343d">+91 958 511 1449</font></div><div><a href="https://multicorewareinc.com/" style="color:rgb(17,85,204)" target="_blank"><img src="https://docs.google.com/uc?export=download&id=1kc3RJu9M8bnIf6Xa5rUw2d-eEVUsPBE5&revid=0B7tw9XJBmynaemR1VUpQUi9DVytRVW5SVkRwVTFjb1hBMUcwPQ"></a></div></div></div></div></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 7, 2019 at 12:02 PM Niranjan Bala <<a href="mailto:niranjan@multicorewareinc.com" target="_blank">niranjan@multicorewareinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Please ignore the above patch(sent on Nov 5 2019).<div><br clear="all"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><font color="#0c343d" face="verdana, sans-serif">Thanks & Regards</font><div><font color="#0c343d" face="verdana, sans-serif"><b>Niranjan Kumar B</b></font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Video Codec Engineer </font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Media & AI Analytics</font></div><div><font face="trebuchet ms, sans-serif" color="#0c343d">+91 958 511 1449</font></div><div><a href="https://multicorewareinc.com/" style="color:rgb(17,85,204)" target="_blank"><img src="https://docs.google.com/uc?export=download&id=1kc3RJu9M8bnIf6Xa5rUw2d-eEVUsPBE5&revid=0B7tw9XJBmynaemR1VUpQUi9DVytRVW5SVkRwVTFjb1hBMUcwPQ"></a></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 5, 2019 at 7:14 PM Niranjan Bala <<a href="mailto:niranjan@multicorewareinc.com" target="_blank">niranjan@multicorewareinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"># HG changeset patch<br># User Niranjan <<a href="mailto:niranjan@multicorewareinc.com" target="_blank">niranjan@multicorewareinc.com</a>><br># Date 1572519207 -19800<br># Thu Oct 31 16:23:27 2019 +0530<br># Node ID aa1501c6ab8063693fbcd520dd8a772946dfa39f<br># Parent e4fea011918a09e42bfa6d5c295cf0386c0bec7b<br>Enable Boundary Aware Frame Quantizer Selection<br><br>CLI options:<br>1)scenecut-aware-qp<br>2)scenecut-window<br>3)max-qp-delta<br><br>diff -r e4fea011918a -r aa1501c6ab80 doc/reST/cli.rst<br>--- a/doc/reST/cli.rst Mon Oct 21 14:27:15 2019 +0530<br>+++ b/doc/reST/cli.rst Thu Oct 31 16:23:27 2019 +0530<br>@@ -1898,6 +1898,27 @@<br> <br> **CLI ONLY**<br> <br>+.. option:: --scenecut-aware-qp, --no-scenecut-aware-qp<br>+ <br>+ Increase QP for inter-frames after a scenecut is detected, for a specified duration,<br>+ which is set by the --scenecut-window. Decrease QP for scenecut I-Frames.<br>+ Default: disabled.<br>+ <br>+.. option:: --scenecut-window <integer><br>+<br>+ The duration(in milliseconds) for which the QP is incremented for inter-frames<br>+ when --scenecut-aware-qp is enabled.<br>+ Default 500ms.<br>+ <br>+ **Range of values:** 0 to 1000<br>+ <br>+.. option:: --max-qp-delta <integer><br>+<br>+ The base offset by which QP is incremented for inter-frames<br>+ when --scenecut-aware-qp is enabled. Default 5.<br>+ <br>+ **Range of values:** 0 to 10<br>+<br> Quantization Options<br> ====================<br> <br>diff -r e4fea011918a -r aa1501c6ab80 source/CMakeLists.txt<br>--- a/source/CMakeLists.txt Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/CMakeLists.txt Thu Oct 31 16:23:27 2019 +0530<br>@@ -29,7 +29,7 @@<br> option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)<br> mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br> # X265_BUILD must be incremented each time the public API is changed<br>-set(X265_BUILD 181)<br>+set(X265_BUILD 182)<br> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265.def.in" target="_blank">x265.def.in</a>"<br> "${PROJECT_BINARY_DIR}/x265.def")<br> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265_config.h.in" target="_blank">x265_config.h.in</a>"<br>diff -r e4fea011918a -r aa1501c6ab80 source/common/param.cpp<br>--- a/source/common/param.cpp Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/common/param.cpp Thu Oct 31 16:23:27 2019 +0530<br>@@ -175,6 +175,9 @@<br> param->chunkEnd = 0;<br> param->bEnableHRDConcatFlag = 0;<br> param->bEnableFades = 0;<br>+ param->bEnableSceneCutAwareQp = 0;<br>+ param->scenecutWindow = 500;<br>+ param->maxQpDelta = 5;<br> <br> /* Intra Coding Tools */<br> param->bEnableConstrainedIntra = 0;<br>@@ -1294,6 +1297,9 @@<br> p->selectiveSAO = atoi(value);<br> }<br> OPT("fades") p->bEnableFades = atobool(value);<br>+ OPT("scenecut-aware-qp") p->bEnableSceneCutAwareQp = atobool(value);<br>+ OPT("scenecut-window") p->scenecutWindow = atoi(value);<br>+ OPT("max-qp-delta") p->maxQpDelta = atoi(value);<br> OPT("field") p->bField = atobool( value );<br> OPT("cll") p->bEmitCLL = atobool(value);<br> OPT("frame-dup") p->bEnableFrameDuplication = atobool(value);<br>@@ -1703,6 +1709,10 @@<br> }<br> CHECK(param->selectiveSAO < 0 || param->selectiveSAO > 4,<br> "Invalid SAO tune level. Value must be between 0 and 4 (inclusive)");<br>+ CHECK(param->scenecutWindow < 0 || param->scenecutWindow > 1000,<br>+ "Invalid scenecut Window duration. Value must be between 0 and 1000(inclusive)");<br>+ CHECK(param->maxQpDelta < 0 || param->maxQpDelta > 10,<br>+ "Invalid maxQpDelta value. Value must be between 0 and 10 (inclusive)");<br> #if !X86_64<br> CHECK(param->searchMethod == X265_SEA && (param->sourceWidth > 840 || param->sourceHeight > 480),<br> "SEA motion search does not support resolutions greater than 480p in 32 bit build");<br>@@ -2126,6 +2136,9 @@<br> BOOL(p->bEnableSvtHevc, "svt");<br> BOOL(p->bField, "field");<br> s += sprintf(s, " qp-adaptation-range=%.2f", p->rc.qpAdaptationRange);<br>+ BOOL(p->bEnableSceneCutAwareQp, "scenecut-aware-qp");<br>+ if (p->bEnableSceneCutAwareQp)<br>+ s += sprintf(s, " scenecut-window=%d max-qp-delta=%d", p->scenecutWindow, p->maxQpDelta);<br> #undef BOOL<br> return buf;<br> }<br>@@ -2463,6 +2476,9 @@<br> dst->dolbyProfile = src->dolbyProfile;<br> dst->bEnableSvtHevc = src->bEnableSvtHevc;<br> dst->bEnableFades = src->bEnableFades;<br>+ dst->bEnableSceneCutAwareQp = src->bEnableSceneCutAwareQp;<br>+ dst->scenecutWindow = src->scenecutWindow;<br>+ dst->maxQpDelta = src->maxQpDelta;<br> dst->bField = src->bField;<br> <br> #ifdef SVT_HEVC<br>diff -r e4fea011918a -r aa1501c6ab80 source/encoder/encoder.cpp<br>--- a/source/encoder/encoder.cpp Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/encoder/encoder.cpp Thu Oct 31 16:23:27 2019 +0530<br>@@ -1891,7 +1891,11 @@<br> /* pop a single frame from decided list, then provide to frame encoder<br> * curEncoder is guaranteed to be idle at this point */<br> if (!pass)<br>+ {<br> frameEnc = m_lookahead->getDecidedPicture();<br>+ if (m_param->bEnableSceneCutAwareQp && frameEnc && frameEnc->m_lowres.bScenecut)<br>+ m_rateControl->m_lastScenecut = frameEnc->m_poc;<br>+ }<br> if (frameEnc && !pass && (!m_param->chunkEnd || (m_encodedFrameNum < m_param->chunkEnd)))<br> {<br> if (m_param->analysisMultiPassRefine || m_param->analysisMultiPassDistortion)<br>diff -r e4fea011918a -r aa1501c6ab80 source/encoder/ratecontrol.cpp<br>--- a/source/encoder/ratecontrol.cpp Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/encoder/ratecontrol.cpp Thu Oct 31 16:23:27 2019 +0530<br>@@ -173,6 +173,8 @@<br> m_lastPredictorReset = 0;<br> m_avgPFrameQp = 0;<br> m_isFirstMiniGop = false;<br>+ m_lastScenecut = -1;<br>+ m_lastScenecutAwareIFrame = -1;<br> if (m_param->rc.rateControlMode == X265_RC_CRF)<br> {<br> m_param->rc.qp = (int)m_param->rc.rfConstant;<br>@@ -1843,6 +1845,13 @@<br> }<br> rce->qpNoVbv = q;<br> }<br>+ /* Scenecut Aware QP offsets*/<br>+ if (m_param->bEnableSceneCutAwareQp)<br>+ {<br>+ qScale = scenecutAwareQp(curFrame, qScale);<br>+ q = x265_qScale2qp(qScale);<br>+ rce->qpNoVbv = q;<br>+ }<br> if (m_isVbv)<br> {<br> lmin = m_lastQScaleFor[P_SLICE] / m_lstep;<br>@@ -2097,6 +2106,12 @@<br> q = tuneQSacleForZone(rce, q);<br> q = x265_clip3(lqmin, lqmax, q);<br> }<br>+ /* Scenecut Aware QP offsets*/<br>+ if (m_param->bEnableSceneCutAwareQp)<br>+ {<br>+ q = scenecutAwareQp(curFrame, q);<br>+ rce->qpNoVbv = x265_qScale2qp(q);<br>+ }<br> q = clipQscale(curFrame, rce, q);<br> <br> <br>@@ -3120,3 +3135,52 @@<br> buf = strstr(src, "~");<br> }<br> }<br>+<br>+double RateControl::scenecutAwareQp(Frame* curFrame, double q)<br>+{<br>+ uint32_t maxWindowSize = uint32_t((m_param->scenecutWindow / 1000.0) * (m_param->fpsNum / m_param->fpsDenom) + 0.5);<br>+ uint32_t windowSize = maxWindowSize / 3;<br>+ int lastScenecut = m_top->m_rateControl->m_lastScenecut;<br>+ int lastIFrame = m_top->m_rateControl->m_lastScenecutAwareIFrame;<br>+ double maxQpDelta = x265_qp2qScale(double(m_param->maxQpDelta));<br>+ double iSliceDelta = x265_qp2qScale(double(I_SLICE_DELTA));<br>+ double sliceTypeDelta = SLICE_TYPE_DELTA * maxQpDelta;<br>+ double window2Delta = WINDOW2_DELTA * maxQpDelta;<br>+ double window3Delta = WINDOW3_DELTA * maxQpDelta;<br>+<br>+ bool isFrameInsideWindow = curFrame->m_poc > lastScenecut && curFrame->m_poc <= (lastScenecut + int(maxWindowSize));<br>+<br>+ if (isFrameInsideWindow && IS_X265_TYPE_I(curFrame->m_lowres.sliceType))<br>+ {<br>+ m_top->m_rateControl->m_lastScenecutAwareIFrame = curFrame->m_poc;<br>+ }<br>+ else if (isFrameInsideWindow && (curFrame->m_lowres.sliceType == X265_TYPE_P))<br>+ {<br>+ if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut + int(maxWindowSize))<br>+ && curFrame->m_poc > lastIFrame))<br>+ {<br>+ q += maxQpDelta - sliceTypeDelta;<br>+ if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>+ q -= window2Delta;<br>+ else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))<br>+ q -= window3Delta;<br>+ }<br>+ }<br>+ else if (isFrameInsideWindow && IS_X265_TYPE_B(curFrame->m_lowres.sliceType))<br>+ {<br>+ if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut + int(maxWindowSize))<br>+ && curFrame->m_poc > lastIFrame))<br>+ {<br>+ q += maxQpDelta;<br>+ if (curFrame->m_lowres.sliceType == X265_TYPE_B)<br>+ q += sliceTypeDelta;<br>+ if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>+ q -= window2Delta;<br>+ else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))<br>+ q -= window3Delta;<br>+ }<br>+ }<br>+ if (IS_X265_TYPE_I(curFrame->m_lowres.sliceType) && curFrame->m_lowres.bScenecut)<br>+ q = q - iSliceDelta;<br>+ return q;<br>+}<br>diff -r e4fea011918a -r aa1501c6ab80 source/encoder/ratecontrol.h<br>--- a/source/encoder/ratecontrol.h Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/encoder/ratecontrol.h Thu Oct 31 16:23:27 2019 +0530<br>@@ -46,6 +46,13 @@<br> #define MIN_AMORTIZE_FRACTION 0.2<br> #define CLIP_DURATION(f) x265_clip3(MIN_FRAME_DURATION, MAX_FRAME_DURATION, f)<br> <br>+/*Scenecut Aware QP*/<br>+#define I_SLICE_DELTA 2 /* Subtracted from base QP for the scenecut I frames*/<br>+#define SLICE_TYPE_DELTA 0.3 /* The offset decremented or incremented for P-frames or b-frames respectively*/<br>+#define WINDOW1_DELTA 0 /* The offset for the frames coming in the window-1*/<br>+#define WINDOW2_DELTA 0.3 /* The offset for the frames coming in the window-2*/<br>+#define WINDOW3_DELTA 0.6 /* The offset for the frames coming in the window-3*/<br>+<br> struct Predictor<br> {<br> double coeffMin;<br>@@ -142,6 +149,8 @@<br> bool m_initVbv;<br> int m_lastAbrResetPoc;<br> <br>+ int m_lastScenecut;<br>+ int m_lastScenecutAwareIFrame;<br> double m_rateTolerance;<br> double m_frameDuration; /* current frame duration in seconds */<br> double m_bitrate;<br>@@ -261,6 +270,8 @@<br> int writeRateControlFrameStats(Frame* curFrame, RateControlEntry* rce);<br> bool initPass2();<br> <br>+ double scenecutAwareQp(Frame* curFrame, double q);<br>+<br> protected:<br> <br> static const int s_slidingWindowFrames;<br>diff -r e4fea011918a -r aa1501c6ab80 source/test/regression-tests.txt<br>--- a/source/test/regression-tests.txt Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/test/regression-tests.txt Thu Oct 31 16:23:27 2019 +0530<br>@@ -158,6 +158,7 @@<br> ducks_take_off_420_1_720p50.y4m,--preset medium --selective-sao 4 --sao --crf 20<br> Traffic_4096x2048_30p.y4m, --preset medium --frame-dup --dup-threshold 60 --hrd --bitrate 10000 --vbv-bufsize 15000 --vbv-maxrate 12000<br> Kimono1_1920x1080_24_400.yuv,--preset superfast --qp 28 --zones 0,139,q=32<br>+Island_960x540_420p_8bit_24fps.yuv,--no-cutree --aq-mode 0 --bitrate 6000 --scenecut-aware-qp<br> <br> # Main12 intraCost overflow bug test<br> 720p50_parkrun_ter.y4m,--preset medium<br>diff -r e4fea011918a -r aa1501c6ab80 source/x265.h<br>--- a/source/x265.h Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/x265.h Thu Oct 31 16:23:27 2019 +0530<br>@@ -1832,6 +1832,18 @@<br> /*Flag to indicate if rate-control history has to be reset during zone reconfiguration.<br> Default 1 (Enabled). API only. */<br> int bResetZoneConfig;<br>+<br>+ /* Increase QP for inter-frames after a scenecut is detected, for a specified duration.<br>+ * Default is disabled. */<br>+ int bEnableSceneCutAwareQp;<br>+<br>+ /*The duration(in milliseconds) for which the QP is incremented for inter-frames when bEnableSceneCutAwareQp is set.<br>+ * Default 500ms.*/<br>+ int scenecutWindow;<br>+<br>+ /* The offset by which QP is incremented for inter-frames when bEnableSceneCutAwareQp is set.<br>+ * Default is +5. */<br>+ int maxQpDelta;<br> } x265_param;<br> /* x265_param_alloc:<br> * Allocates an x265_param instance. The returned param structure is not<br>diff -r e4fea011918a -r aa1501c6ab80 source/x265cli.h<br>--- a/source/x265cli.h Mon Oct 21 14:27:15 2019 +0530<br>+++ b/source/x265cli.h Thu Oct 31 16:23:27 2019 +0530<br>@@ -131,6 +131,10 @@<br> { "scenecut-bias", required_argument, NULL, 0 },<br> { "fades", no_argument, NULL, 0 },<br> { "no-fades", no_argument, NULL, 0 },<br>+ { "scenecut-aware-qp", no_argument, NULL, 0 },<br>+ { "no-scenecut-aware-qp", no_argument, NULL, 0 },<br>+ { "scenecut-window",required_argument, NULL, 0 },<br>+ { "max-qp-delta", required_argument, NULL, 0 },<br> { "radl", required_argument, NULL, 0 },<br> { "ctu-info", required_argument, NULL, 0 },<br> { "intra-refresh", no_argument, NULL, 0 },<br>@@ -487,6 +491,9 @@<br> H0(" --scenecut <integer> How aggressively to insert extra I-frames. Default %d\n", param->scenecutThreshold);<br> H1(" --scenecut-bias <0..100.0> Bias for scenecut detection. Default %.2f\n", param->scenecutBias);<br> H0(" --[no-]fades Enable detection and handling of fade-in regions. Default %s\n", OPT(param->bEnableFades));<br>+ H1(" --[no-]scenecut-aware-qp Enable increasing QP for frames inside the scenecut window after scenecut. Default %s\n", OPT(param->bEnableSceneCutAwareQp));<br>+ H1(" --scenecut-window <0..1000> QP incremental duration(in milliseconds) when scenecut-aware-qp is enabled. Default %d\n", param->scenecutWindow);<br>+ H1(" --max-qp-delta <0..10> QP offset to increment with base QP for inter-frames. Default %d\n", param->maxQpDelta);<br> H0(" --radl <integer> Number of RADL pictures allowed in front of IDR. Default %d\n", param->radl);<br> H0(" --intra-refresh Use Periodic Intra Refresh instead of IDR frames\n");<br> H0(" --rc-lookahead <integer> Number of frames for frame-type lookahead (determines encoder latency) Default %d\n", param->lookaheadDepth);<br><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><font color="#0c343d" face="verdana, sans-serif">Thanks & Regards</font><div><font color="#0c343d" face="verdana, sans-serif"><b>Niranjan Kumar B</b></font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Video Codec Engineer </font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Media & AI Analytics</font></div><div><font face="trebuchet ms, sans-serif" color="#0c343d">+91 958 511 1449</font></div><div><a href="https://multicorewareinc.com/" style="color:rgb(17,85,204)" target="_blank"><img src="https://docs.google.com/uc?export=download&id=1kc3RJu9M8bnIf6Xa5rUw2d-eEVUsPBE5&revid=0B7tw9XJBmynaemR1VUpQUi9DVytRVW5SVkRwVTFjb1hBMUcwPQ"></a></div></div></div></div></div></div></div></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org" target="_blank">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font face="georgia, serif">Regards,</font><div><b><font face="georgia, serif">Aruna Matheswaran,</font></b></div><div><font face="georgia, serif">Video Codec Engineer,</font></div><div><font face="georgia, serif">Media & AI analytics BU,</font></div><div><span><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><span style="border:none;display:inline-block;overflow:hidden;width:153px;height:58px"><img src="https://lh5.googleusercontent.com/gjX5cPNIZgwUrhfqkTwQUZWztIKmmo0qs3kbwvkS5H-bDVE2ftte9pMTVnFLSjOcjYWLtfc6_OGpxW4vraLg2r5QAIf1Q3MpldFDgWtzK_gXi8ptw5B3joIbsGL6mxj-JRdjHzT5" width="96" height="36" style="margin-left: 0px; margin-top: 0px;"></span></span></span><font face="georgia, serif"><br></font></div><div><span><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><span style="border:none;display:inline-block;overflow:hidden;width:153px;height:58px"><img src="https://lh5.googleusercontent.com/gjX5cPNIZgwUrhfqkTwQUZWztIKmmo0qs3kbwvkS5H-bDVE2ftte9pMTVnFLSjOcjYWLtfc6_OGpxW4vraLg2r5QAIf1Q3MpldFDgWtzK_gXi8ptw5B3joIbsGL6mxj-JRdjHzT5" style="margin-left: 0px; margin-top: 0px;"></span></span></span><font face="georgia, serif"><br></font></div><div><font face="georgia, serif"><br></font></div></div></div></div></div></div></div></div></div>