0

Final:Result after calculating and displaying the differenceI am new to VVC and I am going through the reference software's code trying to understand it. I have encoded and decoded videos using the reference software. I want to extract the bitstream from it, I want to know the number of bits there are in each macroblock. I am not sure which class I should be working with, for now I am looking at, mv.cpp, QuantRDOQ.cpp, and TrQuant.cpp.

I am afraid to mess the code up completely, I don't know where to add what lines of code. Start: Result after calculating and displaying the difference P.S. The linked pictures are after my problem has been solved, I attached these pictures because of my query in the comments.

YS2021
  • 13
  • 4

2 Answers2

0

The simpleset solution that I'm aware of is at the encoder side.

The trick is to compute the difference in the number of written bits "before" and "after" encoding a Coding Unit (CU) (aka macroblock). This stuff happens in the CABACWriter.cpp file.

You should go to to coding_tree() function, where coding_unit() function is called, which is responsible for context-coding all syntax elementes in the current CU. There, you may call the function getNumBins() twice: once before and once after coding_unit(). The difference of the two value should do the job for you.

Mosen
  • 403
  • 2
  • 7
  • Thanks a lot for your suggestion! I called the getnumbins () function and tried to print out the values in CABACWriter.cpp but I get this error during compilation: libc++abi.dylib: terminating with uncaught exception of type Exception: ERROR: In function "getNumBins" in /Users/mac/documents/VVCSoftware_VTM-master/source/Lib/EncoderLib/BinEncoder.h:254: Not supported @Mosen – YS2021 Jul 22 '20 at 15:36
  • Thanks a lot for your suggestion! I called the getnumbins () function and tried to print out the values in CABACWriter.cpp but I get this error during compilation: libc++abi.dylib: terminating with uncaught exception of type Exception: ERROR: In function "getNumBins" in /Users/mac/documents/VVCSoftware_VTM-master/source/Lib/EncoderLib/BinEncoder.h:254: Not supported @Mosen I tried replying but I don't know why I can't tag your name properly so I am not sure if you'll see this. – YS2021 Jul 22 '20 at 23:50
0

As the error says, getNumBins() is not supported by the CABAC estimator. So you should make sure you call it "only" during the encoding, and not during the RDO.

This should do the job:

if (isEncoding())
    before = m_BinEncoder.getNumBins()

coding_unit( cu, partitioner, cuCtx );

if (isEncoding())
{
    after = m_BinEncoder.getNumBins();
    diff = after - before;
}
Mosen
  • 403
  • 2
  • 7
  • Thanks a lot for your reply. I'll try and let you know if it works. – YS2021 Jul 28 '20 at 17:42
  • I tried it out and it works, I tried to print out the difference because I wanted to know the number of bits in a macroblock. I added the line: cout<<"The difference is: "< – YS2021 Jul 28 '20 at 19:21
  • could you also suggest how to get the macro block information from the decoder side? And the motion vectors? I want partially decode to get the macro block and motion vectors. Looking forward to your suggestion. @Mosen – YS2021 Jul 31 '20 at 09:15
  • As far as I know, you can't use this solution at the decoder side. – Mosen Aug 03 '20 at 10:39
  • Alright, thanks for letting me know. Sorry for the late reply, I didn’t realize I got a reply. How would you suggest extracting the motion vectors and the quantization parameters at the encoder side? I think we can get the from CABACWriter.cpp as well. @Mosen – YS2021 Aug 06 '20 at 23:31
  • I figured out how to extract the quantization parameters. I extracted them from EncGOP.cpp. Now I am working on extracting the motion vectors. – YS2021 Aug 12 '20 at 09:49
  • Same principle applies on motion vectors. Except that you should be dealing with some other functions e.g. `cu_pred_data`, `merge_flag`, `merge_data`, `mvp_flag`, `affine_flag`, `mvd_coding` etc. – Mosen Aug 12 '20 at 10:22
  • Thank you. I think I got the motion vectors as well but not sure if they are correct. Now I am looking at getting the number of ctu (width x height) so I can have a 2-d array output where I can see which MV refers to which CTU. – YS2021 Aug 21 '20 at 05:45