<div dir="ltr">So, the general idea here is to reuse analysis data from lower resolution encodes (save mode) for higher resolution encodes (load mode). The compression efficiency loss here will always be higher, than, if you used high-res analysis data for low-res encodes. </div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 2, 2017 at 10:58 PM, <span dir="ltr"><<a href="mailto:kavitha@multicorewareinc.com" target="_blank">kavitha@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Kavitha Sampath <<a href="mailto:kavitha@multicorewareinc.com">kavitha@multicorewareinc.com</a>><br>
# Date 1495615463 -19800<br>
# Wed May 24 14:14:23 2017 +0530<br>
# Node ID 802bb7ead1e0151a604bc293451c73<wbr>5990656162<br>
# Parent 404253434d33e99955aac29480ee16<wbr>b8e939a64c<br>
Reuse analysis info of low resolution for full resolution encoding.<br>
<br>
New CLI option --scale-factor is added. This option should be coupled<br>
with analysis-mode, --refine-level 10. It specifies the factor<br>
by which input video of save mode should be scaled down.<br>
Currently only scale-factor 2 is supported.<br>
<br>
diff -r 404253434d33 -r 802bb7ead1e0 source/common/cudata.cpp<br>
--- a/source/common/cudata.cpp Wed May 24 08:39:45 2017 +0530<br>
+++ b/source/common/cudata.cpp Wed May 24 14:14:23 2017 +0530<br>
@@ -28,6 +28,7 @@<br>
#include "picyuv.h"<br>
#include "mv.h"<br>
#include "cudata.h"<br>
+#define MAX_MV 1 << 14<br>
<br>
using namespace X265_NS;<br>
<br>
@@ -1623,6 +1624,11 @@<br>
dir |= (1 << list);<br>
candMvField[count][list].mv = colmv;<br>
candMvField[count][list].<wbr>refIdx = refIdx;<br>
+ if (m_encData->m_param-><wbr>scaleFactor && m_encData->m_param-><wbr>analysisMode == X265_ANALYSIS_SAVE && m_log2CUSize[0] < 4)<br>
+ {<br>
+ MV dist(MAX_MV, MAX_MV);<br>
+ candMvField[count][list].mv = dist;<br>
+ }<br>
}<br>
}<br>
<br>
@@ -1783,7 +1789,13 @@<br>
int curRefPOC = m_slice->m_refPOCList[picList]<wbr>[refIdx];<br>
int curPOC = m_slice->m_poc;<br>
<br>
- pmv[numMvc++] = amvpCand[num++] = scaleMvByPOCDist(neighbours[<wbr>MD_COLLOCATED].mv[picList], curPOC, curRefPOC, colPOC, colRefPOC);<br>
+ if (m_encData->m_param-><wbr>scaleFactor && m_encData->m_param-><wbr>analysisMode == X265_ANALYSIS_SAVE && (m_log2CUSize[0] < 4))<br>
+ {<br>
+ MV dist(MAX_MV, MAX_MV);<br>
+ pmv[numMvc++] = amvpCand[num++] = dist;<br>
+ }<br>
+ else<br>
+ pmv[numMvc++] = amvpCand[num++] = scaleMvByPOCDist(neighbours[<wbr>MD_COLLOCATED].mv[picList], curPOC, curRefPOC, colPOC, colRefPOC);<br>
}<br>
}<br>
<br>
diff -r 404253434d33 -r 802bb7ead1e0 source/encoder/analysis.cpp<br>
--- a/source/encoder/analysis.cpp Wed May 24 08:39:45 2017 +0530<br>
+++ b/source/encoder/analysis.cpp Wed May 24 14:14:23 2017 +0530<br>
@@ -2263,6 +2263,19 @@<br>
mode.cu.m_mvd[list][pu.<wbr>puAbsPartIdx] = mode.cu.m_mv[list][pu.<wbr>puAbsPartIdx] - mvp;<br>
}<br>
}<br>
+ else if(m_param->scaleFactor)<br>
+ {<br>
+ MVField candMvField[MRG_MAX_NUM_CANDS]<wbr>[2]; // double length for mv of both lists<br>
+ uint8_t candDir[MRG_MAX_NUM_CANDS];<br>
+ <a href="http://mode.cu">mode.cu</a>.<wbr>getInterMergeCandidates(pu.<wbr>puAbsPartIdx, part, candMvField, candDir);<br>
+ mode.cu.m_mvpIdx[0][pu.<wbr>puAbsPartIdx] = interDataCTU->mvpIdx[0][cuIdx + part];<br>
+ uint8_t mvpIdx = mode.cu.m_mvpIdx[0][pu.<wbr>puAbsPartIdx];<br>
+ mode.cu.setPUInterDir(candDir[<wbr>mvpIdx], pu.puAbsPartIdx, part);<br>
+ mode.cu.setPUMv(0, candMvField[mvpIdx][0].mv, pu.puAbsPartIdx, part);<br>
+ mode.cu.setPUMv(1, candMvField[mvpIdx][1].mv, pu.puAbsPartIdx, part);<br>
+ mode.cu.setPURefIdx(0, (int8_t)candMvField[mvpIdx][0]<wbr>.refIdx, pu.puAbsPartIdx, part);<br>
+ mode.cu.setPURefIdx(1, (int8_t)candMvField[mvpIdx][1]<wbr>.refIdx, pu.puAbsPartIdx, part);<br>
+ }<br>
}<br>
motionCompensation(<a href="http://mode.cu" rel="noreferrer" target="_blank">mode.cu</a>, pu, mode.predYuv, true, (m_csp != X265_CSP_I400 && m_frame->m_fencPic->m_picCsp != X265_CSP_I400));<br>
}<br>
diff -r 404253434d33 -r 802bb7ead1e0 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Wed May 24 08:39:45 2017 +0530<br>
+++ b/source/encoder/encoder.cpp Wed May 24 14:14:23 2017 +0530<br>
@@ -2839,6 +2839,11 @@<br>
X265_FREAD(&analysis-><wbr>satdCost, sizeof(int64_t), 1, m_analysisFile);<br>
X265_FREAD(&analysis-><wbr>numCUsInFrame, sizeof(int), 1, m_analysisFile);<br>
X265_FREAD(&analysis-><wbr>numPartitions, sizeof(int), 1, m_analysisFile);<br>
+ int scaledNumPartition = analysis->numPartitions;<br>
+ int factor = 1 << m_param->scaleFactor;<br>
+<br>
+ if (m_param->scaleFactor)<br>
+ analysis->numPartitions *= factor;<br>
<br>
/* Memory is allocated for inter and intra analysis data based on the slicetype */<br>
allocAnalysis(analysis);<br>
@@ -2862,12 +2867,31 @@<br>
for (uint32_t d = 0; d < depthBytes; d++)<br>
{<br>
int bytes = analysis->numPartitions >> (depthBuf[d] * 2);<br>
+ if (m_param->scaleFactor)<br>
+ {<br>
+ if (depthBuf[d] == 0)<br>
+ depthBuf[d] = 1;<br>
+ if (partSizes[d] == SIZE_NxN)<br>
+ partSizes[d] = SIZE_2Nx2N;<br>
+ }<br>
memset(&((analysis_intra_data *)analysis->intraData)->depth[<wbr>count], depthBuf[d], bytes);<br>
memset(&((analysis_intra_data *)analysis->intraData)-><wbr>chromaModes[count], modeBuf[d], bytes);<br>
memset(&((analysis_intra_data *)analysis->intraData)-><wbr>partSizes[count], partSizes[d], bytes);<br>
count += bytes;<br>
}<br>
- X265_FREAD(((analysis_intra_<wbr>data *)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFile);<br>
+<br>
+ if (!m_param->scaleFactor)<br>
+ {<br>
+ X265_FREAD(((analysis_intra_<wbr>data *)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFile);<br>
+ }<br>
+ else<br>
+ {<br>
+ uint8_t *tempLumaBuf = X265_MALLOC(uint8_t, analysis->numCUsInFrame * scaledNumPartition);<br>
+ X265_FREAD(tempLumaBuf, sizeof(uint8_t), analysis->numCUsInFrame * scaledNumPartition, m_analysisFile);<br>
+ for (uint32_t ctu32Idx = 0, cnt = 0; ctu32Idx < analysis->numCUsInFrame * scaledNumPartition; ctu32Idx++, cnt += factor)<br>
+ memset(&((analysis_intra_data *)analysis->intraData)->modes[<wbr>cnt], tempLumaBuf[ctu32Idx], factor);<br>
+ X265_FREE(tempLumaBuf);<br>
+ }<br>
X265_FREE(tempBuf);<br>
consumedBytes += frameRecordSize;<br>
}<br>
@@ -2923,12 +2947,16 @@<br>
for (uint32_t d = 0; d < depthBytes; d++)<br>
{<br>
int bytes = analysis->numPartitions >> (depthBuf[d] * 2);<br>
+ if (m_param->scaleFactor && modeBuf[d] == MODE_INTRA && depthBuf[d] == 0)<br>
+ depthBuf[d] = 1;<br>
memset(&((analysis_inter_data *)analysis->interData)->depth[<wbr>count], depthBuf[d], bytes);<br>
memset(&((analysis_inter_data *)analysis->interData)->modes[<wbr>count], modeBuf[d], bytes);<br>
if (m_param->analysisRefineLevel > 4)<br>
{<br>
+ if (m_param->scaleFactor && modeBuf[d] == MODE_INTRA && partSize[d] == SIZE_NxN)<br>
+ partSize[d] = SIZE_2Nx2N;<br>
memset(&((analysis_inter_data *)analysis->interData)-><wbr>partSize[count], partSize[d], bytes);<br>
- int numPU = nbPartsTable[(int)partSize[d]]<wbr>;<br>
+ int numPU = (modeBuf[d] == MODE_INTRA) ? 1 : nbPartsTable[(int)partSize[d]]<wbr>;<br>
for (int pu = 0; pu < numPU; pu++)<br>
{<br>
if (pu) d++;<br>
@@ -2940,6 +2968,11 @@<br>
{<br>
((analysis_inter_data *)analysis->interData)-><wbr>mvpIdx[i][count + pu] = mvpIdx[i][d];<br>
((analysis_inter_data *)analysis->interData)-><wbr>refIdx[i][count + pu] = refIdx[i][d];<br>
+ if (m_param->scaleFactor)<br>
+ {<br>
+ mv[i][d].x *= (int16_t)m_param->scaleFactor;<br>
+ mv[i][d].y *= (int16_t)m_param->scaleFactor;<br>
+ }<br>
memcpy(&((analysis_inter_data *)analysis->interData)->mv[i][<wbr>count + pu], &mv[i][d], sizeof(MV));<br>
}<br>
}<br>
@@ -2961,7 +2994,20 @@<br>
X265_FREE(mv[i]);<br>
}<br>
if (bIntraInInter)<br>
- X265_FREAD(((analysis_intra_<wbr>data *)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFile);<br>
+ {<br>
+ if (!m_param->scaleFactor)<br>
+ {<br>
+ X265_FREAD(((analysis_intra_<wbr>data *)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFile);<br>
+ }<br>
+ else<br>
+ {<br>
+ uint8_t *tempLumaBuf = X265_MALLOC(uint8_t, analysis->numCUsInFrame * scaledNumPartition);<br>
+ X265_FREAD(tempLumaBuf, sizeof(uint8_t), analysis->numCUsInFrame * scaledNumPartition, m_analysisFile);<br>
+ for (uint32_t ctu32Idx = 0, cnt = 0; ctu32Idx < analysis->numCUsInFrame * scaledNumPartition; ctu32Idx++, cnt += factor)<br>
+ memset(&((analysis_intra_data *)analysis->intraData)->modes[<wbr>cnt], tempLumaBuf[ctu32Idx], factor);<br>
+ X265_FREE(tempLumaBuf);<br>
+ }<br>
+ }<br>
}<br>
else<br>
X265_FREAD(((analysis_inter_<wbr>data *)analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir, m_analysisFile);<br>
@@ -3183,7 +3229,7 @@<br>
interDataCTU->partSize[<wbr>depthBytes] = partSize;<br>
<br>
/* Store per PU data */<br>
- uint32_t numPU = nbPartsTable[(int)partSize];<br>
+ uint32_t numPU = (predMode == MODE_INTRA) ? 1 : nbPartsTable[(int)partSize];<br>
for (uint32_t puIdx = 0; puIdx < numPU; puIdx++)<br>
{<br>
uint32_t puabsPartIdx = ctu->getPUOffset(puIdx, absPartIdx) + absPartIdx;<br>
diff -r 404253434d33 -r 802bb7ead1e0 source/encoder/slicetype.cpp<br>
--- a/source/encoder/slicetype.cpp Wed May 24 08:39:45 2017 +0530<br>
+++ b/source/encoder/slicetype.cpp Wed May 24 14:14:23 2017 +0530<br>
@@ -893,7 +893,7 @@<br>
if (m_param->rc.cuTree && !m_param->rc.bStatRead)<br>
/* update row satds based on cutree offsets */<br>
curFrame->m_lowres.satdCost = frameCostRecalculate(frames, p0, p1, b);<br>
- else if (m_param->analysisMode != X265_ANALYSIS_LOAD)<br>
+ else if (m_param->analysisMode != X265_ANALYSIS_LOAD || m_param->scaleFactor)<br>
{<br>
if (m_param->rc.aqMode)<br>
curFrame->m_lowres.satdCost = curFrame->m_lowres.costEstAq[b - p0][p1 - b];<br>
______________________________<wbr>_________________<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/<wbr>listinfo/x265-devel</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Deepthi</div>
</div>