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.

Linux/DRA746: How to get orignal w/h from stream header

Part Number: DRA746

Tool/software: Linux

Hi Ram, 

I can get w/h from parsing stream header as show below.

1. set decodeHeader of IVIDDEC3_DynamicParams to XDM_PARSE_HEADER

2. call XDM_SETPARAMS

3. call XDM_GETSTATUS and the correct w/h are stored in outputHeight/outputWidth

But w/h i got are aligned in step 3.

240X180 is aligned to 240*192, which is not expected.

So how to get original width and hegiht?

  • Hi Gao,
    For which decoder you are seeing the height getting aligned?

    Ram
  • HI Gao,
    Can you please share a small dump of your stream. I don't have a stream with this resolution.

    Ram
  • I do some tests for mpeg4 decoder, and i find mpeg4 decoder returns the original width and height to application, not like 264 does.
  • Hi Ram,

    I attach this mp4, you can do some further check with this file

  • Hi Ram,
    and the same as 1080P, 264 decoder will return 1920x1088 parsing from stream header instead of 1920x1080
  • Hi Gao,

    I have attached the Elecard analyzer snapshot for this stream, It looks decoder respects pic_height_in_map_units_minus1 while deriving the frame_height and also respects crop information to  provide 180 as output video.

    I will let you know once I confirm with codec team.

    Ram

  • Hi Gao,

    The above post from Ram is correct. Its with respect to H.264 standard.

    The streams encoded with frame_cropping_flag will be always aligned. If the frame_cropping_flag is disabled then we will get the actual width & height. In the shared stream, actual Height can be calculated from:

    actual_height = (pic_height_in_map_units_minus1 + 1) - (2 * frame_crop_bottom_flag)

                          = (11Mbs + 1) - (2*6)

                          = 12MBs(192 pixels) - (12)

                          = 180 pixels.

    Similarly for HD (1920x1080)

    actual_height =  1088 - (2 * 4)

                          = 1080.

  • Hi Prashanth,

    Thank you for your answer.

    The above post is how to calculate original width and height from elecard streamEye.

    I wonder how to get original w/h from stream header, according to IVIDDEC3_Status struct?

  • Hi Gao,

    Yes, this is how the actual Resolution is calculated in H.264. To be specific,

    if(frame_cropping_flag){

    width = ((pic_width_in_mbs_minus1 +1)*16) - frame_crop_left_offset*2 - frame_crop_right_offset*2;
    height= ((2 - frame_mbs_only_flag)* (pic_height_in_map_units_minus1 +1) * 16) - (frame_crop_top_offset * 2) - (frame_crop_bottom_offset * 2);

    }

    When frame_cropping_flag is equal to 0, the following values shall be inferred: frame_crop_left_offset = 0, frame_crop_right_offset = 0, frame_crop_top_offset = 0, and frame_crop_bottom_offset = 0.

    The above is according to H.264 Spec.

  • Hi Prashanth,
    The answer post above means I should parse stream header by myself to get frame_crop_left_offset/frame_crop_right_offset /frame_crop_top_offset/frame_crop_bottom_offset/pic_width_in_mbs_minus1/frame_cropping_flag. And I cannot get actual resolution from 264 decoder directly?

    Best Regrads
  • Hi Prashanth,
    The answer post above is telling me how to get original width and height from sps/pps, which application can parse using ffmpeg thirdparty library.
    But I wonder how to get orginal width and height directly without parsing sps/pps, because I already using ti 264 decoder to parse stream header.
    I seems ti 264 decoder does not support this feature?

    Best Regards.
    Gao
  • Hi Gao,
    I am looking on the same. I will get back to you.
  • Hi Gao,

    By analysing more on this I got few points to share with you.

    As per H.264 Spec. XDM_GETSTATUS call will give the aligned width & height. The aligned resolution is needed for buffer allocation.

    The Actual Width & Height can be found from ,  outArgs->displayBufs.activeFrameRegion after decoding the full frame.

    activeFrameRegion (http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/xdais/latest/docs/html/struct_i_v_i_d_e_o2___buf_desc.html#details)

    Please refer Appendix A (Picture Format in H.264 User Guide). Attaching the snap shot of UserGuide here.

  • Hi Gao,
    Some more information on why it returns aligned resolution.

    Application will do XDM_GETBUFINFO control call to know the buffer requirements. Codec will return the aligned width & height. Application has to allocate the buffers for the aligned resolution to avoid Buffer corruption. If in case buffers are allocated for actual width & height, buffers will be corrupted and no output will be seen.

    That's the reason XDM_GESTATUS will have aligned resolution. And the actual resolution will be returned at outArgs->displayBufs.activeFrameRegion when the frame is ready to display.
  • Hi Prashanth,
    I try to get original resolution as you tell above, sometimes mOutArgs->displayBufs.bufDesc[0].activeFrameRegion returns invalid value at started. The logs are below as show, and I get the right resolution until input frame count is 13.

    =====================
    Line 5113: 11-13 18:07:05.327 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 1, mInArgs->inputID=0xb3720fd0, fd 0x23, mInput 0xb0223000, size 817, bytesConsumed 817, timestamp 0.000, err -1
    Line 5115: 11-13 18:07:05.327 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5117: 11-13 18:07:05.327 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0x2000a00, IH264VDEC_ERR_MISSINGSLICE XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 5153: 11-13 18:07:05.330 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 2, mInArgs->inputID=0xb3720820, fd 0x2b, mInput 0xa953d000, size 13, bytesConsumed 13, timestamp 0.060, err -1
    Line 5155: 11-13 18:07:05.330 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5157: 11-13 18:07:05.330 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0x2000a00, IH264VDEC_ERR_MISSINGSLICE XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 5291: 11-13 18:07:05.333 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 3, mInArgs->inputID=0xb3720670, fd 0x2d, mInput 0xa9531000, size 12, bytesConsumed 12, timestamp 0.040, err -1
    Line 5303: 11-13 18:07:05.333 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5379: 11-13 18:07:05.337 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0x2000a00, IH264VDEC_ERR_MISSINGSLICE XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 5455: 11-13 18:07:05.342 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 4, mInArgs->inputID=0xb3721050, fd 0x2f, mInput 0xa9525000, size 12, bytesConsumed 12, timestamp 0.020, err -1
    Line 5459: 11-13 18:07:05.343 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5473: 11-13 18:07:05.343 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0x2000a00, IH264VDEC_ERR_MISSINGSLICE XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 5509: 11-13 18:07:05.350 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 5, mInArgs->inputID=0xb3721088, fd 0x31, mInput 0xa9519000, size 2885, bytesConsumed 2885, timestamp 0.080, err -1
    Line 5511: 11-13 18:07:05.351 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5513: 11-13 18:07:05.351 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0x2000a00, IH264VDEC_ERR_MISSINGSLICE XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 5589: 11-13 18:07:05.354 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 6, mInArgs->inputID=0xb37210c0, fd 0x33, mInput 0xa950d000, size 735, bytesConsumed 735, timestamp 0.140, err -1
    Line 5619: 11-13 18:07:05.356 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5621: 11-13 18:07:05.356 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0xa10, IH264VDEC_ERR_MBDATA XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 5643: 11-13 18:07:05.359 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 7, mInArgs->inputID=0xb3720ff0, fd 0x35, mInput 0xa9501000, size 393, bytesConsumed 393, timestamp 0.120, err -1
    Line 5647: 11-13 18:07:05.359 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5649: 11-13 18:07:05.359 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0x2000a00, IH264VDEC_ERR_MISSINGSLICE XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 5793: 11-13 18:07:05.374 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 8, mInArgs->inputID=0xb3721180, fd 0x37, mInput 0xa94f5000, size 91, bytesConsumed 91, timestamp 0.100, err -1
    Line 5797: 11-13 18:07:05.375 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5799: 11-13 18:07:05.375 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0x2000a00, IH264VDEC_ERR_MISSINGSLICE XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 5851: 11-13 18:07:05.379 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 9, mInArgs->inputID=0xb37211b8, fd 0x23, mInput 0xb0223000, size 819, bytesConsumed 819, timestamp 0.200, err -1
    Line 5853: 11-13 18:07:05.379 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5855: 11-13 18:07:05.379 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0x2000a00, IH264VDEC_ERR_MISSINGSLICE XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 5909: 11-13 18:07:05.384 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 10, mInArgs->inputID=0xb37211f0, fd 0x2b, mInput 0xa953d000, size 52, bytesConsumed 52, timestamp 0.180, err -1
    Line 5911: 11-13 18:07:05.384 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5913: 11-13 18:07:05.384 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0xa10, IH264VDEC_ERR_MBDATA XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 5959: 11-13 18:07:05.389 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 11, mInArgs->inputID=0xb3721228, fd 0x2d, mInput 0xa9531000, size 74, bytesConsumed 74, timestamp 0.160, err -1
    Line 5961: 11-13 18:07:05.389 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 5963: 11-13 18:07:05.389 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0xa10, IH264VDEC_ERR_MBDATA XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 6011: 11-13 18:07:05.393 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 12, mInArgs->inputID=0xb3721260, fd 0x2f, mInput 0xa9525000, size 302, bytesConsumed 302, timestamp 0.220, err -1
    Line 6013: 11-13 18:07:05.393 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(0, 0), (0, 0)
    Line 6015: 11-13 18:07:05.393 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0x2000a00, IH264VDEC_ERR_MISSINGSLICE XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 6067: 11-13 18:07:05.397 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 13, mInArgs->inputID=0xb3721298, fd 0x31, mInput 0xa9519000, size 3708, bytesConsumed 3708, timestamp 0.240, err -1
    Line 6069: 11-13 18:07:05.397 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(32, 24), (272, 204)
    Line 6071: 11-13 18:07:05.397 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 511)get output frame, mInCount: 013, mOutCount: 001, outBuf: 0xb3720fd0, drmName: 20
    Line 6073: 11-13 18:07:05.397 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 525)FreeBufID[0]: 0xb3720fd0 fd:63
    Line 6075: 11-13 18:07:05.397 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0xa10, IH264VDEC_ERR_MBDATA XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 6187: 11-13 18:07:05.404 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 14, mInArgs->inputID=0xb37212d0, fd 0x33, mInput 0xa950d000, size 261, bytesConsumed 261, timestamp 0.300, err -1
    Line 6189: 11-13 18:07:05.404 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(32, 24), (272, 204)
    Line 6191: 11-13 18:07:05.404 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 511)get output frame, mInCount: 014, mOutCount: 002, outBuf: 0xb3721050, drmName: 23
    Line 6193: 11-13 18:07:05.404 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 525)FreeBufID[0]: 0xb3721050 fd:69
    Line 6195: 11-13 18:07:05.405 15286 15301 D DecoderH264: [TI] (decoder_h264.cc, checkExtendedErr, 136)mOutArgs->extendedError 0xa10, IH264VDEC_ERR_MBDATA XDM_APPLIEDCONCEALMENT XDM_CORRUPTEDDATA
    Line 6213: 11-13 18:07:05.408 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 484)VIDDEC3_process mInCount 15, mInArgs->inputID=0xb37210f8, fd 0x35, mInput 0xa9501000, size 83, bytesConsumed 83, timestamp 0.280, err -1
    Line 6215: 11-13 18:07:05.408 15286 15301 D DecoderBase: [TI] (decoder_base.cc, processBuffer, 490)(32, 24), (272, 204)
    ================================

    So Whether 264 decoder sets original resolution to outputWidth/outputHeight of IVIDDEC3_Status and application do the aligned job, which as mpeg4/mpeg2 decoder do.

    Best Regards.
    Gao
  • Hi Gao,

    That might be possible because, the displayDelay    = IVIDDEC3_DISPLAY_DELAY_AUTO; Here the buffers held by the codec are given to display w.r.t display delay. It can hold up-to 16 frames when set to IVIDDEC3_DISPLAY_DELAY_AUTO.

    Can you set it to IVIDDEC3_DECODE_ORDER ? It should return the exact resolution after decoding first frame.

  • Hi Prashanth,
    Setting displayDelay to IVIDDEC3_DECODE_ORDER means output frames are out of order, which I do not expect.
    So, I try to get original resolution using ffmpeg third party and it works well for me now.
    Thanks for you supports.

    Best Regards
    Gao
  • Hi Gao,

    Yes, it would display out of order. This is just to get the actual frame resolution after decoding first frame. Later on its recommended to set display delay as AUTO. Thanks. Can we close this thread if its answered the query?