<div dir="ltr">From 1b4c75031d7ebe6a52fd87f3b1850d924067189c Mon Sep 17 00:00:00 2001<br>From: Karam Singh <<a href="mailto:karam.singh@multicorewareinc.com">karam.singh@multicorewareinc.com</a>><br>Date: Thu, 24 Oct 2024 18:04:04 +0530<br>Subject: [PATCH 07/10] search range optimization - 1<br><br>---<br> source/common/param.cpp          | 6 ++++++<br> source/common/temporalfilter.cpp | 8 ++++----<br> source/common/temporalfilter.h   | 2 +-<br> source/encoder/slicetype.cpp     | 6 +++---<br> source/x265.h                    | 4 ++++<br> 5 files changed, 18 insertions(+), 8 deletions(-)<br><br>diff --git a/source/common/param.cpp b/source/common/param.cpp<br>index 1beb3c056..195937f5e 100755<br>--- a/source/common/param.cpp<br>+++ b/source/common/param.cpp<br>@@ -418,6 +418,9 @@ void x265_param_default(x265_param* param)<br>     /* MCSTF */<br>     param->bEnableTemporalFilter = 0;<br>     param->temporalFilterStrength = 0.95;<br>+    param->searchRangeForLayer0 = 3;<br>+    param->searchRangeForLayer1 = 3;<br>+    param->searchRangeForLayer2 = 3;<br> <br>     /*Alpha Channel Encoding*/<br>     param->bEnableAlpha = 0;<br>@@ -2985,6 +2988,9 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>     dst->bField = src->bField;<br>     dst->bEnableTemporalFilter = src->bEnableTemporalFilter;<br>     dst->temporalFilterStrength = src->temporalFilterStrength;<br>+    dst->searchRangeForLayer0 = src->searchRangeForLayer0;<br>+    dst->searchRangeForLayer1 = src->searchRangeForLayer1;<br>+    dst->searchRangeForLayer2 = src->searchRangeForLayer2;<br>     dst->confWinRightOffset = src->confWinRightOffset;<br>     dst->confWinBottomOffset = src->confWinBottomOffset;<br>     dst->bliveVBV2pass = src->bliveVBV2pass;<br>diff --git a/source/common/temporalfilter.cpp b/source/common/temporalfilter.cpp<br>index 7c1be767e..521e367c8 100644<br>--- a/source/common/temporalfilter.cpp<br>+++ b/source/common/temporalfilter.cpp<br>@@ -649,10 +649,10 @@ void TemporalFilter::bilateralFilter(Frame* frame,<br> }<br> <br> void TemporalFilter::motionEstimationLuma(MV *mvs, uint32_t mvStride, pixel* src,int stride, int height, int width, pixel* buf, int blockSize,<br>-    MV *previous, uint32_t prevMvStride, int factor)<br>+    int sRange, MV* previous, uint32_t prevMvStride, int factor)<br> {<br> <br>-    int range = 5;<br>+    int range = sRange;<br> <br> <br>     const int stepSize = blockSize;<br>@@ -675,7 +675,7 @@ void TemporalFilter::motionEstimationLuma(MV *mvs, uint32_t mvStride, pixel* src<br> <br>             if (previous == NULL)<br>             {<br>-                range = 8;<br>+                range = sRange;<br>             }<br>             else<br>             {<br>@@ -893,7 +893,7 @@ void TemporalFilter::motionEstimationLumaDoubleRes(MV *mvs, uint32_t mvStride, P<br>             }<br> <br>             prevBest = best;<br>-            int doubleRange = 3 * 4;<br>+            int doubleRange = 1 * 4;<br>             for (int y2 = prevBest.y - doubleRange; y2 <= prevBest.y + doubleRange; y2 += 4)<br>             {<br>                 for (int x2 = prevBest.x - doubleRange; x2 <= prevBest.x + doubleRange; x2 += 4)<br>diff --git a/source/common/temporalfilter.h b/source/common/temporalfilter.h<br>index 1cd8028c7..3e03d7737 100644<br>--- a/source/common/temporalfilter.h<br>+++ b/source/common/temporalfilter.h<br>@@ -155,7 +155,7 @@ namespace X265_NS {<br> <br>         void bilateralFilter(Frame* frame, TemporalFilterRefPicInfo* mctfRefList, double overallStrength);<br> <br>-        void motionEstimationLuma(MV *mvs, uint32_t mvStride, pixel* src, int stride, int height, int width, pixel* buf, int bs,<br>+        void motionEstimationLuma(MV *mvs, uint32_t mvStride, pixel* src, int stride, int height, int width, pixel* buf, int bs, int sRange,<br>             MV *previous = 0, uint32_t prevmvStride = 0, int factor = 1);<br> <br>         void motionEstimationLumaDoubleRes(MV *mvs, uint32_t mvStride, PicYuv *orig, PicYuv *buffer, int blockSize,<br>diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp<br>index bd9f0793a..5fd885227 100644<br>--- a/source/encoder/slicetype.cpp<br>+++ b/source/encoder/slicetype.cpp<br>@@ -1801,9 +1801,9 @@ void Lookahead::estimatelowresmotion(Frame* curframe)<br>     {<br>         TemporalFilterRefPicInfo * ref = &curframe->m_mcstfRefList[i - 1];<br> <br>-        curframe->m_mcstf->motionEstimationLuma(ref->mvs0, ref->mvsStride0, curframe->m_lowres.lowerResPlane[0], (curframe->m_lowres.lumaStride / 2), (curframe->m_lowres.lines / 2), (curframe->m_lowres.width / 2), ref->lowerRes, 16);<br>-        curframe->m_mcstf->motionEstimationLuma(ref->mvs1, ref->mvsStride1, curframe->m_lowres.lowresPlane[0], (curframe->m_lowres.lumaStride), (curframe->m_lowres.lines), (curframe->m_lowres.width), ref->lowres, 16, ref->mvs0, ref->mvsStride0, 2);<br>-        curframe->m_mcstf->motionEstimationLuma(ref->mvs2, ref->mvsStride2, curframe->m_fencPic->m_picOrg[0], curframe->m_fencPic->m_stride, curframe->m_fencPic->m_picHeight, curframe->m_fencPic->m_picWidth, ref->picBuffer->m_picOrg[0], 16, ref->mvs1, ref->mvsStride1, 2);<br>+        curframe->m_mcstf->motionEstimationLuma(ref->mvs0, ref->mvsStride0, curframe->m_lowres.lowerResPlane[0], (curframe->m_lowres.lumaStride / 2), (curframe->m_lowres.lines / 2), (curframe->m_lowres.width / 2), ref->lowerRes, 16, m_param->searchRangeForLayer2);<br>+        curframe->m_mcstf->motionEstimationLuma(ref->mvs1, ref->mvsStride1, curframe->m_lowres.lowresPlane[0], (curframe->m_lowres.lumaStride), (curframe->m_lowres.lines), (curframe->m_lowres.width), ref->lowres, 16, m_param->searchRangeForLayer1, ref->mvs0, ref->mvsStride0, 2);<br>+        curframe->m_mcstf->motionEstimationLuma(ref->mvs2, ref->mvsStride2, curframe->m_fencPic->m_picOrg[0], curframe->m_fencPic->m_stride, curframe->m_fencPic->m_picHeight, curframe->m_fencPic->m_picWidth, ref->picBuffer->m_picOrg[0], 16, m_param->searchRangeForLayer0, ref->mvs1, ref->mvsStride1, 2);<br>         curframe->m_mcstf->motionEstimationLumaDoubleRes(ref->mvs, ref->mvsStride, curframe->m_fencPic, ref->picBuffer, 8, ref->mvs2, ref->mvsStride2, 1, ref->error);<br>     }<br> <br>diff --git a/source/x265.h b/source/x265.h<br>index 13c4a47e2..b4dceb406 100644<br>--- a/source/x265.h<br>+++ b/source/x265.h<br>@@ -2314,6 +2314,10 @@ typedef struct x265_param<br>     /*Motion compensated temporal filter*/<br>     int      bEnableTemporalFilter;<br>     double   temporalFilterStrength;<br>+    /*Search Range for L0, L1 and L2 in MCTF*/<br>+    int      searchRangeForLayer0;<br>+    int      searchRangeForLayer1;<br>+    int      searchRangeForLayer2;<br> <br>     /*SBRC*/<br>     int      bEnableSBRC;<br>-- <br>2.36.0.windows.1<br><br></div>