[x265] [PATCH] Avoid calling slicetypeDecide() routine when analysis-load is enabled
Ashok Kumar Mishra
ashok at multicorewareinc.com
Mon Jul 2 16:15:35 CEST 2018
On Mon, Jul 2, 2018 at 7:37 PM, <bhavna at multicorewareinc.com> wrote:
> # HG changeset patch
> # User Bhavna Hariharan <bhavna at multicorewareinc.com>
> # Date 1530094711 -19800
> # Wed Jun 27 15:48:31 2018 +0530
> # Node ID 0a629ea6036b24d60d0a1bc8a7b2f6d5cc476a02
> # Parent 289b8a3730ae108bbb9e4b295dc915205ba2d0e9
> Avoid calling slicetypeDecide() routine when analysis-load is enabled.
>
> This patch does the following:
> 1) Bypass slicetypeDecide() call for analysis-load
> 2) Update params that must match between analysis save and load runs
>
> diff -r 289b8a3730ae -r 0a629ea6036b source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cpp Fri Jun 22 11:47:36 2018 +0530
> +++ b/source/encoder/encoder.cpp Wed Jun 27 15:48:31 2018 +0530
> @@ -4105,6 +4105,7 @@
> int readValue = 0;
> int count = 0;
>
> + X265_PARAM_VALIDATE(saveParam->intraRefresh, sizeof(int), 1,
> &m_param->bIntraRefresh, intra-refresh);
> X265_PARAM_VALIDATE(saveParam->maxNumReferences, sizeof(int), 1,
> &m_param->maxNumReferences, ref);
> X265_PARAM_VALIDATE(saveParam->analysisReuseLevel, sizeof(int), 1,
> &m_param->analysisReuseLevel, analysis-reuse-level);
> X265_PARAM_VALIDATE(saveParam->keyframeMax, sizeof(int), 1,
> &m_param->keyframeMax, keyint);
> @@ -4113,9 +4114,9 @@
> X265_PARAM_VALIDATE(saveParam->bframes, sizeof(int), 1,
> &m_param->bframes, bframes);
> X265_PARAM_VALIDATE(saveParam->bPyramid, sizeof(int), 1,
> &m_param->bBPyramid, bPyramid);
> X265_PARAM_VALIDATE(saveParam->minCUSize, sizeof(int), 1,
> &m_param->minCUSize, min - cu - size);
> - X265_PARAM_VALIDATE(saveParam->radl, sizeof(int), 1, &m_param->radl,
> radl);
> X265_PARAM_VALIDATE(saveParam->lookaheadDepth, sizeof(int), 1,
> &m_param->lookaheadDepth, rc - lookahead);
> - X265_PARAM_VALIDATE(saveParam->gopLookahead, sizeof(int), 1,
> &m_param->gopLookahead, gop - lookahead);
> + X265_PARAM_VALIDATE(saveParam->chunkStart, sizeof(int), 1,
> &m_param->chunkStart, chunk-start);
> + X265_PARAM_VALIDATE(saveParam->chunkEnd, sizeof(int), 1,
> &m_param->chunkEnd, chunk-end);
>
> int sourceHeight, sourceWidth;
> if (writeFlag)
> @@ -4133,8 +4134,8 @@
> int curSourceHeight = m_param->sourceHeight - m_conformanceWindow.
> bottomOffset;
> int curSourceWidth = m_param->sourceWidth - m_conformanceWindow.
> rightOffset;
>
> - X265_FREAD(&sourceWidth, sizeof(int), 1, m_analysisFileIn,
> &(saveParam->sourceHeight));
> - X265_FREAD(&sourceHeight, sizeof(int), 1, m_analysisFileIn,
> &(saveParam->sourceWidth));
> + X265_FREAD(&sourceWidth, sizeof(int), 1, m_analysisFileIn,
> &(saveParam->sourceWidth));
> + X265_FREAD(&sourceHeight, sizeof(int), 1, m_analysisFileIn,
> &(saveParam->sourceHeight));
> X265_FREAD(&readValue, sizeof(int), 1, m_analysisFileIn,
> &(saveParam->maxCUSize));
>
> bool isScaledRes = (2 * sourceHeight == curSourceHeight) && (2 *
> sourceWidth == curSourceWidth);
> diff -r 289b8a3730ae -r 0a629ea6036b source/encoder/slicetype.cpp
> --- a/source/encoder/slicetype.cpp Fri Jun 22 11:47:36 2018 +0530
> +++ b/source/encoder/slicetype.cpp Wed Jun 27 15:48:31 2018 +0530
> @@ -1088,86 +1088,105 @@
> }
>
> int bframes, brefs;
> - for (bframes = 0, brefs = 0;; bframes++)
> + if (!m_param->analysisLoad)
> {
> - Lowres& frm = list[bframes]->m_lowres;
> -
> - if (frm.sliceType == X265_TYPE_BREF && !m_param->bBPyramid &&
> brefs == m_param->bBPyramid)
> + for (bframes = 0, brefs = 0;; bframes++)
> {
> - frm.sliceType = X265_TYPE_B;
> - x265_log(m_param, X265_LOG_WARNING, "B-ref at frame %d
> incompatible with B-pyramid\n",
> - frm.frameNum);
> - }
> + Lowres& frm = list[bframes]->m_lowres;
> +
> + if (frm.sliceType == X265_TYPE_BREF && !m_param->bBPyramid &&
> brefs == m_param->bBPyramid)
> + {
> + frm.sliceType = X265_TYPE_B;
> + x265_log(m_param, X265_LOG_WARNING, "B-ref at frame %d
> incompatible with B-pyramid\n",
> + frm.frameNum);
> + }
>
> - /* pyramid with multiple B-refs needs a big enough dpb that the
> preceding P-frame stays available.
> - * smaller dpb could be supported by smart enough use of mmco,
> but it's easier just to forbid it. */
> - else if (frm.sliceType == X265_TYPE_BREF && m_param->bBPyramid &&
> brefs &&
> - m_param->maxNumReferences <= (brefs + 3))
> - {
> - frm.sliceType = X265_TYPE_B;
> - x265_log(m_param, X265_LOG_WARNING, "B-ref at frame %d
> incompatible with B-pyramid and %d reference frames\n",
> - frm.sliceType, m_param->maxNumReferences);
> + /* pyramid with multiple B-refs needs a big enough dpb that
> the preceding P-frame stays available.
> + * smaller dpb could be supported by smart enough use of
> mmco, but it's easier just to forbid it. */
> + else if (frm.sliceType == X265_TYPE_BREF &&
> m_param->bBPyramid && brefs &&
> + m_param->maxNumReferences <= (brefs + 3))
> + {
> + frm.sliceType = X265_TYPE_B;
> + x265_log(m_param, X265_LOG_WARNING, "B-ref at frame %d
> incompatible with B-pyramid and %d reference frames\n",
> + frm.sliceType, m_param->maxNumReferences);
> + }
> + if (((!m_param->bIntraRefresh || frm.frameNum == 0) &&
> frm.frameNum - m_lastKeyframe >= m_param->keyframeMax &&
> + (!m_extendGopBoundary || frm.frameNum - m_lastKeyframe >=
> m_param->keyframeMax + m_param->gopLookahead)) ||
> + (frm.frameNum == (m_param->chunkStart - 1)) ||
> (frm.frameNum == m_param->chunkEnd))
> + {
> + if (frm.sliceType == X265_TYPE_AUTO || frm.sliceType ==
> X265_TYPE_I)
> + frm.sliceType = m_param->bOpenGOP && m_lastKeyframe
> >= 0 ? X265_TYPE_I : X265_TYPE_IDR;
> + bool warn = frm.sliceType != X265_TYPE_IDR;
> + if (warn && m_param->bOpenGOP)
> + warn &= frm.sliceType != X265_TYPE_I;
> + if (warn)
> + {
> + x265_log(m_param, X265_LOG_WARNING, "specified frame
> type (%d) at %d is not compatible with keyframe interval\n",
> + frm.sliceType, frm.frameNum);
> + frm.sliceType = m_param->bOpenGOP && m_lastKeyframe
> >= 0 ? X265_TYPE_I : X265_TYPE_IDR;
> + }
> + }
> + if ((frm.sliceType == X265_TYPE_I && frm.frameNum -
> m_lastKeyframe >= m_param->keyframeMin) || (frm.frameNum ==
> (m_param->chunkStart - 1)) || (frm.frameNum == m_param->chunkEnd))
> + {
> + if (m_param->bOpenGOP)
> + {
> + m_lastKeyframe = frm.frameNum;
> + frm.bKeyframe = true;
> + }
> + else
> + frm.sliceType = X265_TYPE_IDR;
> + }
> + if (frm.sliceType == X265_TYPE_IDR)
> + {
> + /* Closed GOP */
> + m_lastKeyframe = frm.frameNum;
> + frm.bKeyframe = true;
> + if (bframes > 0 && !m_param->radl)
> + {
> + list[bframes - 1]->m_lowres.sliceType = X265_TYPE_P;
> + bframes--;
> + }
> + }
> + if (m_param->radl && !m_param->bOpenGOP && list[bframes + 1])
> + {
> + if ((frm.frameNum - m_lastKeyframe) >
> (m_param->keyframeMax - m_param->radl - 1) && (frm.frameNum -
> m_lastKeyframe) < m_param->keyframeMax)
> + frm.sliceType = X265_TYPE_B;
> + if ((frm.frameNum - m_lastKeyframe) ==
> (m_param->keyframeMax - m_param->radl - 1))
> + frm.sliceType = X265_TYPE_P;
> + }
> +
> + if (bframes == m_param->bframes || !list[bframes + 1])
> + {
> + if (IS_X265_TYPE_B(frm.sliceType))
> + x265_log(m_param, X265_LOG_WARNING, "specified frame
> type is not compatible with max B-frames\n");
> + if (frm.sliceType == X265_TYPE_AUTO ||
> IS_X265_TYPE_B(frm.sliceType))
> + frm.sliceType = X265_TYPE_P;
> + }
> + if (frm.sliceType == X265_TYPE_BREF)
> + brefs++;
> + if (frm.sliceType == X265_TYPE_AUTO)
> + frm.sliceType = X265_TYPE_B;
> + else if (!IS_X265_TYPE_B(frm.sliceType))
> + break;
> }
> - if (((!m_param->bIntraRefresh || frm.frameNum == 0) &&
> frm.frameNum - m_lastKeyframe >= m_param->keyframeMax &&
> - (!m_extendGopBoundary || frm.frameNum - m_lastKeyframe >=
> m_param->keyframeMax + m_param->gopLookahead)) ||
> - (frm.frameNum == (m_param->chunkStart - 1)) || (frm.frameNum
> == m_param->chunkEnd))
> + }
> + else
> + {
> + for (bframes = 0, brefs = 0;; bframes++)
> {
> - if (frm.sliceType == X265_TYPE_AUTO || frm.sliceType ==
> X265_TYPE_I)
> - frm.sliceType = m_param->bOpenGOP && m_lastKeyframe >= 0
> ? X265_TYPE_I : X265_TYPE_IDR;
> - bool warn = frm.sliceType != X265_TYPE_IDR;
> - if (warn && m_param->bOpenGOP)
> - warn &= frm.sliceType != X265_TYPE_I;
> - if (warn)
> - {
> - x265_log(m_param, X265_LOG_WARNING, "specified frame type
> (%d) at %d is not compatible with keyframe interval\n",
> - frm.sliceType, frm.frameNum);
> - frm.sliceType = m_param->bOpenGOP && m_lastKeyframe >= 0
> ? X265_TYPE_I : X265_TYPE_IDR;
> - }
> - }
> - if ((frm.sliceType == X265_TYPE_I && frm.frameNum -
> m_lastKeyframe >= m_param->keyframeMin) || (frm.frameNum ==
> (m_param->chunkStart - 1)) || (frm.frameNum == m_param->chunkEnd))
> - {
> - if (m_param->bOpenGOP)
> + Lowres& frm = list[bframes]->m_lowres;
> + if (frm.sliceType == X265_TYPE_BREF)
> + brefs++;
> + if ((IS_X265_TYPE_I(frm.sliceType) && frm.frameNum -
> m_lastKeyframe >= m_param->keyframeMin)
> + || (frm.frameNum == (m_param->chunkStart - 1)) ||
> (frm.frameNum == m_param->chunkEnd))
> {
> m_lastKeyframe = frm.frameNum;
> frm.bKeyframe = true;
> }
> - else
> - frm.sliceType = X265_TYPE_IDR;
> - }
> - if (frm.sliceType == X265_TYPE_IDR)
> - {
> - /* Closed GOP */
> - m_lastKeyframe = frm.frameNum;
> - frm.bKeyframe = true;
> - if (bframes > 0 && !m_param->radl)
> - {
> - list[bframes - 1]->m_lowres.sliceType = X265_TYPE_P;
> - bframes--;
> - }
> + if (!IS_X265_TYPE_B(frm.sliceType))
> + break;
> }
> - if (m_param->radl && !m_param->bOpenGOP && list[bframes + 1])
> - {
> - if ((frm.frameNum - m_lastKeyframe) > (m_param->keyframeMax
> - m_param->radl - 1) && (frm.frameNum - m_lastKeyframe) <
> m_param->keyframeMax)
> - frm.sliceType = X265_TYPE_B;
> - if ((frm.frameNum - m_lastKeyframe) == (m_param->keyframeMax
> - m_param->radl - 1))
> - frm.sliceType = X265_TYPE_P;
> - }
> -
> - if (bframes == m_param->bframes || !list[bframes + 1])
> - {
> - if (IS_X265_TYPE_B(frm.sliceType))
> - x265_log(m_param, X265_LOG_WARNING, "specified frame type
> is not compatible with max B-frames\n");
> - if (frm.sliceType == X265_TYPE_AUTO ||
> IS_X265_TYPE_B(frm.sliceType))
> - frm.sliceType = X265_TYPE_P;
> - }
> - if (frm.sliceType == X265_TYPE_BREF)
> - brefs++;
> - if (frm.sliceType == X265_TYPE_AUTO)
> - frm.sliceType = X265_TYPE_B;
> - else if (!IS_X265_TYPE_B(frm.sliceType))
> - break;
> }
> -
> if (bframes)
> list[bframes - 1]->m_lowres.bLastMiniGopBFrame = true;
> list[bframes]->m_lowres.leadingBframes = bframes;
> diff -r 289b8a3730ae -r 0a629ea6036b source/x265.h
> --- a/source/x265.h Fri Jun 22 11:47:36 2018 +0530
> +++ b/source/x265.h Wed Jun 27 15:48:31 2018 +0530
> @@ -121,9 +121,10 @@
> int bPyramid;
> int maxCUSize;
> int minCUSize;
> - int radl;
> + int intraRefresh;
> int lookaheadDepth;
> - int gopLookahead;
> + int chunkStart;
> + int chunkEnd;
> }x265_analysis_validate;
>
> /* Stores all analysis data for a single frame */
>
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
>
Pushed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20180702/4a581fa8/attachment-0001.html>
More information about the x265-devel
mailing list