cisco/openh264

data broken after encoded into h264 stream

Opened this issue · 0 comments

I use openh264(tried both 2.2 and 2.4.1 release version and compiled on ubuntu) to encode 1920x1080 yuv420 frames into h264 stream and write these data into a file. But when I use VLC or potplayer to read this file, I see the data is broken kind of, I don't mean h264 data cannot be recognized. H264 data can be recognized but the frames decoded is broken. On the top of the frame there is a green block(even on first frame I mean I frame where no frames would be reffed to encode this I frame) while inputted yuv420 frames doesn't show this green block on the top of the frame so it is introduced by encoder i think. And also in some other frames there are also some abnormal things with abnormal color different from original yuv frames. And encoder params is here.
ret = WelsCreateSVCEncoder(&pEncoder);
if (ret != 0) {
mprintf("Failed to create encoder.\n");
exit(1);
}
long long event_value = 0;
SEncParamExt param;
(*pEncoder)->GetDefaultParams(pEncoder, &param);
memset(&param, 0, sizeof(SEncParamExt));
param.bEnableFrameCroppingFlag = false;
param.iUsageType = CAMERA_VIDEO_REAL_TIME;
param.iPicWidth = SPECIFIED_WIDTH;
param.iPicHeight = SPECIFIED_HEIGHT;
param.iTargetBitrate = 20000000; // 比特率
param.iRCMode = RC_BITRATE_MODE;// I tried RC_OFF_MODE and RC_QUALITY_MODE but things still bad.
param.fMaxFrameRate = 30.0f; // 最大帧率
param.iSpatialLayerNum = 1;
param.iEntropyCodingModeFlag = 0; // 设置为0,表示CABAC
param.iComplexityMode = MEDIUM_COMPLEXITY; // 设置为 LOW_COMPLEXITY

// 设置 GOP 和 B 帧参数
param.iNumRefFrame = 1; // 参考帧的数量
param.iLTRRefNum = 0; // 长期参考帧的数量
param.iMultipleThreadIdc = 1; // 线程数
param.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_SINGLE_SLICE;
param.sSpatialLayers[0].sSliceArgument.uiSliceNum = 0;
param.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 0;
param.iMaxQp = 28;                      ///< the maximum QP encoder supports
param.iMinQp = 22;

// GOP 参数设置
param.uiIntraPeriod = 30; // 关键帧(I 帧)的周期为 30
//param.uiFrameToBeCoded = 0; //

Uploading uvc_push_stream_first_part.zip…
设置为 0,表示编码当前帧

here is 3 zip files where you can find the h264 stream file and inputed yuv420 frames to check because of the limit of file uploaded so I have divided them into 3 parts and compress them you can decompress one of them to check the file in it.
hope for your reply and if you want to talk on emails for more info, here is my email 1192601321@qq.com.
thanks very much.