<div dir="ltr">I have a few of these cosmetic fixes queued localy, and yes, they should be in stable. <br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 17, 2015 at 11:44 AM, Steve Borho <span dir="ltr"><<a href="mailto:steve@borho.org" target="_blank">steve@borho.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 08/17, <a href="mailto:aarthi@multicorewareinc.com">aarthi@multicorewareinc.com</a> wrote:<br>
> # HG changeset patch<br>
> # User Aarthi Thirumalai<br>
> # Date 1437505166 -19800<br>
> # Wed Jul 22 00:29:26 2015 +0530<br>
> # Node ID 51320561d41f32faa75dd3d04d88ea68500ce995<br>
> # Parent d56b2466c04459205287e1581d8a36eebf372ba6<br>
> slicetype: Modify Scenecut algorithm to detect scene transition points<br>
> to improve Rate Control (refs #160).<br>
><br>
> identify scene trasitions, fade-ins, fadeouts, sceneCuts and signal the flag bSceneCut<br>
> in Lowres structure. This flag will be used by RateControl to adjust the wps during scene cuts.<br>
<br>
</span>'wps' typo<br>
<br>
are these two patches ok for the stable branch?<br>
<div><div class="h5"><br>
> diff -r d56b2466c044 -r 51320561d41f source/common/lowres.cpp<br>
> --- a/source/common/lowres.cpp Wed Aug 12 18:12:20 2015 +0530<br>
> +++ b/source/common/lowres.cpp Wed Jul 22 00:29:26 2015 +0530<br>
> @@ -126,7 +126,7 @@<br>
> void Lowres::init(PicYuv *origPic, int poc)<br>
> {<br>
> bLastMiniGopBFrame = false;<br>
> - bScenecut = true; // could be a scene-cut, until ruled out by flash detection<br>
> + bScenecut = false; // could be a scene-cut, until ruled out by flash detection<br>
> bKeyframe = false; // Not a keyframe unless identified by lookahead<br>
> frameNum = poc;<br>
> leadingBframes = 0;<br>
> diff -r d56b2466c044 -r 51320561d41f source/encoder/slicetype.cpp<br>
> --- a/source/encoder/slicetype.cpp Wed Aug 12 18:12:20 2015 +0530<br>
> +++ b/source/encoder/slicetype.cpp Wed Jul 22 00:29:26 2015 +0530<br>
> @@ -483,6 +483,7 @@<br>
> m_pool = pool;<br>
><br>
> m_lastNonB = NULL;<br>
> + m_isSceneTransition = false;<br>
> m_scratch = NULL;<br>
> m_tld = NULL;<br>
> m_filled = false;<br>
> @@ -1267,10 +1268,16 @@<br>
><br>
> int numBFrames = 0;<br>
> int numAnalyzed = numFrames;<br>
> - if (m_param->scenecutThreshold && scenecut(frames, 0, 1, true, origNumFrames, maxSearch))<br>
> +<br>
> + if (m_param->bFrameAdaptive)<br>
> {<br>
> - frames[1]->sliceType = X265_TYPE_I;<br>
> - return;<br>
> + bool isScenecut = scenecut(frames, 0, 1, true, origNumFrames);<br>
> + /* When scenecut threshold is set, use scenecut detection for I frame placements */<br>
> + if (!m_param->scenecutThreshold && isScenecut)<br>
> + {<br>
> + frames[1]->sliceType = X265_TYPE_I;<br>
> + return;<br>
> + }<br>
> }<br>
><br>
> if (m_param->bframes)<br>
> @@ -1357,14 +1364,13 @@<br>
> /* Check scenecut on the first minigop. */<br>
> for (int j = 1; j < numBFrames + 1; j++)<br>
> {<br>
> - if (m_param->scenecutThreshold && scenecut(frames, j, j + 1, false, origNumFrames, maxSearch))<br>
> + if (m_param->scenecutThreshold && scenecut(frames, j, j + 1, false, origNumFrames))<br>
> {<br>
> frames[j]->sliceType = X265_TYPE_P;<br>
> numAnalyzed = j;<br>
> break;<br>
> }<br>
> }<br>
> -<br>
> resetStart = bKeyframe ? 1 : X265_MIN(numBFrames + 2, numAnalyzed + 1);<br>
> }<br>
> else<br>
> @@ -1388,46 +1394,97 @@<br>
> if (bIsVbvLookahead)<br>
> vbvLookahead(frames, numFrames, bKeyframe);<br>
><br>
> + int maxp1 = X265_MIN(m_param->bframes + 1, origNumFrames);<br>
> /* Restore frame types for all frames that haven't actually been decided yet. */<br>
> for (int j = resetStart; j <= numFrames; j++)<br>
> + {<br>
> frames[j]->sliceType = X265_TYPE_AUTO;<br>
> + /* If any frame marked as scenecut is being restarted for sliceDecision,<br>
> + * undo scene Transition flag */<br>
> + if (j <= maxp1 && frames[j]->bScenecut && m_isSceneTransition)<br>
> + m_isSceneTransition = false;<br>
> + }<br>
> }<br>
><br>
> -bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, int numFrames, int maxSearch)<br>
> +bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, int numFrames)<br>
> {<br>
> /* Only do analysis during a normal scenecut check. */<br>
> if (bRealScenecut && m_param->bframes)<br>
> {<br>
> int origmaxp1 = p0 + 1;<br>
> /* Look ahead to avoid coding short flashes as scenecuts. */<br>
> - if (m_param->bFrameAdaptive == X265_B_ADAPT_TRELLIS)<br>
> - /* Don't analyse any more frames than the trellis would have covered. */<br>
> - origmaxp1 += m_param->bframes;<br>
> - else<br>
> - origmaxp1++;<br>
> + origmaxp1 += m_param->bframes;<br>
> int maxp1 = X265_MIN(origmaxp1, numFrames);<br>
> -<br>
> + bool fluctuate = false;<br>
> + bool noScenecuts = false;<br>
> + int64_t avgSatdCost = 0;<br>
> + if (frames[0]->costEst[1][0] > -1)<br>
> + avgSatdCost = frames[0]->costEst[1][0];<br>
> + int cnt = 1;<br>
> /* Where A and B are scenes: AAAAAABBBAAAAAA<br>
> * If BBB is shorter than (maxp1-p0), it is detected as a flash<br>
> * and not considered a scenecut. */<br>
> for (int cp1 = p1; cp1 <= maxp1; cp1++)<br>
> {<br>
> if (!scenecutInternal(frames, p0, cp1, false))<br>
> + {<br>
> /* Any frame in between p0 and cur_p1 cannot be a real scenecut. */<br>
> for (int i = cp1; i > p0; i--)<br>
> + {<br>
> frames[i]->bScenecut = false;<br>
> + noScenecuts = false;<br>
> + }<br>
> + }<br>
> + else if (scenecutInternal(frames, cp1 - 1, cp1, false))<br>
> + {<br>
> + /* If current frame is a Scenecut from p0 frame as well as Scenecut from<br>
> + * preceeding frame, mark it as a Scenecut */<br>
> + frames[cp1]->bScenecut = true;<br>
> + noScenecuts = true;<br>
> + }<br>
> +<br>
> + /* compute average satdcost of all the frames in the mini-gop to confirm<br>
> + * whether there is any great fluctuation among them to rule out false positives */<br>
> + X265_CHECK(frames[cp1]->costEst[cp1 - p0][0]!= -1, "costEst is not done \n");<br>
> + avgSatdCost += frames[cp1]->costEst[cp1 - p0][0];<br>
> + cnt++;<br>
> }<br>
> + /* Identify possible scene fluctuations by comparing the satd cost of the frames.<br>
> + * This could denote the beginning or ending of scene transitions.<br>
> + * During a scene transition(fade in/fade outs), if fluctuate remains false,<br>
> + * then the scene had completed its transition or stabilized.<br>
> + */<br>
><br>
> - /* Where A-F are scenes: AAAAABBCCDDEEFFFFFF<br>
> - * If each of BB ... EE are shorter than (maxp1-p0), they are<br>
> - * detected as flashes and not considered scenecuts.<br>
> - * Instead, the first F frame becomes a scenecut.<br>
> - * If the video ends before F, no frame becomes a scenecut. */<br>
> - for (int cp0 = p0; cp0 <= maxp1; cp0++)<br>
> + if (noScenecuts)<br>
> {<br>
> - if (origmaxp1 > maxSearch || (cp0 < maxp1 && scenecutInternal(frames, cp0, maxp1, false)))<br>
> - /* If cur_p0 is the p0 of a scenecut, it cannot be the p1 of a scenecut. */<br>
> - frames[cp0]->bScenecut = false;<br>
> + fluctuate = false;<br>
> + avgSatdCost /= cnt;<br>
> + for (int i= p1 ; i <= maxp1; i++)<br>
> + {<br>
> + if (abs(frames[i]->costEst[i - p0][0] - avgSatdCost) > 0.1 * avgSatdCost)<br>
> + {<br>
> + fluctuate = true;<br>
> + if (!m_isSceneTransition && frames[i]->bScenecut)<br>
> + {<br>
> + m_isSceneTransition = true;<br>
> + /* just mark the first scenechange in the scene transition as a scenecut. */<br>
> + for (int j = i + 1; j <= maxp1; j++)<br>
> + {<br>
> + frames[j]->bScenecut = false;<br>
<br>
</div></div>don't need braces here or below<br>
<span class=""><br>
> + }<br>
> + break;<br>
> + }<br>
> + }<br>
> + if (frames[i]->bScenecut)<br>
> + {<br>
> + frames[i]->bScenecut = false;<br>
> + }<br>
<br>
</span>this assignment can be done unconditionally<br>
<div class="HOEnZb"><div class="h5"><br>
> + }<br>
> + }<br>
> + if (!fluctuate && !noScenecuts)<br>
> + {<br>
> + /* Signal end of scene transitioning */<br>
> + m_isSceneTransition = false;<br>
> }<br>
> }<br>
><br>
> @@ -1451,22 +1508,23 @@<br>
><br>
> /* magic numbers pulled out of thin air */<br>
> float threshMin = (float)(threshMax * 0.25);<br>
> - float bias;<br>
> -<br>
> - if (m_param->keyframeMin == m_param->keyframeMax)<br>
> - threshMin = threshMax;<br>
> - if (gopSize <= m_param->keyframeMin / 4)<br>
> - bias = threshMin / 4;<br>
> - else if (gopSize <= m_param->keyframeMin)<br>
> - bias = threshMin * gopSize / m_param->keyframeMin;<br>
> - else<br>
> + double bias = 0.05;<br>
> + if (bRealScenecut)<br>
> {<br>
> - bias = threshMin<br>
> - + (threshMax - threshMin)<br>
> - * (gopSize - m_param->keyframeMin)<br>
> - / (m_param->keyframeMax - m_param->keyframeMin);<br>
> + if (m_param->keyframeMin == m_param->keyframeMax)<br>
> + threshMin = threshMax;<br>
> + if (gopSize <= m_param->keyframeMin / 4)<br>
> + bias = threshMin / 4;<br>
> + else if (gopSize <= m_param->keyframeMin)<br>
> + bias = threshMin * gopSize / m_param->keyframeMin;<br>
> + else<br>
> + {<br>
> + bias = threshMin<br>
> + + (threshMax - threshMin)<br>
> + * (gopSize - m_param->keyframeMin)<br>
> + / (m_param->keyframeMax - m_param->keyframeMin);<br>
> + }<br>
> }<br>
> -<br>
> bool res = pcost >= (1.0 - bias) * icost;<br>
> if (res && bRealScenecut)<br>
> {<br>
> diff -r d56b2466c044 -r 51320561d41f source/encoder/slicetype.h<br>
> --- a/source/encoder/slicetype.h Wed Aug 12 18:12:20 2015 +0530<br>
> +++ b/source/encoder/slicetype.h Wed Jul 22 00:29:26 2015 +0530<br>
> @@ -127,7 +127,7 @@<br>
> int m_numCoopSlices;<br>
> int m_numRowsPerSlice;<br>
> bool m_filled;<br>
> -<br>
> + bool m_isSceneTransition;<br>
> Lookahead(x265_param *param, ThreadPool *pool);<br>
><br>
> #if DETAILED_CU_STATS<br>
> @@ -156,7 +156,7 @@<br>
> void slicetypeAnalyse(Lowres **frames, bool bKeyframe);<br>
><br>
> /* called by slicetypeAnalyse() to make slice decisions */<br>
> - bool scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, int numFrames, int maxSearch);<br>
> + bool scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, int numFrames);<br>
> bool scenecutInternal(Lowres **frames, int p0, int p1, bool bRealScenecut);<br>
> void slicetypePath(Lowres **frames, int length, char(*best_paths)[X265_LOOKAHEAD_MAX + 1]);<br>
> int64_t slicetypePathCost(Lowres **frames, char *path, int64_t threshold);<br>
> _______________________________________________<br>
> x265-devel mailing list<br>
> <a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
> <a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Steve Borho<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</div></div></blockquote></div><br></div>