<div data-ntes="ntes_mail_body_root" style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div id="spnEditorContent"><p style="margin: 0;">Hi Richard,</p><p style="margin: 0;"><br></p><p style="margin: 0;">We don't change default frame-threads to 1 for more compression performance reason, the</p><p style="margin: 0;">slice mostly use for large resolution, it allow encoder couple future frame in parallel, the user</p><p style="margin: 0;">may set frame-threads to 1 for more compression ratio.</p><p style="margin: 0;">In exist method, we made restrict on vertical motion only, most motion in horizon direction, </p><p style="margin: 0;">compression performance drop is not so much around the slice boundary.</p></div><div style="position:relative;zoom:1"></div><div id="divNeteaseMailCard"></div><div style="margin: 0;"><br></div><div style="margin: 0;">Moreover, the inconsistency is a problem, if output bitstream become different each run, it</div><div style="margin: 0;">difficult to debug and estimate output effect.</div><div style="margin: 0;"><br></div><div style="margin: 0;">If more people interesting Slice than Tile, we may use area lock to keep output deterministic</div><div style="margin: 0;">without limited MV range, it may more balance in speed and compression performance.</div><div style="margin: 0;"><br></div><div style="margin: 0;">Regards,</div><div style="margin: 0;">Chen</div><p>At 2025-03-18 14:38:57, "Richard" <ccc7922@foxmail.com> wrote:</p><blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">Yes, that fixes the most prominet problem, but there's still compression lost due to the restriction,</span></div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">you know, a horizontal pan isn't all that rare in the everyday contents.</span></div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;"><br></span></div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">May I ask what's the extent of the impact of this incorrectness, to the encoding?</span></div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">If it only causes run to run inconsistency, that's actually not a big problem, it was supposed to be</span></div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">fixed in the previous commit (eaeeab5 back in Nov 2016), but apparently something changed</span></div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">along the way broke it again, now it's non-deterministic again even with the restriction.</span></div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;"><br></span></div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">I suggest default frame-threads to 1 when multiple slices are used. It helps with both deterministic</span></div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">and compression (because the restriction is not applied).</span></div><div><br></div><article><div style="display:flex;align-items:center;padding-top:8px" contenteditable="false">
<div style="color:#959DA6;font-size:12px;line-height:30px;background:#FFF">Original</div>
<hr style="border: none;flex-grow:1;border-top:1px solid rgba(21, 46, 74, 0.07);margin-left:8px">
</div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;"><br></span></div><div><br></div><p style="line-height: 1.7; margin: 0px;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);">Hi Richard,</span></p><p style="line-height: 1.7; margin: 0px;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);"><br></span></p><p style="line-height: 1.7; margin: 0px;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);">There are parallelism restrict, interpolate can't across slice boundary.</span></p><p style="line-height: 1.7; margin: 0px;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);">The range [-16,+12] is integer pixel [-4,+3], if MV Y-axis in this range, the interpolate may generate incorrect result.</span></p><p style="line-height: 1.7; margin: 0px;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);">There have some special point interpolate in Horizontal direction only, but it is less probability to choice as best MV, so just check ZeroMv enough.</span></p><p style="line-height: 1.7; margin: 0px;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);"><br></span></p><p style="line-height: 1.7; margin: 0px;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);">Regards</span></p><p style="line-height: 1.7; margin: 0px;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);">Chen</span></p><p style="line-height: 1.7; margin: 0px;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);"><br></span></p><p style="line-height: 1.7; margin: 0px;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);"><br></span></p><p style="line-height: 1.7;"><span style="font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);">At 2025-03-17 23:12:32, "Richard" <ccc7922@foxmail.com> wrote:</span></p><blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left: 1px solid rgb(204, 204, 204);"><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">Zero MV is only one special case of the problem.</span></div><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;"><br></span></div><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">The code of MV restriction calculation:</span></div><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;"> tld.analysis.m_sliceMinY = -(int32_t)(rowInSlice * m_param->maxCUSize * 4) + 3 * 4;<br> tld.analysis.m_sliceMaxY = (int32_t)((endRowInSlicePlus1 - 1 - row) * (m_param->maxCUSize * 4) - 4 * 4);</span></div><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;"><br></span></div><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">The constants will cause MVs to be restricted to >12 or <-16 in slice boundaries.</span></div><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">example:</span></div><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;"> minY: -2036, maxY: -16</span></div><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">or</span></div><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;"> minY: 12, maxY: 1776</span></div><div style="line-height: 1.7; font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;">So any MV that has its Y-axis in the range of -16 to 12 will have problem.</span></div><div style="line-height: 1.7; font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);"><br></div><article><div style="display:flex;align-items:center;padding-top:8px" contenteditable="false">
<div style="color:#959DA6;font-size:12px;line-height:30px;background:#FFF">Original</div>
<hr style="border: none;border:none;flex-grow:1;border-top:1px solid rgba(21, 46, 74, 0.07);margin-left:8px">
</div><div style="font-family: -apple-system, system-ui; font-size: 14px; color: rgb(0, 0, 0);"><span style="line-height: 1.6;"><br></span></div><div><br></div><span style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">From baff7691e9bc4f93bccc85ae78d95ad9ade7a8d0 Mon Sep 17 00:00:00 2001</span>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
From: Min Chen <chenm003@163.com></div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Date: Fri, 14 Mar 2025 22:27:02 -0700</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Subject: [PATCH] Improve Slices option with check zeroMv</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
---</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
source/encoder/analysis.cpp | 4 ++--</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
source/encoder/motion.cpp | 8 ++++++++</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
2 files changed, 10 insertions(+), 2 deletions(-)</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
diff --git a/source/encoder/analysis.cpp b/source/encoder/analysis.cpp</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
index 5475e4800..e3c410e59 100644</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
--- a/source/encoder/analysis.cpp</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+++ b/source/encoder/analysis.cpp</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
@@ -3166,7 +3166,7 @@ void Analysis::checkMerge2Nx2N_rd0_4(Mode& skip, Mode& merge, const CUGeom& cuGe</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
}</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
for (uint32_t i = 0; i < numMergeCand; ++i)</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
{</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
- if (m_bFrameParallel)</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+ if (m_bFrameParallel && candMvField[i][0].mv.notZero())</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
{</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
// Parallel slices bound check</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
if (m_param->maxSlices > 1)</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
@@ -3300,7 +3300,7 @@ void Analysis::checkMerge2Nx2N_rd5_6(Mode& skip, Mode& merge, const CUGeom& cuGe</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
}</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
for (uint32_t i = 0; i < numMergeCand; i++)</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
{</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
- if (m_bFrameParallel)</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+ if (m_bFrameParallel && candMvField[i][0].mv.notZero())</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
{</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
// Parallel slices bound check</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
if (m_param->maxSlices > 1)</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
diff --git a/source/encoder/motion.cpp b/source/encoder/motion.cpp</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
index 58e943652..86f413c3d 100644</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
--- a/source/encoder/motion.cpp</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+++ b/source/encoder/motion.cpp</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
@@ -1596,6 +1596,14 @@ me_hex2:</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
// check mv range for slice bound</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
X265_CHECK(((bmv.y >= qmvmin.y) & (bmv.y <= qmvmax.y)), "mv beyond range!");</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+ // Get a chance to ZeroMv</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+ if (bmv.notZero())</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+ {</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+ int cost = subpelCompare(ref, MV(0, 0), satd) + mvcost(MV(0, 0));</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+ if (cost <= bcost)</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+ bmv = MV(0, 0);</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+ }</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
+</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
x265_emms();</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
outQMv = bmv;</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
return bcost;</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
-- </div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
2.43.0.windows.1</div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
<span class="_Entity _EType_OWALink _EId_OWALink _EReadonly_1" style="display:inline-block"><span></span></span></div><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
</div></article><div style="line-height: 1.7; font-family: Arial; font-size: 14px; color: rgb(0, 0, 0);"><br></div></blockquote></article><div><br></div></blockquote></div>