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.

DVRRDK_04_01 H264 to H264 transcode problem

Hello. I wrote custom transcode chain using linkapi. The chain gets MPEG2 or H264 video as input and transcodes it to H264 with or without deinterlacing. The picture is ok when mpeg2 is used as the input, but some kind of frame shift appears when I use H264 as the input even if it is the video transcoded by my chain.

Here is the some examples:

When MPEG2 as the input:

When previous output is used as the input:

Decoder params:

if(codecID == AV_CODEC_ID_MPEG2VIDEO) {
_params.chCreateParams[chId].format = IVIDEO_MPEG2HP;
} else {
_params.chCreateParams[chId].format = IVIDEO_H264HP;
}

_params.chCreateParams[chId].fieldMergeDecodeEnable = 0;
_params.chCreateParams[chId].numBufPerCh = 10;

_params.chCreateParams[chId].profile = IH264VDEC_PROFILE_ANY;
_params.chCreateParams[chId].displayDelay = -1;
_params.chCreateParams[chId].dpbBufSizeInFrames = IH264VDEC_DPB_NUMFRAMES_AUTO;

if(interlaced) {
_params.chCreateParams[chId].processCallLevel = VDEC_FIELDLEVELPROCESSCALL;
} else {
_params.chCreateParams[chId].processCallLevel = VDEC_FRAMELEVELPROCESSCALL;
}

_params.chCreateParams[chId].targetMaxWidth = 720;
_params.chCreateParams[chId].targetMaxHeight = 576;
_params.chCreateParams[chId].defaultDynamicParams.targetFrameRate = 25;

Encoder params:

_params.chCreateParams[chId].format = IVIDEO_H264HP;
_params.chCreateParams[chId].profile = IH264_HIGH_PROFILE;
_params.chCreateParams[chId].fieldMergeEncodeEnable = 0;
_params.chCreateParams[chId].encodingPreset = VENC_XDM_USER_DEFINED;
_params.chCreateParams[chId].rateControlPreset = VENC_RATE_CTRL_VBR;
_params.chCreateParams[chId].defaultDynamicParams.intraFrameInterval = 25;
_params.chCreateParams[chId].defaultDynamicParams.targetBitRate = 2000*1000;
_params.chCreateParams[chId].maxBitRate = _params.chCreateParams[chId].defaultDynamicParams.targetBitRate * 1.55;
_params.chCreateParams[chId].defaultDynamicParams.interFrameInterval = 1;
_params.chCreateParams[chId].defaultDynamicParams.mvAccuracy = IVIDENC2_MOTIONVECTOR_QUARTERPEL;
_params.chCreateParams[chId].defaultDynamicParams.inputFrameRate = inputFrameRate;
_params.chCreateParams[chId].defaultDynamicParams.rcAlg = VENC_RATE_CTRL_VBR;
_params.chCreateParams[chId].defaultDynamicParams.qpMin = 1;
_params.chCreateParams[chId].defaultDynamicParams.qpMax = 35;
_params.chCreateParams[chId].defaultDynamicParams.qpInit = -1;

Deinterlacer output queue is DEI_LINK_OUT_QUE_VIP_SC

Filling the buffer: 

memcpy(list.bufs[0]->addr, packet->buf->data, packet->buf->size);
list.bufs[0]->fillLength = packet->buf->size;
list.bufs[0]->upperTimeStamp = static_cast<UInt32> ((packet->pts >> 32)& 0xFFFFFFFF);
list.bufs[0]->lowerTimeStamp = static_cast<UInt32> (packet->pts & 0xFFFFFFFF);

IpcBitsOutHLOS channel info:

_params.inQueInfo.chInfo[chId].width = 720;
_params.inQueInfo.chInfo[chId].height = 576;
_params.inQueInfo.chInfo[chId].scanFormat = scanFmt;
_params.inQueInfo.chInfo[chId].bufType = 0; // NOT USED
_params.inQueInfo.chInfo[chId].codingformat = 0; // NOT USED
_params.inQueInfo.chInfo[chId].dataFormat = 0; // NOT USED
_params.inQueInfo.chInfo[chId].memType = 0; // NOT USED
_params.inQueInfo.chInfo[chId].startX = 0; // NOT USED
_params.inQueInfo.chInfo[chId].startY = 0; // NOT USED
_params.inQueInfo.chInfo[chId].pitch[0] = 0; // NOT USED
_params.inQueInfo.chInfo[chId].pitch[1] = 0; // NOT USED
_params.inQueInfo.chInfo[chId].pitch[2] = 0; // NOT USED
_params.maxQueueDepth[chId] = 20;
_params.chMaxReqBufSize[chId] = 720 * 576;
_params.totalBitStreamBufferSize[chId] = 720 * 576 * 5;

I think it could be related to the buffer padding, because there was the same problem with ezsdk. Could you help me please?

  • Hi,

    Looks H264 encoder is not getting correct offset/buffer pointer. Please note padding sizes will be different for H264 and MPEG2. Please check input buffer related to padding.

    Thanks,

  • Hi,

    I'm not responsible for buffer exchange between two links and can not control the padding through link api if I understand correctly. Could you explain how to set correct offset or provide the patch which fix this issue?
  • Hi,

    I've tried to use tiled memory but the artifacts are still there. Is there any way to change buffer offsets but do not pass frames to A8 to do so?

  • I have  found  the cause of the problem. EncLink_AlgDynamicParams.startX and EncLink_AlgDynamicParams.startY are set to 0 at startup. Encoder link is not taking in account  the input frame's start coords when changing the dynamic params of encoder. I added these lines to EncLink_codecDynamicResolutionChange in encLink_common.c:

    if(pFrameInfo->rtChInfo.startX != chDynamicParams->startX) {
    chDynamicParams->startX = pFrameInfo->rtChInfo.startX;
    rtParamUpdatePerFrame = TRUE;
    }
    if(pFrameInfo->rtChInfo.startY != chDynamicParams->startY) {
    chDynamicParams->startY = pFrameInfo->rtChInfo.startY;
    rtParamUpdatePerFrame = TRUE;
    }

    These changes helped me to fix the encoder link. Right after that I decided to add deinterlacer into the chain. I found that it's also suffering the same problem. Dei is much more complicated component to fix. Could someone from TI help me to resolve this problem?