video-processingvideo-encodinghevcvideo-codecs

changing HM reference software to display some information about the bitstream


I am very new to the HM HEVC (and the JEM) reference software, and I am currently trying to understand the source code. I want to add some lines to display for each component: name of Algo (i.e. inter/intra Algos) + length of the bitstream+ position in output bin file. To know which component cost more bits to code and how codec is working. I want to do same thing for the JEM also after that. my problem first is that I am unable of understanding a lot of function there, the comment is not sufficient, so is there any references to understand the code??!! (I already read the Manuel ,doesn’t help). 2nd I don’t know where & how exactly to add these lines; is it in TEncGOP, TEncSlice or TEncCU. Ps: I don’t think in TEncGOP.compressGOP so maybe in the 2 other classes.


Solution

  • (I put the answer to comment that @Mourad put four hours ago here, becuase it will be long)

    I assume that you could manage to find where the actual encoding after the RDO loop is implemented. As you correctly mentioned, xEncodeCU is the function you need to refer to make sure you are not still in the RDO.

    Now you need to find the exact function in xEncodeCU that is responsible for your target codec tool.

    For instance, if you want to count the number of bits for coefficient coding, you should be looking into the m_pcEntropyCoder->encodeCoeff() (It's a JEM function and may have different name in the HM). Once you find this line in the xEncodeCU, you may do this and get the number of bits written inside encodeCoeff() function:

    UInt b_before = m_pcEntropyCoder->getNumberOfWrittenBits();
    m_pcEntropyCoder->encodeCoeff( ... );
    UInt b_after = m_pcEntropyCoder->getNumberOfWrittenBits();
    UInt writtenBitsCoeff = b_after - b_before;
    

    One important point: as you cas see, the function getNumberOfWrittenBits() gives you integer rates, which is obtained by rounding sum of fractional rates corresponding to all syntax elements coded inside the function encodeCoeff. This error might or might not be acceptable, depending on your problem. For example, if instead of coefficient coding rate, you wanted to know the rate of CBF, then this error would not be acceptable at all. Because, CBF rate is mostly less than one bit. If this is your case, then you would need to calculate the fractional bits one-by-one. It would be totally different and relatively more complicated than this.