Bitstream Error in the VPS of output stream when AccessUnitDelimeters is turned on

Issue #64 resolved
Former user created an issue

Description:

When encode with AccessUnitDelimeter turned on, the output bitstream will have a corrupt VPS structure, so this will cause decoders to report error and failed to decode the video.

It is because in FrameEncoder::compressFrame(), if AccessUnitDelimeter is turned on, the internal bitstream writer is first used to generate the AU_Delimeter buffer, which will result 1 byte data in the writer, but then the bitstream writer didn't get reset first when it is used in the function getStreamHeaders() to generate the VPS, so there will be 1 byte of error data at the beginning of VPS, which is write into the output stream.

Version:

Seems it appears after version 1.1+140-ba9c58a4bee0

Proposed Fix

I think the fix is to reset the bitstream writer before actually generate the VPS, this will solve the problem.

void FrameEncoder::getStreamHeaders(NALList& list, Bitstream& bs)
{
    TEncEntropy* entropyCoder = getEntropyCoder(0);

    /* headers for start of bitstream */

+    bs.resetBits();  // fix forcorrupt VPS 

    entropyCoder->setEntropyCoder(&m_sbacCoder, NULL);
    entropyCoder->setBitstream(&bs);
    entropyCoder->encodeVPS(&m_top->m_vps);
    bs.writeByteAlignment();
    list.serialize(NAL_UNIT_VPS, bs);

    bs.resetBits();
    entropyCoder->encodeSPS(&m_sps);
    bs.writeByteAlignment();

Thanks!

regards,

Albert.

Comments (2)

  1. Deepthi Nandakumar

    Thanks, yes - that sounds like a bug fix. Can you send a patch for this, so this contribution can be attributed to you?

    Please follow the guidelines on the wiki on how to submit patches.

  2. Log in to comment