HEVC代码追踪(二):encode

简介: <pre name="code" class="cpp">// ====================================================================================================================// Public member functions// =================
// ====================================================================================================================
// Public member functions
// ====================================================================================================================

/**
 - create internal class
 - initialize internal variable
 - until the end of input YUV file, call encoding function in TEncTop class
 - delete allocated buffers
 - destroy internal class
 .
 */
Void TAppEncTop::encode()
{
  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
  if (!bitstreamFile)
  {
    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
    exit(EXIT_FAILURE);
  }

  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;	//使用new在运行阶段分配未命名的内存来存储值
  TComPicYuv*       pcPicYuvRec = NULL;
  // initialize internal class & member variables
  xInitLibCfg();
  xCreateLib();
  xInitLib(m_isField);
  
  // main encoder loop
  Int   iNumEncoded = 0;
  Bool  bEos = false;
  
  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process

  // allocate original YUV buffer(分配原始YUV缓冲区)
  if( m_isField )
  {
    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeightOrg, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
  }
  else
  {
    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
  }
  
  while ( !bEos )
  {
    // get buffers
    xGetBuffer(pcPicYuvRec);

    // read input YUV file
    m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, m_aiPad );

    // increase number of received frames
    m_iFrameRcvd++;
    
    bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
    Bool flush = 0;
    // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
    if (m_cTVideoIOYuvInputFile.isEof())
    {
      flush = true;
      bEos = true;
      m_iFrameRcvd--;
      m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd);
    }

    // call encoding function for one frame
    if ( m_isField )
    {
      m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst);
    }
    else
    {
      m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
    }
    
    // write bistream to file if necessary
    if ( iNumEncoded > 0 )
    {
      xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits);
      outputAccessUnits.clear();
    }
  }

  m_cTEncTop.printSummary(m_isField);

  // delete original YUV buffer
  pcPicYuvOrg->destroy();
  delete pcPicYuvOrg;	//使用delete释放内存(只能用delete来释放使用new分配的内存)
  pcPicYuvOrg = NULL;
  
  // delete used buffers in encoder class
  m_cTEncTop.deletePicBuffer();
  
  // delete buffers & classes
  xDeleteBuffer();
  xDestroyLib();
  
  printRateSummary();

  return;
}

目录
相关文章
|
编解码
HEVC代码追踪(十三):解码之decode
<p><br></p> <p></p> <pre name="code" class="cpp">// ==================================================================================================================== // Public member functions
1795 0
HEVC代码追踪(十四):解码之xDecodeSlice
<p><br></p> <p></p> <pre name="code" class="cpp">Bool TDecTop::decode(InputNALUnit&amp; nalu, Int&amp; iSkipFrame, Int&amp; iPOCLastDisplay) { // Initialize entropy decoder m_cEntropyDecoder
2386 0
HEVC代码追踪(十五):解码之decompressSlice
<p><br></p> <p></p> <pre name="code" class="cpp">Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic*&amp; rpcPic) { TComSlice* pcSlice = rpcPic-&gt;getSlice(rpcPic-&gt;getC
1189 0
|
机器学习/深度学习 编解码
HEVC代码追踪(十二):解码之int main
<p><br></p> <p></p> <pre name="code" class="cpp">int main(int argc, char* argv[]) { TAppDecTop cTAppDecTop; // print information fprintf( stdout, "\n" ); fprintf( stdout, "HM software:
1152 0
HEVC代码追踪(八。三):encodeCoeff
<p><br></p> <p></p> <pre name="code" class="cpp">// texture /** encode coefficients * \param pcCU * \param uiAbsPartIdx * \param uiDepth * \param uiWidth * \param uiHeight */ Void TEncEntro
1857 0
HEVC代码追踪(八。二):estIntraPredChromaQT
<p><br></p> <p></p> <pre code_snippet_id="537345" snippet_file_name="blog_20141130_1_6232807" name="code" class="cpp">Void TEncSearch::estIntraPredChromaQT( TComDataCU* pcCU,
1681 0
|
编解码
HEVC代码追踪(六):compressCU
<p><br></p> <p></p> <pre code_snippet_id="537266" snippet_file_name="blog_20141130_1_961923" name="code" class="cpp">Void TEncCu::compressCU( TComDataCU*&amp; rpcCU ) { // initialize CU data
1428 0
HEVC代码追踪(七):xCompressCu
<p><br></p> <p></p> <pre name="code" class="cpp">// ==================================================================================================================== // Protected member functi
2604 0
HEVC代码追踪(八。一):estIntraPredQT
<p><br></p> <p></p> <pre code_snippet_id="537334" snippet_file_name="blog_20141130_1_4880297" name="code" class="cpp">Void TEncSearch::estIntraPredQT( TComDataCU* pcCU,
2372 0
HEVC代码追踪(八):帧内-&gt;xCheckRDCostIntra
<p><br></p> <p></p> <pre name="code" class="cpp">Void TEncCu::xCheckRDCostIntra( TComDataCU*&amp; rpcBestCU, TComDataCU*&amp; rpcTempCU, PartSize eSize ) { UInt uiDepth = rpcTempCU-&gt;getDepth
2678 0