[x265] [PATCH] Fix psnr and ssim reported with mcstf feature

Kirithika Kalirathnam kirithika at multicorewareinc.com
Tue Jan 13 07:15:09 UTC 2026


>From 618b23da0bba0edeca06aded845841c800c8eceb Mon Sep 17 00:00:00 2001
From: Kirithika <kirithika at multicorewareinc.com>
Date: Fri, 9 Jan 2026 10:52:11 +0530
Subject: [PATCH] Fix psnr and ssim reported with mcstf feature

---
 source/common/param.cpp        |  2 ++
 source/encoder/encoder.cpp     | 22 ++++++++++++++++++++--
 source/encoder/framefilter.cpp |  4 ++--
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/source/common/param.cpp b/source/common/param.cpp
index a35b06339..fa702e597 100755
--- a/source/common/param.cpp
+++ b/source/common/param.cpp
@@ -2200,6 +2200,8 @@ void x265_print_params(x265_param* param)
 #if ENABLE_HDR10_PLUS
     TOOLOPT(param->toneMapFile != NULL, "dhdr10-info");
 #endif
+    if(param->bEnableTemporalFilter)
+        TOOLOPT(param->bEnableTemporalFilter, "mcstf");
     x265_log(param, X265_LOG_INFO, "tools:%s\n", buf);
     fflush(stderr);
 }
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 2e65cb1a9..423c94609 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -1538,10 +1538,20 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)
                     {
                         inFrame[layer]->m_fencPic->m_cuOffsetY = m_sps.cuOffsetY;
                         inFrame[layer]->m_fencPic->m_buOffsetY = m_sps.buOffsetY;
+                        if (m_param->bEnableTemporalFilter)
+                        {
+                            inFrame[layer]->m_mcstffencPic->m_cuOffsetY = m_sps.cuOffsetY;
+                            inFrame[layer]->m_mcstffencPic->m_buOffsetY = m_sps.buOffsetY;
+                        }
                         if (m_param->internalCsp != X265_CSP_I400)
                         {
                             inFrame[layer]->m_fencPic->m_cuOffsetC = m_sps.cuOffsetC;
                             inFrame[layer]->m_fencPic->m_buOffsetC = m_sps.buOffsetC;
+                            if (m_param->bEnableTemporalFilter)
+                            {
+                                inFrame[layer]->m_mcstffencPic->m_cuOffsetC = m_sps.cuOffsetC;
+                                inFrame[layer]->m_mcstffencPic->m_buOffsetC = m_sps.buOffsetC;
+                            }
                         }
                     }
                     else
@@ -1558,12 +1568,20 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)
                         {
                             m_sps.cuOffsetY = inFrame[layer]->m_fencPic->m_cuOffsetY;
                             m_sps.buOffsetY = inFrame[layer]->m_fencPic->m_buOffsetY;
+                            if (m_param->bEnableTemporalFilter)
+                            {
+                                inFrame[layer]->m_mcstffencPic->m_cuOffsetY = m_sps.cuOffsetY;
+                                inFrame[layer]->m_mcstffencPic->m_buOffsetY = m_sps.buOffsetY;
+                            }
                             if (m_param->internalCsp != X265_CSP_I400)
                             {
                                 m_sps.cuOffsetC = inFrame[layer]->m_fencPic->m_cuOffsetC;
-                                m_sps.cuOffsetY = inFrame[layer]->m_fencPic->m_cuOffsetY;
                                 m_sps.buOffsetC = inFrame[layer]->m_fencPic->m_buOffsetC;
-                                m_sps.buOffsetY = inFrame[layer]->m_fencPic->m_buOffsetY;
+                                if (m_param->bEnableTemporalFilter)
+                                {
+                                    inFrame[layer]->m_mcstffencPic->m_cuOffsetC = m_sps.cuOffsetC;
+                                    inFrame[layer]->m_mcstffencPic->m_buOffsetC = m_sps.buOffsetC;
+                                }
                             }
                         }
                     }
diff --git a/source/encoder/framefilter.cpp b/source/encoder/framefilter.cpp
index c60cf9261..bb5fb7512 100644
--- a/source/encoder/framefilter.cpp
+++ b/source/encoder/framefilter.cpp
@@ -663,7 +663,7 @@ void FrameFilter::processPostRow(int row, int layer)
     uint32_t cuAddr = lineStartCUAddr;
     if (m_param->bEnablePsnr)
     {
-        PicYuv* fencPic = m_frame->m_fencPic;
+        PicYuv* fencPic = m_param->bEnableTemporalFilter ? m_frame->m_mcstffencPic : m_frame->m_fencPic;

         intptr_t stride = reconPic->m_stride;
         uint32_t width  = reconPic->m_picWidth - m_pad[0];
@@ -689,7 +689,7 @@ void FrameFilter::processPostRow(int row, int layer)
     if (m_param->bEnableSsim && m_ssimBuf)
     {
         pixel *rec = reconPic->m_picOrg[0];
-        pixel *fenc = m_frame->m_fencPic->m_picOrg[0];
+        pixel *fenc = m_param->bEnableTemporalFilter ? m_frame->m_mcstffencPic->m_picOrg[0] : m_frame->m_fencPic->m_picOrg[0];
         intptr_t stride1 = reconPic->m_stride;
         intptr_t stride2 = m_frame->m_fencPic->m_stride;
         uint32_t bEnd = ((row) == (this->m_numRows - 1));
--
2.28.0.windows.1


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20260113/c353cf6b/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-fix-mcstf-psnr.diff
Type: application/octet-stream
Size: 4959 bytes
Desc: patch-fix-mcstf-psnr.diff
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20260113/c353cf6b/attachment-0001.obj>


More information about the x265-devel mailing list