<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">From 9fa5285d5dcb13b9baa682627803150d4b49f3d5 Mon Sep 17 00:00:00 2001<br>From: Pavan Tarun <<a href="mailto:pavan.tarun@multicorewareinc.com">pavan.tarun@multicorewareinc.com</a>><br>Date: Tue, 2 Jul 2024 14:31:39 +0530<br>Subject: [PATCH] Updated mcstf filter to use two reference frames for fast<br> presets<br><br>---<br> source/common/frame.cpp    |  1 +<br> source/common/param.cpp    | 10 +++++++++-<br> source/encoder/encoder.cpp |  4 ++++<br> source/x265.h              |  1 +<br> 4 files changed, 15 insertions(+), 1 deletion(-)<br><br>diff --git a/source/common/frame.cpp b/source/common/frame.cpp<br>index ae3773e..7947433 100644<br>--- a/source/common/frame.cpp<br>+++ b/source/common/frame.cpp<br>@@ -85,6 +85,7 @@ bool Frame::create(x265_param *param, float* quantOffsets)<br>     if (m_param->bEnableTemporalFilter)<br>     {<br>         m_mcstf = new TemporalFilter;<br>+        m_mcstf->m_range = param->mcstfFrameRange;<br>         m_mcstf->init(param);<br> <br>         m_fencPicSubsampled2 = new PicYuv;<br>diff --git a/source/common/param.cpp b/source/common/param.cpp<br>index e90b08e..5b29225 100755<br>--- a/source/common/param.cpp<br>+++ b/source/common/param.cpp<br>@@ -183,6 +183,7 @@ void x265_param_default(x265_param* param)<br>     param->bEnableSceneCutAwareQp = 0;<br>     param->fwdMaxScenecutWindow = 1200;<br>     param->bwdMaxScenecutWindow = 600;<br>+    param->mcstfFrameRange = 2;<br>     for (int i = 0; i < 6; i++)<br>     {<br>         int deltas[6] = { 5, 4, 3, 2, 1, 0 };<br>@@ -417,6 +418,7 @@ int x265_param_default_preset(x265_param* param, const char* preset, const char*<br> <br>         if (!strcmp(preset, "ultrafast"))<br>         {<br>+            param->mcstfFrameRange = 1;<br>             param->maxNumMergeCand = 2;<br>             param->bIntraInBFrames = 0;<br>             param->lookaheadDepth = 5;<br>@@ -441,6 +443,7 @@ int x265_param_default_preset(x265_param* param, const char* preset, const char*<br>         }<br>         else if (!strcmp(preset, "superfast"))<br>         {<br>+            param->mcstfFrameRange = 1;<br>             param->maxNumMergeCand = 2;<br>             param->bIntraInBFrames = 0;<br>             param->lookaheadDepth = 10;<br>@@ -461,6 +464,7 @@ int x265_param_default_preset(x265_param* param, const char* preset, const char*<br>         }<br>         else if (!strcmp(preset, "veryfast"))<br>         {<br>+            param->mcstfFrameRange = 1;<br>             param->maxNumMergeCand = 2;<br>             param->limitReferences = 3;<br>             param->bIntraInBFrames = 0;<br>@@ -474,6 +478,7 @@ int x265_param_default_preset(x265_param* param, const char* preset, const char*<br>         }<br>         else if (!strcmp(preset, "faster"))<br>         {<br>+            param->mcstfFrameRange = 1;<br>             param->maxNumMergeCand = 2;<br>             param->limitReferences = 3;<br>             param->bIntraInBFrames = 0;<br>@@ -485,6 +490,7 @@ int x265_param_default_preset(x265_param* param, const char* preset, const char*<br>         }<br>         else if (!strcmp(preset, "fast"))<br>         {<br>+            param->mcstfFrameRange = 1;<br>             param->maxNumMergeCand = 2;<br>             param->limitReferences = 3;<br>             param->bEnableEarlySkip = 0;<br>@@ -497,6 +503,7 @@ int x265_param_default_preset(x265_param* param, const char* preset, const char*<br>         }<br>         else if (!strcmp(preset, "medium"))<br>         {<br>+            param->mcstfFrameRange = 1;<br>             /* defaults */<br>         }<br>         else if (!strcmp(preset, "slow"))<br>@@ -1674,7 +1681,7 @@ int x265_check_params(x265_param* param)<br>         CHECK(param->edgeVarThreshold < 0.0f || param->edgeVarThreshold > 1.0f,<br>               "Minimum edge density percentage for a CU should be an integer between 0 to 100");<br>     }<br>-    CHECK(param->bframes && param->bframes >= param->lookaheadDepth && !param->rc.bStatRead,<br>+    CHECK(param->bframes && (param->bEnableTemporalFilter ? (param->bframes > param->lookaheadDepth) : (param->bframes >= param->lookaheadDepth)) && !param->rc.bStatRead,<br>           "Lookahead depth must be greater than the max consecutive bframe count");<br>     CHECK(param->bframes < 0,<br>           "bframe count should be greater than zero");<br>@@ -2558,6 +2565,7 @@ bool parseMaskingStrength(x265_param* p, const char* value)<br> <br> void x265_copy_params(x265_param* dst, x265_param* src)<br> {<br>+    dst->mcstfFrameRange = src->mcstfFrameRange;<br>     dst->cpuid = src->cpuid;<br>     dst->frameNumThreads = src->frameNumThreads;<br>     if (src->numaPools) dst->numaPools = strdup(src->numaPools);<br>diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br>index 8620a48..0f188e6 100644<br>--- a/source/encoder/encoder.cpp<br>+++ b/source/encoder/encoder.cpp<br>@@ -3907,6 +3907,10 @@ void Encoder::configure(x265_param *p)<br>         p->limitReferences = 0;<br>     }<br> <br>+    if ((m_param->bEnableTemporalFilter) && (p->bframes < 5)){<br>+        x265_log(p, X265_LOG_WARNING, "Setting the number of B-frames to 5, as MCSTF filter is enabled.\n");<br>+        p->bframes = 5;<br>+    }<br>     if ((p->bEnableTemporalSubLayers > 2) && !p->bframes)<br>     {<br>         x265_log(p, X265_LOG_WARNING, "B frames not enabled, temporal sublayer disabled\n");<br>diff --git a/source/x265.h b/source/x265.h<br>index 4452526..c48b864 100644<br>--- a/source/x265.h<br>+++ b/source/x265.h<br>@@ -2268,6 +2268,7 @@ typedef struct x265_param<br> <br>     /*SBRC*/<br>     int      bEnableSBRC;<br>+    int mcstfFrameRange;<br> } x265_param;<br> <br> /* x265_param_alloc:<br>-- <br>1.8.3.1<br></div></div>