From f47f95db0700d52897836787622628550742f476 Mon Sep 17 00:00:00 2001 From: Mr-Z-2697 <74594146+mr-z-2...@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
0001-search.cpp-clip-the-best-MV-to-ensure-resulting-mvdL.patch
Description: Binary data
_______________________________________________ x265-devel mailing list x265-devel@videolan.org https://mailman.videolan.org/listinfo/x265-devel