从 VVC VTM 参考软件输出值到文本文件

Output values from VVC VTM reference software to a text file

编辑代码来自 CABACWriter.cpp 这是我用来获取宏块中的 no.of 位并将它们输出到文本文件的代码:

    int before;
    int after;
    int diff;
    ofstream outfile;
    outfile.open("Macroblock.txt");
   if (isEncoding())
{
   before = m_BinEncoder.getNumWrittenBits();
}
coding_unit( cu, partitioner, cuCtx );
    if (isEncoding())
    {
        
        after = m_BinEncoder.getNumWrittenBits();
        diff = after - before;
    }
    
    outfile << diff << endl;
    outfile.close();

当我运行时,我只得到文本文件中最后一个宏块的no.of位。

这是我用来在每个宏块中显示 no.of 位而不将它们放入文本文件的代码:

    int before;
    int after;
    int diff;
   
   if (isEncoding())
   {
        
       before = m_BinEncoder.getNumWrittenBits();
   }
// coding unit
  coding_unit( cu, partitioner, cuCtx );
    if (isEncoding())
    {
        after = m_BinEncoder.getNumWrittenBits();
        diff = after - before;
    }
    cout<<"The difference is: "<<diff<<endl;

当我这样做时,我可以看到每个宏块中的位数,而不仅仅是最后一个宏块。

谁能帮我显示输出文本文件中每个宏块的 no.of 位?我正在考虑使用 for 循环,但后来我不知道最大迭代次数应该是多少,因为每个视频在每一帧中都会有不同的 no.of 宏块。所以我认为应该有一个适用于所有人的变量。

所以我想通了。这是得到我要找的东西的正确答案:

    int before;
    int after;
    int diff;
   ofstream outfile;
    outfile.open("Macroblock.txt", ofstream::app);
   if (isEncoding())
   {
        
       before = m_BinEncoder.getNumWrittenBits();
   }
  // coding unit
  coding_unit( cu, partitioner, cuCtx );
    if (isEncoding()){
        
        after = m_BinEncoder.getNumWrittenBits();
       
        diff = after - before;

    }
    
   streambuf* stream_buffer_cout = cout.rdbuf();
    
    streambuf* stream_buffer_file = outfile.rdbuf();
    cout.rdbuf(stream_buffer_file);
    cout<<"The difference is: "<<diff<<endl;
    
    outfile.close();