[x265] [PATCH] search.cpp: clip the best MV to ensure resulting mvdLX is compliant
Richard
ccc7922 at foxmail.com
Sun Jul 13 08:31:21 UTC 2025
From f47f95db0700d52897836787622628550742f476 Mon Sep 17 00:00:00 2001
From: Mr-Z-2697 <74594146+Mr-Z-2697 at users.noreply.github.com>
Date: Sun, 13 Jul 2025 16:09:53 +0800
Subject: [PATCH] search.cpp: clip the best MV to ensure resulting mvdLX is
compliant
The value of the mvdLX should be in the range of [-2^15, 2^15-1], as specified in H.265 7.4.9.9 Motion vector difference semantics.
However there was no safety check in this area, the mvdLX have been observed to exceed the range, under some rare circumstances.
Due to the rare nature of the bug, this patch only does simple clipping, without further measures, to minimize the speed penalty.
---
source/encoder/search.cpp | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/source/encoder/search.cpp b/source/encoder/search.cpp
index 0522f52cc..9dd409499 100644
--- a/source/encoder/search.cpp
+++ b/source/encoder/search.cpp
@@ -2543,6 +2543,12 @@ void Search::predInterSearch(Mode& interMode, const CUGeom& cuGeom, bool bChroma
}
}
+ // to ensure the mvdLX is in the range of [-2^15, 2^15-1]
+ MV clipmin((int32_t) -(1 << 15) , (int32_t) -(1 << 15) );
+ MV clipmax((int32_t) (1 << 15) - 1, (int32_t) (1 << 15) - 1);
+ bestME[0].mv = bestME[0].mv.clipped(bestME[0].mvp + clipmin, bestME[0].mvp + clipmax);
+ bestME[1].mv = bestME[1].mv.clipped(bestME[1].mvp + clipmin, bestME[1].mvp + clipmax);
+
/* Bi-directional prediction */
MotionData bidir[2];
uint32_t bidirCost = MAX_UINT;
@@ -2648,6 +2654,11 @@ void Search::predInterSearch(Mode& interMode, const CUGeom& cuGeom, bool bChroma
bidirBits = bits0 + bits1 + m_listSelBits[2] - (m_listSelBits[0] + m_listSelBits[1]);
}
}
+ // to ensure the mvdLX is in the range of [-2^15, 2^15-1]
+ MV clipmin((int32_t) -(1 << 15) , (int32_t) -(1 << 15) );
+ MV clipmax((int32_t) (1 << 15) - 1, (int32_t) (1 << 15) - 1);
+ bidir[0].mv = bidir[0].mv.clipped(bidir[0].mvp + clipmin, bidir[0].mvp + clipmax);
+ bidir[1].mv = bidir[1].mv.clipped(bidir[1].mvp + clipmin, bidir[1].mvp + clipmax);
}
/* select best option and store into CU */
--
2.49.0.windows.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20250713/55d19de8/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-search.cpp-clip-the-best-MV-to-ensure-resulting-mvdL.patch
Type: application/octet-stream
Size: 2296 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20250713/55d19de8/attachment.obj>
More information about the x265-devel
mailing list