This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320DM368: Transcoding an H.264 byte stream, previous encoded by DM365 H.264 Encoder 2.30.0.6 with DM365 H.264 Decoder from the DVSDK 4.2.0.6 (DM368)

Part Number: TMS320DM368

Hi,

I am trying to decode an H.264 byte stream, previously encoded by the official encoder, in order to re-encode it using a different bitrate. Actually I was trying to re-encode a stream from a different encoder, but since it did not work, I tried to use the same native H.264 encoder that we use all the time, just to check that the decoder is working properly and that I know how to use it.

Unfortunately, it is not working for me. The decoder initializes fine and after not long it identifies the video resolution correctly. It also sends a few images, which I then feed directly to the encoder with the same parameters, just a different bitrate. However, the images are not recognizable. I should probably assume at this stage that there is some buffer mismatch, perhaps the Y and UV, width and pitch are not passed correctly. But the problems are seen in the log, where almost every call to VIDDEC2_process ends with return code of -1 and some extended error that I get from the status. The common errors are 0x200 (applied concealment) , 0x600 (+insufficient data), etc. The number of consumed bytes is only sometimes related to the length, sometimes more, sometimes less.

HD-Decoding causes the VIDDEC2_process to crash, so I am only trying VGA at this time.

The video decoder is initialized with the following parameters:

IVIDDEC2_Params &vdpParams = m_hvdpParams.viddecParams;
vdpParams.size = sizeof( m_hvdpParams );
vdpParams.maxHeight = MAX_HEIGHT;
vdpParams.maxWidth = MAX_WIDTH;
vdpParams.maxFrameRate = MAX_FRATE * 1000;
vdpParams.maxBitRate = MAX_BITRATE;
vdpParams.dataEndianness = XDM_BYTE;
vdpParams.forceChromaFormat = XDM_YUV_420SP;
m_hvdpParams.displayDelay = 0;
m_hvdpParams.hdvicpHandle = NULL;
m_hvdpParams.disableHDVICPeveryFrame = 0;
m_hvdpParams.levelLimit = LEVEL_4_2;
m_hvdpParams.frame_closedloop_flag = 0;
m_hvdpParams.inputDataMode = IH264VDEC_TI_ENTIREFRAME;
m_hvdpParams.sliceFormat = IH264VDEC_TI_BYTESTREAM;

IVIDDEC2_DynamicParams &vddpDynamicParams = m_hvddDynamicParams.viddecDynamicParams;
vddpDynamicParams.size = sizeof( m_hvddDynamicParams );
vddpDynamicParams.decodeHeader = XDM_DECODE_AU;
vddpDynamicParams.displayWidth = 0;
vddpDynamicParams.frameSkipMode = IVIDEO_NO_SKIP;
vddpDynamicParams.frameOrder = IVIDDEC2_DISPLAY_ORDER;
vddpDynamicParams.newFrameFlag = XDAS_FALSE;
vddpDynamicParams.mbDataFlag = XDAS_FALSE;
m_hvddDynamicParams.getDataFxn = NULL;
m_hvddDynamicParams.dataSyncHandle = NULL;
m_hvddDynamicParams.resetHDVICPeveryFrame = 1;

m_hVideoDecoder = VIDDEC2_create( m_hEngine, "h264dec", &vdpParams );

I have tried to parse the NAL units myself and feed them separately.

I have also tried to just give it a buffer with any NAL units inside and try to progress according to the number of bytes consumed.

Can you tell me what I am doing wrong or what is the right way to use the H.264 decoder?

Thanks,

Gadi

  • Hi Gadi,

    Gadi Bergman said:
    The decoder initializes fine and after not long it identifies the video resolution correctly. It also sends a few images, which I then feed directly to the encoder with the same parameters, just a different bitrate. However, the images are not recognizable

    Could you check by dumping the decoder output before feeding directly to the encoder. Since decoder is throwing insufficient data error,  Stream might be corrupted.May be this decoder dump should give you some clue. You can also use the sample test application in the package for this experiment @(dm365_h264dec_02_00_00_13_production/dm365_h264dec_02_00_00_13_production/packages/ti/sdo/codecs/h264dec/apps/client/).

    Did you try freshly encoding a stream instead of using the existing one?

  • Hi Prashanth,

    Thank you for your suggestion. The problem is that I don't have or don't know of a tool that would take the output of the decoder and display it other than the encoder used to pass it on to our system (YUV420SP/NV12). I know the encoder works well. The h.264 video stream looks good when used with FFMPEG decoder on a PC, but I cannot use FFMPEG decoder on the DM368 because it is not fast enough (tried it). My concerns are these:

    1. Perhaps I don't fully understand how to feed the byte stream into the decoder. Should I parse the NAL units and place them as separate input buffers in the same call? Should I call the decoder with one NAL unit at a time as a single input buffer? Should I wait with the SPS and PPS until the IDR or other unit before feeding the stream into the decoder? Should I ignore the NAL units and just feed a single buffer as is? What should I do with the number of bytes consumed? What happens if these bytes consume only part of the input NAL unit? The client test example has many options and is very confusing. I need one set of options that works.

    2. Is it allowed to pass the output buffer from the decoder as an input buffer directly to the h264 encoder? I understand they are both using the same format YUV420SP, I tune the encoder with the decoder output width, height and pitch and assign the input buffer pointers to Y (0) and UV (1) as I get them as output from the decoder. Are the caching and alignment requirements from this output/input buffer similar?

    Thanks,
    Gadi
  • Hi Gadi,

    Can you please share the bitstream(elementary .264 file) which you using?

  • Hi Prashanth,

    You may download an example video file using this link: H.264 Video

    Thanks,

    Gadi

  • Dear Gadi,
    Thanks for sharing the stream.
    Here i see the stream starts with P-frame which has SPS&PPS info. But the I-frame doesn't have any any SPS&PPS information.
    This is not expected behaviour!. Can you please check why is it encoded so?
    I-frame should have SPS&PPS information.

  • Dear Prashanth,

    Thank you for finding this bug in our system involving the order of SPS and PPS with relation to the I-Frame.

    Here is a new file with hopefully a fix to this problem: H.264 Example File

    However, this does not change the fact that I still cannot decode this file without tons of errors and see anything recognizable after re-encoding it.

    Are you capable of decoding it with the TI DM36x H.264 Decoder? If so, can you tell me what I should do in terms of decoder parameters, NAL unit parsing, how to supply the input buffers to the decoder, etc?

  • OK, I found the problem. It was the allocation of the input data buffer. Changing the allocation to CMEM_alloc, as in the decoder example, fixed the problems and now the frames are decoded correctly with no errors and displayed correctly after re-encoding.

    Dear Prashanth, thanks again for your help.
  • Dear Gadi,

    Good to know that its resolved. Thanks for closing this.