<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 8, 2018 at 5:44 PM,  <span dir="ltr"><<a href="mailto:aruna@multicorewareinc.com" target="_blank">aruna@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 Aruna Matheswaran <<a href="mailto:aruna@multicorewareinc.com">aruna@multicorewareinc.com</a>><br>
# Date 1526883919 -19800<br>
#      Mon May 21 11:55:19 2018 +0530<br>
# Node ID 00eec4796d233e72d6344c7f4c9d5c<wbr>69a9c55501<br>
# Parent  ed853c4af6710a991d0cdf4bf68e00<wbr>fe32edaacb<br>
Use the data structure of analysis-save/load for multi-pass-opt-analysis/multi-<wbr>pass-opt-distortion.<br>
<br>
diff -r ed853c4af671 -r 00eec4796d23 source/common/frame.cpp<br>
--- a/source/common/frame.cpp   Fri Apr 06 14:35:00 2018 +0530<br>
+++ b/source/common/frame.cpp   Mon May 21 11:55:19 2018 +0530<br>
@@ -83,7 +83,7 @@<br>
         m_analysisData.wt = NULL;<br>
         m_analysisData.intraData = NULL;<br>
         m_analysisData.interData = NULL;<br>
-        m_analysis2Pass.<wbr>analysisFramedata = NULL;<br>
+        m_analysisData.distortionData = NULL;<br>
     }<br>
<br>
     if (param->bDynamicRefine)<br>
diff -r ed853c4af671 -r 00eec4796d23 source/common/frame.h<br>
--- a/source/common/frame.h     Fri Apr 06 14:35:00 2018 +0530<br>
+++ b/source/common/frame.h     Mon May 21 11:55:19 2018 +0530<br>
@@ -109,7 +109,6 @@<br>
     Frame*                 m_prev;<br>
     x265_param*            m_param;              // Points to the latest param set for the frame.<br>
     x265_analysis_data     m_analysisData;<br>
-    x265_analysis_2Pass    m_analysis2Pass;<br>
     RcStats*               m_rcData;<br>
<br>
     Event                  m_copyMVType;<br>
diff -r ed853c4af671 -r 00eec4796d23 source/common/framedata.h<br>
--- a/source/common/framedata.h Fri Apr 06 14:35:00 2018 +0530<br>
+++ b/source/common/framedata.h Mon May 21 11:55:19 2018 +0530<br>
@@ -203,13 +203,8 @@<br>
    int64_t*     sadCost;<br>
 };<br>
<br>
-struct analysis2PassFrameData<br>
+struct analysisDistortionData<br>
 {<br>
-    uint8_t*      depth;<br>
-    MV*           m_mv[2];<br>
-    int*          mvpIdx[2];<br>
-    int32_t*      ref[2];<br>
-    uint8_t*      modes;<br>
     sse_t*        distortion;<br>
     sse_t*        ctuDistortion;<br>
     double*       scaledDistortion;<br>
diff -r ed853c4af671 -r 00eec4796d23 source/encoder/analysis.cpp<br>
--- a/source/encoder/analysis.cpp       Fri Apr 06 14:35:00 2018 +0530<br>
+++ b/source/encoder/analysis.cpp       Mon May 21 11:55:19 2018 +0530<br>
@@ -187,23 +187,20 @@<br>
         for (uint32_t i = 0; i < cuGeom.numPartitions; i++)<br>
             ctu.m_log2CUSize[i] = (uint8_t)m_param-><wbr>maxLog2CUSize - ctu.m_cuDepth[i];<br>
     }<br>
-    if (m_param-><wbr>analysisMultiPassRefine && m_param->rc.bStatRead)<br>
+    if (m_param-><wbr>analysisMultiPassRefine && m_param->rc.bStatRead && (m_slice->m_sliceType != I_SLICE))<br>
     {<br>
-        m_multipassAnalysis = (analysis2PassFrameData*)m_<wbr>frame->m_analysis2Pass.<wbr>analysisFramedata;<br>
-        m_multipassDepth = &m_multipassAnalysis->depth[<wbr>ctu.m_cuAddr * ctu.m_numPartitions];<br>
-        if (m_slice->m_sliceType != I_SLICE)<br>
+        int numPredDir = m_slice->isInterP() ? 1 : 2;<br>
+        m_reuseInterDataCTU = (analysis_inter_data*)m_frame-<wbr>>m_analysisData.interData;<br>
+        for (int dir = 0; dir < numPredDir; dir++)<br>
         {<br>
-            int numPredDir = m_slice->isInterP() ? 1 : 2;<br>
-            for (int dir = 0; dir < numPredDir; dir++)<br>
-            {<br>
-                m_multipassMv[dir] = &m_multipassAnalysis->m_mv[<wbr>dir][ctu.m_cuAddr * ctu.m_numPartitions];<br>
-                m_multipassMvpIdx[dir] = &m_multipassAnalysis->mvpIdx[<wbr>dir][ctu.m_cuAddr * ctu.m_numPartitions];<br>
-                m_multipassRef[dir] = &m_multipassAnalysis->ref[dir]<wbr>[ctu.m_cuAddr * ctu.m_numPartitions];<br>
-            }<br>
-            m_multipassModes = &m_multipassAnalysis->modes[<wbr>ctu.m_cuAddr * ctu.m_numPartitions];<br>
+            m_reuseMv[dir] = &m_reuseInterDataCTU->mv[dir][<wbr>ctu.m_cuAddr * ctu.m_numPartitions];<br>
+            m_reuseMvpIdx[dir] = &m_reuseInterDataCTU->mvpIdx[<wbr>dir][ctu.m_cuAddr * ctu.m_numPartitions];<br>
         }<br>
+        m_reuseRef = &m_reuseInterDataCTU->ref[ctu.<wbr>m_cuAddr * ctu.m_numPartitions];<br>
+        m_reuseModes = &m_reuseInterDataCTU->modes[<wbr>ctu.m_cuAddr * ctu.m_numPartitions];<br>
+        m_reuseDepth = &m_reuseInterDataCTU->depth[<wbr>ctu.m_cuAddr * ctu.m_numPartitions];<br>
     }<br>
-<br>
+    <br>
     if ((m_param->analysisSave || m_param->analysisLoad) && m_slice->m_sliceType != I_SLICE && m_param->analysisReuseLevel > 1 && m_param->analysisReuseLevel < 10)<br>
     {<br>
         int numPredDir = m_slice->isInterP() ? 1 : 2;<br>
@@ -1284,11 +1281,11 @@<br>
                 }<br>
             }<br>
         }<br>
-        if (m_param-><wbr>analysisMultiPassRefine && m_param->rc.bStatRead && m_multipassAnalysis)<br>
+        if (m_param-><wbr>analysisMultiPassRefine && m_param->rc.bStatRead && m_reuseInterDataCTU)<br>
         {<br>
-            if (mightNotSplit && depth == m_multipassDepth[cuGeom.<wbr>absPartIdx])<br>
+            if (mightNotSplit && depth == m_reuseDepth[cuGeom.<wbr>absPartIdx])<br>
             {<br>
-                if (m_multipassModes[cuGeom.<wbr>absPartIdx] == MODE_SKIP)<br>
+                if (m_reuseModes[cuGeom.<wbr>absPartIdx] == MODE_SKIP)<br>
                 {<br>
                     md.pred[PRED_MERGE].cu.<wbr>initSubCU(parentCTU, cuGeom, qp);<br>
                     md.pred[PRED_SKIP].cu.<wbr>initSubCU(parentCTU, cuGeom, qp);<br>
@@ -1977,11 +1974,11 @@<br>
             }<br>
         }<br>
<br>
-        if (m_param-><wbr>analysisMultiPassRefine && m_param->rc.bStatRead && m_multipassAnalysis)<br>
+        if (m_param-><wbr>analysisMultiPassRefine && m_param->rc.bStatRead && m_reuseInterDataCTU)<br>
         {<br>
-            if (mightNotSplit && depth == m_multipassDepth[cuGeom.<wbr>absPartIdx])<br>
+            if (mightNotSplit && depth == m_reuseDepth[cuGeom.<wbr>absPartIdx])<br>
             {<br>
-                if (m_multipassModes[cuGeom.<wbr>absPartIdx] == MODE_SKIP)<br>
+                if (m_reuseModes[cuGeom.<wbr>absPartIdx] == MODE_SKIP)<br>
                 {<br>
                     md.pred[PRED_MERGE].cu.<wbr>initSubCU(parentCTU, cuGeom, qp);<br>
                     md.pred[PRED_SKIP].cu.<wbr>initSubCU(parentCTU, cuGeom, qp);<br>
@@ -3015,7 +3012,7 @@<br>
         }<br>
     }<br>
<br>
-    if (m_param-><wbr>analysisMultiPassRefine && m_param->rc.bStatRead && m_multipassAnalysis)<br>
+    if (m_param-><wbr>analysisMultiPassRefine && m_param->rc.bStatRead && m_reuseInterDataCTU)<br>
     {<br>
         uint32_t numPU = interMode.cu.getNumPartInter(<wbr>0);<br>
         for (uint32_t part = 0; part < numPU; part++)<br>
@@ -3023,9 +3020,10 @@<br>
             MotionData* bestME = interMode.bestME[part];<br>
             for (int32_t i = 0; i < numPredDir; i++)<br>
             {<br>
-                bestME[i].ref = m_multipassRef[i][cuGeom.<wbr>absPartIdx];<br>
-                bestME[i].mv = m_multipassMv[i][cuGeom.<wbr>absPartIdx];<br>
-                bestME[i].mvpIdx = m_multipassMvpIdx[i][cuGeom.<wbr>absPartIdx];<br>
+                int* ref = &m_reuseRef[i * m_frame->m_analysisData.<wbr>numPartitions * m_frame->m_analysisData.<wbr>numCUsInFrame];<br>
+                bestME[i].ref = ref[cuGeom.absPartIdx];<br>
+                bestME[i].mv = m_reuseMv[i][cuGeom.<wbr>absPartIdx];<br>
+                bestME[i].mvpIdx = m_reuseMvpIdx[i][cuGeom.<wbr>absPartIdx];<br>
             }<br>
         }<br>
     }<br>
@@ -3079,7 +3077,7 @@<br>
         }<br>
     }<br>
<br>
-    if (m_param-><wbr>analysisMultiPassRefine && m_param->rc.bStatRead && m_multipassAnalysis)<br>
+    if (m_param-><wbr>analysisMultiPassRefine && m_param->rc.bStatRead && m_reuseInterDataCTU)<br>
     {<br>
         uint32_t numPU = interMode.cu.getNumPartInter(<wbr>0);<br>
         for (uint32_t part = 0; part < numPU; part++)<br>
@@ -3087,9 +3085,10 @@<br>
             MotionData* bestME = interMode.bestME[part];<br>
             for (int32_t i = 0; i < numPredDir; i++)<br>
             {<br>
-                bestME[i].ref = m_multipassRef[i][cuGeom.<wbr>absPartIdx];<br>
-                bestME[i].mv = m_multipassMv[i][cuGeom.<wbr>absPartIdx];<br>
-                bestME[i].mvpIdx = m_multipassMvpIdx[i][cuGeom.<wbr>absPartIdx];<br>
+                int* ref = &m_reuseRef[i * m_frame->m_analysisData.<wbr>numPartitions * m_frame->m_analysisData.<wbr>numCUsInFrame];<br>
+                bestME[i].ref = ref[cuGeom.absPartIdx];<br>
+                bestME[i].mv = m_reuseMv[i][cuGeom.<wbr>absPartIdx];<br>
+                bestME[i].mvpIdx = m_reuseMvpIdx[i][cuGeom.<wbr>absPartIdx];<br>
             }<br>
         }<br>
     }<br>
@@ -3563,10 +3562,10 @@<br>
<br>
     if (m_param-><wbr>analysisMultiPassDistortion && m_param->rc.bStatRead)<br>
     {<br>
-        m_multipassAnalysis = (analysis2PassFrameData*)m_<wbr>frame->m_analysis2Pass.<wbr>analysisFramedata;<br>
-        if ((m_multipassAnalysis-><wbr>threshold[ctu.m_cuAddr] < 0.9 || m_multipassAnalysis-><wbr>threshold[ctu.m_cuAddr] > 1.1)<br>
-            && m_multipassAnalysis-><wbr>highDistortionCtuCount && m_multipassAnalysis-><wbr>lowDistortionCtuCount)<br>
-            qp += m_multipassAnalysis->offset[<wbr>ctu.m_cuAddr];<br>
+        analysisDistortionData* distortionData = (analysisDistortionData*)m_<wbr>frame->m_analysisData.<wbr>distortionData;<br>
+        if ((distortionData->threshold[<wbr>ctu.m_cuAddr] < 0.9 || distortionData->threshold[ctu.<wbr>m_cuAddr] > 1.1)<br>
+            && distortionData-><wbr>highDistortionCtuCount && distortionData-><wbr>lowDistortionCtuCount)<br>
+            qp += distortionData->offset[ctu.m_<wbr>cuAddr];<br>
     }<br>
<br>
     int loopIncr;<br>
diff -r ed853c4af671 -r 00eec4796d23 source/encoder/analysis.h<br>
--- a/source/encoder/analysis.h Fri Apr 06 14:35:00 2018 +0530<br>
+++ b/source/encoder/analysis.h Mon May 21 11:55:19 2018 +0530<br>
@@ -129,18 +129,12 @@<br>
     uint8_t*             m_reuseModes;<br>
     uint8_t*             m_reusePartSize;<br>
     uint8_t*             m_reuseMergeFlag;<br>
+    MV*                  m_reuseMv[2];<br>
+    uint8_t*             m_reuseMvpIdx[2];<br>
<br>
     uint32_t             m_splitRefIdx[4];<br>
     uint64_t*            cacheCost;<br>
<br>
-<br>
-    analysis2PassFrameData* m_multipassAnalysis;<br>
-    uint8_t*                m_multipassDepth;<br>
-    MV*                     m_multipassMv[2];<br>
-    int*                    m_multipassMvpIdx[2];<br>
-    int32_t*                m_multipassRef[2];<br>
-    uint8_t*                m_multipassModes;<br>
-<br>
     uint8_t                 m_evaluateInter;<br>
     int32_t                 m_refineLevel;<br>
<br>
diff -r ed853c4af671 -r 00eec4796d23 source/encoder/api.cpp<br>
--- a/source/encoder/api.cpp    Fri Apr 06 14:35:00 2018 +0530<br>
+++ b/source/encoder/api.cpp    Mon May 21 11:55:19 2018 +0530<br>
@@ -278,7 +278,7 @@<br>
         pic_in->analysisData.wt = NULL;<br>
         pic_in->analysisData.intraData = NULL;<br>
         pic_in->analysisData.interData = NULL;<br>
-        pic_in->analysis2Pass.<wbr>analysisFramedata = NULL;<br>
+        pic_in->analysisData.<wbr>distortionData = NULL;<br>
     }<br>
<br>
     if (pp_nal && numEncoded > 0 && encoder->m_outputCount >= encoder->m_latestParam-><wbr>chunkStart)<br>
diff -r ed853c4af671 -r 00eec4796d23 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp        Fri Apr 06 14:35:00 2018 +0530<br>
+++ b/source/encoder/encoder.cpp        Mon May 21 11:55:19 2018 +0530<br>
@@ -1262,13 +1262,15 @@<br>
             {<br>
                 if (pic_out)<br>
                 {<br>
-                    pic_out->analysis2Pass.poc = pic_out->poc;<br>
-                    pic_out->analysis2Pass.<wbr>analysisFramedata = outFrame->m_analysis2Pass.<wbr>analysisFramedata;<br>
+                    pic_out->analysisData.poc = pic_out->poc;<br>
+                    pic_out->analysisData.<wbr>interData = outFrame->m_analysisData.<wbr>interData;<br>
+                    pic_out->analysisData.<wbr>intraData = outFrame->m_analysisData.<wbr>intraData;<br>
+                    pic_out->analysisData.<wbr>distortionData = outFrame->m_analysisData.<wbr>distortionData;<br>
                 }<br>
-                writeAnalysis2PassFile(&<wbr>outFrame->m_analysis2Pass, *outFrame->m_encData, outFrame->m_lowres.sliceType);<br>
+                writeAnalysisFile(&outFrame-><wbr>m_analysisData, *outFrame->m_encData, outFrame->m_lowres.sliceType);<br>
             }<br>
             if (m_param-><wbr>analysisMultiPassRefine || m_param-><wbr>analysisMultiPassDistortion)<br>
-                freeAnalysis2Pass(&outFrame-><wbr>m_analysis2Pass, outFrame->m_lowres.sliceType);<br>
+                freeAnalysis(&outFrame->m_<wbr>analysisData, outFrame->m_lowres.sliceType);<br>
             if (m_param->internalCsp == X265_CSP_I400)<br>
             {<br>
                 if (slice->m_sliceType == P_SLICE)<br>
@@ -1373,10 +1375,14 @@<br>
         {<br>
             if (m_param-><wbr>analysisMultiPassRefine || m_param-><wbr>analysisMultiPassDistortion)<br>
             {<br>
-                allocAnalysis2Pass(&frameEnc-><wbr>m_analysis2Pass, frameEnc->m_lowres.sliceType);<br>
-                frameEnc->m_analysis2Pass.poc = frameEnc->m_poc;<br>
+                uint32_t widthInCU = (m_param->sourceWidth + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
+                uint32_t heightInCU = (m_param->sourceHeight + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
+                frameEnc->m_analysisData.<wbr>numCUsInFrame = widthInCU * heightInCU;<br>
+                frameEnc->m_analysisData.<wbr>numPartitions = m_param->num4x4Partitions;<br>
+                allocAnalysis(&frameEnc->m_<wbr>analysisData, frameEnc->m_lowres.sliceType);<br>
+                frameEnc->m_analysisData.poc = frameEnc->m_poc;<br>
                 if (m_param->rc.bStatRead)<br>
-                    readAnalysis2PassFile(&<wbr>frameEnc->m_analysis2Pass, frameEnc->m_poc, frameEnc->m_lowres.sliceType);<br>
+                    readAnalysisFile(&frameEnc->m_<wbr>analysisData, frameEnc->m_poc, frameEnc->m_lowres.sliceType);<br>
              }<br>
<br>
             if (frameEnc->m_reconfigureRc && m_reconfigureRc)<br>
@@ -3290,68 +3296,84 @@<br>
     }<br>
 }<br>
<br>
-void Encoder::allocAnalysis2Pass(<wbr>x265_analysis_2Pass* analysis, int sliceType)<br>
+void Encoder::allocAnalysis(x265_<wbr>analysis_data* analysis, int sliceType)<br>
 {<br>
-    analysis->analysisFramedata = NULL;<br>
-    analysis2PassFrameData *analysisFrameData = (analysis2PassFrameData*)<wbr>analysis->analysisFramedata;<br>
-    uint32_t widthInCU = (m_param->sourceWidth + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
-    uint32_t heightInCU = (m_param->sourceHeight + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
-<br>
-    uint32_t numCUsInFrame = widthInCU * heightInCU;<br>
-    CHECKED_MALLOC_ZERO(<wbr>analysisFrameData, analysis2PassFrameData, 1);<br>
-    CHECKED_MALLOC_ZERO(<wbr>analysisFrameData->depth, uint8_t, m_param->num4x4Partitions * numCUsInFrame);<br>
-    CHECKED_MALLOC_ZERO(<wbr>analysisFrameData->distortion, sse_t, m_param->num4x4Partitions * numCUsInFrame);<br>
+    analysis->interData = analysis->intraData = analysis->distortionData = NULL;<br>
+<br>
+    analysisDistortionData *distortionData = (analysisDistortionData*)<wbr>analysis->distortionData;<br>
+    CHECKED_MALLOC_ZERO(<wbr>distortionData, analysisDistortionData, 1);<br>
+    CHECKED_MALLOC_ZERO(<wbr>distortionData->distortion, sse_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
     if (m_param->rc.bStatRead)<br>
     {<br>
-        CHECKED_MALLOC_ZERO(<wbr>analysisFrameData-><wbr>ctuDistortion, sse_t, numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>analysisFrameData-><wbr>scaledDistortion, double, numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>analysisFrameData->offset, double, numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>analysisFrameData->threshold, double, numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(<wbr>distortionData->ctuDistortion, sse_t, analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(<wbr>distortionData-><wbr>scaledDistortion, double, analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(<wbr>distortionData->offset, double, analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(<wbr>distortionData->threshold, double, analysis->numCUsInFrame);<br>
     }<br>
-    if (!IS_X265_TYPE_I(sliceType))<br>
+    analysis->distortionData = distortionData;<br>
+<br>
+    if (IS_X265_TYPE_I(sliceType))<br>
     {<br>
-        CHECKED_MALLOC_ZERO(<wbr>analysisFrameData->m_mv[0], MV, m_param->num4x4Partitions * numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>analysisFrameData->m_mv[1], MV, m_param->num4x4Partitions * numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>analysisFrameData->mvpIdx[0], int, m_param->num4x4Partitions * numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>analysisFrameData->mvpIdx[1], int, m_param->num4x4Partitions * numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>analysisFrameData->ref[0], int32_t, m_param->num4x4Partitions * numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>analysisFrameData->ref[1], int32_t, m_param->num4x4Partitions * numCUsInFrame);<br>
-        CHECKED_MALLOC(<wbr>analysisFrameData->modes, uint8_t, m_param->num4x4Partitions * numCUsInFrame);<br>
+        analysis_intra_data *intraData = (analysis_intra_data*)<wbr>analysis->intraData;<br>
+        CHECKED_MALLOC_ZERO(intraData, analysis_intra_data, 1);<br>
+        CHECKED_MALLOC(intraData-><wbr>depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        analysis->intraData = intraData;<br>
     }<br>
-<br>
-    analysis->analysisFramedata = analysisFrameData;<br>
-<br>
+    else<br>
+    {<br>
+        analysis_inter_data *interData = (analysis_inter_data*)<wbr>analysis->interData;<br>
+        CHECKED_MALLOC_ZERO(interData, analysis_inter_data, 1);<br>
+        CHECKED_MALLOC_ZERO(interData-<wbr>>depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC(interData-><wbr>modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(interData-<wbr>>mvpIdx[0], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(interData-<wbr>>mvpIdx[1], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(interData-<wbr>>mv[0], MV, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(interData-<wbr>>mv[1], MV, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(interData-<wbr>>ref, int32_t, 2 * analysis->numPartitions * analysis->numCUsInFrame);<br>
+        analysis->interData = interData;<br>
+    }<br>
     return;<br>
<br>
 fail:<br>
-    freeAnalysis2Pass(analysis, sliceType);<br>
+    freeAnalysis(analysis, sliceType);<br>
     m_aborted = true;<br>
 }<br>
<br>
-void Encoder::freeAnalysis2Pass(<wbr>x265_analysis_2Pass* analysis, int sliceType)<br>
+void Encoder::freeAnalysis(x265_<wbr>analysis_data* analysis, int sliceType)<br>
 {<br>
-    if (analysis->analysisFramedata)<br>
+    if (analysis->distortionData)<br>
     {<br>
-        X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>depth);<br>
-        X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>distortion);<br>
+        X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>distortion);<br>
         if (m_param->rc.bStatRead)<br>
         {<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>ctuDistortion);<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>scaledDistortion);<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>offset);<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>threshold);<br>
+            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>ctuDistortion);<br>
+            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>scaledDistortion);<br>
+            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>offset);<br>
+            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>threshold);<br>
         }<br>
-        if (!IS_X265_TYPE_I(sliceType))<br>
+        X265_FREE(analysis-><wbr>distortionData);<br>
+    }<br>
+    if (IS_X265_TYPE_I(sliceType))<br>
+    {<br>
+        if (analysis->intraData)<br>
         {<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>m_mv[0]);<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>m_mv[1]);<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>mvpIdx[0]);<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>mvpIdx[1]);<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>ref[0]);<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>ref[1]);<br>
-            X265_FREE(((<wbr>analysis2PassFrameData*)<wbr>analysis->analysisFramedata)-><wbr>modes);<br>
+            X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>depth);<br>
+            X265_FREE(analysis->intraData)<wbr>;<br>
         }<br>
-        X265_FREE(analysis-><wbr>analysisFramedata);<br>
+    }<br>
+    else<br>
+    {<br>
+        if (analysis->interData)<br>
+        {<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mvpIdx[0]);<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mvpIdx[1]);<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mv[0]);<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mv[1]);<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>ref);<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>depth);<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>modes);<br>
+            X265_FREE(analysis->interData)<wbr>;<br>
+        }<br>
     }<br>
 }<br>
<br>
@@ -4188,23 +4210,19 @@<br>
     return SIZE_2Nx2N;<br>
 }<br>
<br>
-void Encoder::<wbr>readAnalysis2PassFile(x265_<wbr>analysis_2Pass* analysis2Pass, int curPoc, int sliceType)<br>
+void Encoder::readAnalysisFile(<wbr>x265_analysis_data* analysis, int curPoc, int sliceType)<br>
 {<br>
<br>
 #define X265_FREAD(val, size, readSize, fileOffset)\<br>
     if (fread(val, size, readSize, fileOffset) != readSize)\<br>
     {\<br>
     x265_log(NULL, X265_LOG_ERROR, "Error reading analysis 2 pass data\n"); \<br>
-    freeAnalysis2Pass(<wbr>analysis2Pass, sliceType); \<br>
+    freeAnalysis(analysis, sliceType); \<br>
     m_aborted = true; \<br>
     return; \<br>
 }\<br>
<br>
     uint32_t depthBytes = 0;<br>
-    uint32_t widthInCU = (m_param->sourceWidth + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
-    uint32_t heightInCU = (m_param->sourceHeight + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
-    uint32_t numCUsInFrame = widthInCU * heightInCU;<br>
-<br>
     int poc; uint32_t frameRecordSize;<br>
     X265_FREAD(&frameRecordSize, sizeof(uint32_t), 1, m_analysisFileIn);<br>
     X265_FREAD(&depthBytes, sizeof(uint32_t), 1, m_analysisFileIn);<br>
@@ -4213,11 +4231,11 @@<br>
     if (poc != curPoc || feof(m_analysisFileIn))<br>
     {<br>
         x265_log(NULL, X265_LOG_WARNING, "Error reading analysis 2 pass data: Cannot find POC %d\n", curPoc);<br>
-        freeAnalysis2Pass(<wbr>analysis2Pass, sliceType);<br>
+        freeAnalysis(analysis, sliceType);<br>
         return;<br>
     }<br>
     /* Now arrived at the right frame, read the record */<br>
-    analysis2Pass->frameRecordSize = frameRecordSize;<br>
+    analysis->frameRecordSize = frameRecordSize;<br>
     uint8_t* tempBuf = NULL, *depthBuf = NULL;<br>
     sse_t *tempdistBuf = NULL, *distortionBuf = NULL;<br>
     tempBuf = X265_MALLOC(uint8_t, depthBytes);<br>
@@ -4226,76 +4244,85 @@<br>
     X265_FREAD(tempdistBuf, sizeof(sse_t), depthBytes, m_analysisFileIn);<br>
     depthBuf = tempBuf;<br>
     distortionBuf = tempdistBuf;<br>
-    analysis2PassFrameData* analysisFrameData = (analysis2PassFrameData*)<wbr>analysis2Pass-><wbr>analysisFramedata;<br>
+    x265_analysis_data *analysisData = (x265_analysis_data*)analysis;<br>
+    analysis_intra_data *intraData = (analysis_intra_data *)analysisData->intraData;<br>
+    analysis_inter_data *interData = (analysis_inter_data *)analysisData->interData;<br>
+    analysisDistortionData *distortionData = (analysisDistortionData *)analysisData-><wbr>distortionData;<br>
+<br>
     size_t count = 0;<br>
     uint32_t ctuCount = 0;<br>
     double sum = 0, sqrSum = 0;<br>
     for (uint32_t d = 0; d < depthBytes; d++)<br>
     {<br>
-        int bytes = m_param->num4x4Partitions >> (depthBuf[d] * 2);<br>
-        memset(&analysisFrameData-><wbr>depth[count], depthBuf[d], bytes);<br>
-        analysisFrameData->distortion[<wbr>count] = distortionBuf[d];<br>
-        analysisFrameData-><wbr>ctuDistortion[ctuCount] += analysisFrameData->distortion[<wbr>count];<br>
+        int bytes = analysis->numPartitions >> (depthBuf[d] * 2);<br>
+        if (IS_X265_TYPE_I(sliceType))<br>
+            memset(&intraData->depth[<wbr>count], depthBuf[d], bytes);<br>
+        else<br>
+            memset(&interData->depth[<wbr>count], depthBuf[d], bytes);<br>
+        distortionData->distortion[<wbr>count] = distortionBuf[d];<br>
+        distortionData->ctuDistortion[<wbr>ctuCount] += distortionData->distortion[<wbr>count];<br>
         count += bytes;<br>
-        if ((count % (unsigned)m_param-><wbr>num4x4Partitions) == 0)<br>
+        if ((count % (unsigned)analysis-><wbr>numPartitions) == 0)<br>
         {<br>
-            analysisFrameData-><wbr>scaledDistortion[ctuCount] = X265_LOG2(X265_MAX(<wbr>analysisFrameData-><wbr>ctuDistortion[ctuCount], 1));<br>
-            sum += analysisFrameData-><wbr>scaledDistortion[ctuCount];<br>
-            sqrSum += analysisFrameData-><wbr>scaledDistortion[ctuCount] * analysisFrameData-><wbr>scaledDistortion[ctuCount];<br>
+            distortionData-><wbr>scaledDistortion[ctuCount] = X265_LOG2(X265_MAX(<wbr>distortionData->ctuDistortion[<wbr>ctuCount], 1));<br>
+            sum += distortionData-><wbr>scaledDistortion[ctuCount];<br>
+            sqrSum += distortionData-><wbr>scaledDistortion[ctuCount] * distortionData-><wbr>scaledDistortion[ctuCount];<br>
             ctuCount++;<br>
         }<br>
     }<br>
-    double avg = sum / numCUsInFrame;<br>
-    analysisFrameData-><wbr>sdDistortion = pow(((sqrSum / numCUsInFrame) - (avg * avg)), 0.5);<br>
-    analysisFrameData-><wbr>averageDistortion = avg;<br>
-    analysisFrameData-><wbr>highDistortionCtuCount = analysisFrameData-><wbr>lowDistortionCtuCount = 0;<br>
-    for (uint32_t i = 0; i < numCUsInFrame; ++i)<br>
+    double avg = sum / analysis->numCUsInFrame;<br>
+    distortionData->sdDistortion = pow(((sqrSum / analysis->numCUsInFrame) - (avg * avg)), 0.5);<br>
+    distortionData-><wbr>averageDistortion = avg;<br>
+    distortionData-><wbr>highDistortionCtuCount = distortionData-><wbr>lowDistortionCtuCount = 0;<br>
+    for (uint32_t i = 0; i < analysis->numCUsInFrame; ++i)<br>
     {<br>
-        analysisFrameData->threshold[<wbr>i] = analysisFrameData-><wbr>scaledDistortion[i] / analysisFrameData-><wbr>averageDistortion;<br>
-        analysisFrameData->offset[i] = (analysisFrameData-><wbr>averageDistortion - analysisFrameData-><wbr>scaledDistortion[i]) / analysisFrameData-><wbr>sdDistortion;<br>
-        if (analysisFrameData->threshold[<wbr>i] < 0.9 && analysisFrameData->offset[i] >= 1)<br>
-            analysisFrameData-><wbr>lowDistortionCtuCount++;<br>
-        else if (analysisFrameData->threshold[<wbr>i] > 1.1 && analysisFrameData->offset[i] <= -1)<br>
-            analysisFrameData-><wbr>highDistortionCtuCount++;<br>
+        distortionData->threshold[i] = distortionData-><wbr>scaledDistortion[i] / distortionData-><wbr>averageDistortion;<br>
+        distortionData->offset[i] = (distortionData-><wbr>averageDistortion - distortionData-><wbr>scaledDistortion[i]) / distortionData->sdDistortion;<br>
+        if (distortionData->threshold[i] < 0.9 && distortionData->offset[i] >= 1)<br>
+            distortionData-><wbr>lowDistortionCtuCount++;<br>
+        else if (distortionData->threshold[i] > 1.1 && distortionData->offset[i] <= -1)<br>
+            distortionData-><wbr>highDistortionCtuCount++;<br>
     }<br>
     if (!IS_X265_TYPE_I(sliceType))<br>
     {<br>
         MV *tempMVBuf[2], *MVBuf[2];<br>
-        int32_t *tempRefBuf[2], *refBuf[2];<br>
-        int *tempMvpBuf[2], *mvpBuf[2];<br>
+        int32_t *tempRefBuf, *refBuf;<br>
+        uint8_t *tempMvpBuf[2], *mvpBuf[2];<br>
         uint8_t* tempModeBuf = NULL, *modeBuf = NULL;<br>
-<br>
         int numDir = sliceType == X265_TYPE_P ? 1 : 2;<br>
+        tempRefBuf = X265_MALLOC(int32_t, numDir * depthBytes);<br>
+<br>
         for (int i = 0; i < numDir; i++)<br>
         {<br>
             tempMVBuf[i] = X265_MALLOC(MV, depthBytes);<br>
             X265_FREAD(tempMVBuf[i], sizeof(MV), depthBytes, m_analysisFileIn);<br>
             MVBuf[i] = tempMVBuf[i];<br>
-            tempMvpBuf[i] = X265_MALLOC(int, depthBytes);<br>
-            X265_FREAD(tempMvpBuf[i], sizeof(int), depthBytes, m_analysisFileIn);<br>
+            tempMvpBuf[i] = X265_MALLOC(uint8_t, depthBytes);<br>
+            X265_FREAD(tempMvpBuf[i], sizeof(uint8_t), depthBytes, m_analysisFileIn);<br>
             mvpBuf[i] = tempMvpBuf[i];<br>
-            tempRefBuf[i] = X265_MALLOC(int32_t, depthBytes);<br>
-            X265_FREAD(tempRefBuf[i], sizeof(int32_t), depthBytes, m_analysisFileIn);<br>
-            refBuf[i] = tempRefBuf[i];<br>
+            X265_FREAD(&tempRefBuf[i*<wbr>depthBytes], sizeof(int32_t), depthBytes, m_analysisFileIn);<br>
         }<br>
+        refBuf = tempRefBuf;<br>
         tempModeBuf = X265_MALLOC(uint8_t, depthBytes);<br>
         X265_FREAD(tempModeBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn);<br>
         modeBuf = tempModeBuf;<br>
-<br>
+        <br>
         count = 0;<br>
+<br>
         for (uint32_t d = 0; d < depthBytes; d++)<br>
         {<br>
-            size_t bytes = m_param->num4x4Partitions >> (depthBuf[d] * 2);<br>
+            size_t bytes = analysis->numPartitions >> (depthBuf[d] * 2);<br>
             for (int i = 0; i < numDir; i++)<br>
             {<br>
+                int32_t* ref = &((analysis_inter_data*)<wbr>analysis->interData)->ref[i * analysis->numPartitions * analysis->numCUsInFrame];<br>
                 for (size_t j = count, k = 0; k < bytes; j++, k++)<br>
                 {<br>
-                    memcpy(&((<wbr>analysis2PassFrameData*)<wbr>analysis2Pass-><wbr>analysisFramedata)->m_mv[i][j]<wbr>, MVBuf[i] + d, sizeof(MV));<br>
-                    memcpy(&((<wbr>analysis2PassFrameData*)<wbr>analysis2Pass-><wbr>analysisFramedata)->mvpIdx[i][<wbr>j], mvpBuf[i] + d, sizeof(int));<br>
-                    memcpy(&((<wbr>analysis2PassFrameData*)<wbr>analysis2Pass-><wbr>analysisFramedata)->ref[i][j], refBuf[i] + d, sizeof(int32_t));<br>
+                    memcpy(&((analysis_inter_data*<wbr>)analysis->interData)->mv[i][<wbr>j], MVBuf[i] + d, sizeof(MV));<br>
+                    memcpy(&((analysis_inter_data*<wbr>)analysis->interData)->mvpIdx[<wbr>i][j], mvpBuf[i] + d, sizeof(uint8_t));<br>
+                    memcpy(&ref[j], refBuf + (i * depthBytes) + d, sizeof(int32_t));<br>
                 }<br>
             }<br>
-            memset(&((<wbr>analysis2PassFrameData *)analysis2Pass-><wbr>analysisFramedata)->modes[<wbr>count], modeBuf[d], bytes);<br>
+            memset(&((analysis_inter_data *)analysis->interData)->modes[<wbr>count], modeBuf[d], bytes);<br>
             count += bytes;<br>
         }<br>
<br>
@@ -4303,8 +4330,8 @@<br>
         {<br>
             X265_FREE(tempMVBuf[i]);<br>
             X265_FREE(tempMvpBuf[i]);<br>
-            X265_FREE(tempRefBuf[i]);<br>
         }<br>
+        X265_FREE(tempRefBuf);<br>
         X265_FREE(tempModeBuf);<br>
     }<br>
     X265_FREE(tempBuf);<br>
@@ -4507,24 +4534,25 @@<br>
 #undef X265_FWRITE<br>
 }<br>
<br>
-void Encoder::<wbr>writeAnalysis2PassFile(x265_<wbr>analysis_2Pass* analysis2Pass, FrameData &curEncData, int slicetype)<br>
+void Encoder::writeAnalysisFile(<wbr>x265_analysis_data* analysis, FrameData &curEncData, int slicetype)<br>
 {<br>
 #define X265_FWRITE(val, size, writeSize, fileOffset)\<br>
     if (fwrite(val, size, writeSize, fileOffset) < writeSize)\<br>
     {\<br>
     x265_log(NULL, X265_LOG_ERROR, "Error writing analysis 2 pass data\n"); \<br>
-    freeAnalysis2Pass(<wbr>analysis2Pass, slicetype); \<br>
+    freeAnalysis(analysis, slicetype); \<br>
     m_aborted = true; \<br>
     return; \<br>
 }\<br>
<br>
     uint32_t depthBytes = 0;<br>
-    uint32_t widthInCU = (m_param->sourceWidth + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
-    uint32_t heightInCU = (m_param->sourceHeight + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
-    uint32_t numCUsInFrame = widthInCU * heightInCU;<br>
-    analysis2PassFrameData* analysisFrameData = (analysis2PassFrameData*)<wbr>analysis2Pass-><wbr>analysisFramedata;<br>
-<br>
-    for (uint32_t cuAddr = 0; cuAddr < numCUsInFrame; cuAddr++)<br>
+    x265_analysis_data *analysisData = (x265_analysis_data*)analysis;<br>
+    analysis_intra_data *intraData = (analysis_intra_data *)analysisData->intraData;<br>
+    analysis_inter_data *interData = (analysis_inter_data *)analysisData->interData;<br>
+    analysisDistortionData *distortionData = (analysisDistortionData *)analysisData-><wbr>distortionData;<br>
+   <br>
+<br>
+    for (uint32_t cuAddr = 0; cuAddr < analysis->numCUsInFrame; cuAddr++)<br>
     {<br>
         uint8_t depth = 0;<br>
<br>
@@ -4533,37 +4561,42 @@<br>
         for (uint32_t absPartIdx = 0; absPartIdx < ctu->m_numPartitions; depthBytes++)<br>
         {<br>
             depth = ctu->m_cuDepth[absPartIdx];<br>
-            analysisFrameData->depth[<wbr>depthBytes] = depth;<br>
-            analysisFrameData->distortion[<wbr>depthBytes] = ctu->m_distortion[absPartIdx];<br>
+            if (curEncData.m_slice->m_<wbr>sliceType == I_SLICE)<br>
+                intraData->depth[depthBytes] = depth;<br>
+            else<br>
+                interData->depth[depthBytes] = depth;<br>
+            distortionData->distortion[<wbr>depthBytes] = ctu->m_distortion[absPartIdx];<br>
             absPartIdx += ctu->m_numPartitions >> (depth * 2);<br>
         }<br>
     }<br>
<br>
     if (curEncData.m_slice->m_<wbr>sliceType != I_SLICE)<br>
     {<br>
+        int32_t* ref[2];<br>
+        ref[0] = ((analysis_inter_data*)<wbr>analysis->interData)->ref;<br>
+        ref[1] = &((analysis_inter_data*)<wbr>analysis->interData)->ref[<wbr>analysis->numPartitions * analysis->numCUsInFrame];<br>
         depthBytes = 0;<br>
-        for (uint32_t cuAddr = 0; cuAddr < numCUsInFrame; cuAddr++)<br>
+        for (uint32_t cuAddr = 0; cuAddr < analysis->numCUsInFrame; cuAddr++)<br>
         {<br>
             uint8_t depth = 0;<br>
             uint8_t predMode = 0;<br>
<br>
             CUData* ctu = curEncData.getPicCTU(cuAddr);<br>
-<br>
             for (uint32_t absPartIdx = 0; absPartIdx < ctu->m_numPartitions; depthBytes++)<br>
             {<br>
                 depth = ctu->m_cuDepth[absPartIdx];<br>
-                analysisFrameData->m_mv[0][<wbr>depthBytes] = ctu->m_mv[0][absPartIdx];<br>
-                analysisFrameData->mvpIdx[0][<wbr>depthBytes] = ctu->m_mvpIdx[0][absPartIdx];<br>
-                analysisFrameData->ref[0][<wbr>depthBytes] = ctu->m_refIdx[0][absPartIdx];<br>
+                interData->mv[0][depthBytes] = ctu->m_mv[0][absPartIdx];<br>
+                interData->mvpIdx[0][<wbr>depthBytes] = ctu->m_mvpIdx[0][absPartIdx];<br>
+                ref[0][depthBytes] = ctu->m_refIdx[0][absPartIdx];<br>
                 predMode = ctu->m_predMode[absPartIdx];<br>
                 if (ctu->m_refIdx[1][absPartIdx] != -1)<br>
                 {<br>
-                    analysisFrameData->m_mv[1][<wbr>depthBytes] = ctu->m_mv[1][absPartIdx];<br>
-                    analysisFrameData->mvpIdx[1][<wbr>depthBytes] = ctu->m_mvpIdx[1][absPartIdx];<br>
-                    analysisFrameData->ref[1][<wbr>depthBytes] = ctu->m_refIdx[1][absPartIdx];<br>
+                    interData->mv[1][depthBytes] = ctu->m_mv[1][absPartIdx];<br>
+                    interData->mvpIdx[1][<wbr>depthBytes] = ctu->m_mvpIdx[1][absPartIdx];<br>
+                    ref[1][depthBytes] = ctu->m_refIdx[1][absPartIdx];<br>
                     predMode = 4; // used as indiacator if the block is coded as bidir<br>
                 }<br>
-                analysisFrameData->modes[<wbr>depthBytes] = predMode;<br>
+                interData->modes[depthBytes] = predMode;<br>
<br>
                 absPartIdx += ctu->m_numPartitions >> (depth * 2);<br>
             }<br>
@@ -4571,34 +4604,40 @@<br>
     }<br>
<br>
     /* calculate frameRecordSize */<br>
-    analysis2Pass->frameRecordSize = sizeof(analysis2Pass-><wbr>frameRecordSize) + sizeof(depthBytes) + sizeof(analysis2Pass->poc);<br>
-<br>
-    analysis2Pass->frameRecordSize += depthBytes * sizeof(uint8_t);<br>
-    analysis2Pass->frameRecordSize += depthBytes * sizeof(sse_t);<br>
+    analysis->frameRecordSize = sizeof(analysis-><wbr>frameRecordSize) + sizeof(depthBytes) + sizeof(analysis->poc);<br>
+    analysis->frameRecordSize += depthBytes * sizeof(uint8_t);<br>
+    analysis->frameRecordSize += depthBytes * sizeof(sse_t);<br>
     if (curEncData.m_slice->m_<wbr>sliceType != I_SLICE)<br>
     {<br>
         int numDir = (curEncData.m_slice->m_<wbr>sliceType == P_SLICE) ? 1 : 2;<br>
-        analysis2Pass->frameRecordSize += depthBytes * sizeof(MV) * numDir;<br>
-        analysis2Pass->frameRecordSize += depthBytes * sizeof(int32_t) * numDir;<br>
-        analysis2Pass->frameRecordSize += depthBytes * sizeof(int) * numDir;<br>
-        analysis2Pass->frameRecordSize += depthBytes * sizeof(uint8_t);<br>
+        analysis->frameRecordSize += depthBytes * sizeof(MV) * numDir;<br>
+        analysis->frameRecordSize += depthBytes * sizeof(int32_t) * numDir;<br>
+        analysis->frameRecordSize += depthBytes * sizeof(uint8_t) * numDir;<br>
+        analysis->frameRecordSize += depthBytes * sizeof(uint8_t);<br>
     }<br>
-    X265_FWRITE(&analysis2Pass-><wbr>frameRecordSize, sizeof(uint32_t), 1, m_analysisFileOut);<br>
+    X265_FWRITE(&analysis-><wbr>frameRecordSize, sizeof(uint32_t), 1, m_analysisFileOut);<br>
     X265_FWRITE(&depthBytes, sizeof(uint32_t), 1, m_analysisFileOut);<br>
-    X265_FWRITE(&analysis2Pass-><wbr>poc, sizeof(uint32_t), 1, m_analysisFileOut);<br>
-<br>
-    X265_FWRITE(analysisFrameData-<wbr>>depth, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>
-    X265_FWRITE(analysisFrameData-<wbr>>distortion, sizeof(sse_t), depthBytes, m_analysisFileOut);<br>
+    X265_FWRITE(&analysis->poc, sizeof(uint32_t), 1, m_analysisFileOut);<br>
+    if (curEncData.m_slice->m_<wbr>sliceType == I_SLICE)<br>
+    {<br>
+        X265_FWRITE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>depth, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>
+    }<br>
+    else<br>
+    {<br>
+        X265_FWRITE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>depth, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>
+    }<br>
+    X265_FWRITE(distortionData-><wbr>distortion, sizeof(sse_t), depthBytes, m_analysisFileOut);<br>
     if (curEncData.m_slice->m_<wbr>sliceType != I_SLICE)<br>
     {<br>
         int numDir = curEncData.m_slice->m_<wbr>sliceType == P_SLICE ? 1 : 2;<br>
         for (int i = 0; i < numDir; i++)<br>
         {<br>
-            X265_FWRITE(analysisFrameData-<wbr>>m_mv[i], sizeof(MV), depthBytes, m_analysisFileOut);<br>
-            X265_FWRITE(analysisFrameData-<wbr>>mvpIdx[i], sizeof(int), depthBytes, m_analysisFileOut);<br>
-            X265_FWRITE(analysisFrameData-<wbr>>ref[i], sizeof(int32_t), depthBytes, m_analysisFileOut);<br>
+            int32_t* ref = &((analysis_inter_data*)<wbr>analysis->interData)->ref[i * analysis->numPartitions * analysis->numCUsInFrame];<br>
+            X265_FWRITE(interData->mv[i], sizeof(MV), depthBytes, m_analysisFileOut);<br>
+            X265_FWRITE(interData->mvpIdx[<wbr>i], sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>
+            X265_FWRITE(ref, sizeof(int32_t), depthBytes, m_analysisFileOut);<br>
         }<br>
-        X265_FWRITE(analysisFrameData-<wbr>>modes, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>
+        X265_FWRITE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>modes, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>
     }<br>
 #undef X265_FWRITE<br>
 }<br>
diff -r ed853c4af671 -r 00eec4796d23 source/encoder/encoder.h<br>
--- a/source/encoder/encoder.h  Fri Apr 06 14:35:00 2018 +0530<br>
+++ b/source/encoder/encoder.h  Mon May 21 11:55:19 2018 +0530<br>
@@ -275,11 +275,13 @@<br>
<br>
     void allocAnalysis(x265_analysis_<wbr>data* analysis);<br>
<br>
+    void allocAnalysis(x265_analysis_<wbr>data* analysis, int sliceType);<br>
+<br>
     void freeAnalysis(x265_analysis_<wbr>data* analysis);<br>
<br>
-    void allocAnalysis2Pass(x265_<wbr>analysis_2Pass* analysis, int sliceType);<br>
+    void freeAnalysis(x265_analysis_<wbr>data* analysis, int sliceType);<br>
<br>
-    void freeAnalysis2Pass(x265_<wbr>analysis_2Pass* analysis, int sliceType);<br>
+    void readAnalysisFile(x265_<wbr>analysis_data* analysis, int poc, int sliceType);<br>
<br>
     void readAnalysisFile(x265_<wbr>analysis_data* analysis, int poc, const x265_picture* picIn, int paramBytes);<br>
<br>
@@ -289,9 +291,10 @@<br>
<br>
     int getPuShape(puOrientation* puOrient, int partSize, int numCTU);<br>
<br>
-    void writeAnalysisFile(x265_<wbr>analysis_data* pic, FrameData &curEncData);<br>
-    void readAnalysis2PassFile(x265_<wbr>analysis_2Pass* analysis2Pass, int poc, int sliceType);<br>
-    void writeAnalysis2PassFile(x265_<wbr>analysis_2Pass* analysis2Pass, FrameData &curEncData, int slicetype);<br>
+    void writeAnalysisFile(x265_<wbr>analysis_data* analysis, FrameData &curEncData);<br>
+<br>
+    void writeAnalysisFile(x265_<wbr>analysis_data* analysis, FrameData &curEncData, int slicetype);<br>
+<br>
     void finishFrameStats(Frame* pic, FrameEncoder *curEncoder, x265_frame_stats* frameStats, int inPoc);<br>
<br>
     int validateAnalysisData(x265_<wbr>analysis_data* analysis, int readWriteFlag);<br>
diff -r ed853c4af671 -r 00eec4796d23 source/x265.h<br>
--- a/source/x265.h     Fri Apr 06 14:35:00 2018 +0530<br>
+++ b/source/x265.h     Mon May 21 11:55:19 2018 +0530<br>
@@ -143,6 +143,7 @@<br>
     x265_lookahead_data lookahead;<br>
     uint8_t*         modeFlag[2];<br>
     x265_analysis_validate saveParam;<br>
+    void*            distortionData;<br>
 } x265_analysis_data;<br>
<br>
 /* cu statistics */<br>
@@ -171,14 +172,6 @@<br>
     /* All the above values will add up to 100%. */<br>
 } x265_pu_stats;<br>
<br>
-<br>
-typedef struct x265_analysis_2Pass<br>
-{<br>
-    uint32_t      poc;<br>
-    uint32_t      frameRecordSize;<br>
-    void*         analysisFramedata;<br>
-}x265_analysis_2Pass;<br>
-<br>
 /* Frame level statistics */<br>
 typedef struct x265_frame_stats<br>
 {<br>
@@ -383,8 +376,6 @@<br>
<br>
     int    height;<br>
<br>
-    x265_analysis_2Pass analysis2Pass;<br>
-<br>
     // pts is reordered in the order of encoding.<br>
     int64_t reorderedPts;<br>
 } x265_picture;<br>
<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>
<br></blockquote></div><br></div><div class="gmail_extra">Pushed.</div></div>