void CALLBACK DecCBFun(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nUser,long nReserved2)
{
hik_player_t *hp = (hik_player_t *)nUser;
long lFrameType = pFrameInfo->nType;
if (lFrameType ==T_AUDIO16)
{
printf("Audio nStamp:%d size:%d pFrameInfo:%dn",pFrameInfo->nStamp,nSize,pFrameInfo->nFrameRate);
}
else if(lFrameType ==T_YV12)
{
if(hp->in_width == 0 || hp->in_height == 0) {
hp->in_width = pFrameInfo->nWidth;
hp->in_height = pFrameInfo->nHeight;
avpicture_alloc(&hp->in_yuv, AV_PIX_FMT_YUV420P, hp->in_width, hp->in_height);
avpicture_alloc(&hp->out_yuv, AV_PIX_FMT_YUV420P, hp->out_width, hp->out_height);
WelsCreateSVCEncoder(&hp->encoder_);
//initilize with basic parameter
SEncParamExt param;
memset (¶m, 0, sizeof (SEncParamBase));
hp->encoder_->GetDefaultParams(¶m);
param.iUsageType = CAMERA_VIDEO_REAL_TIME;
param.fMaxFrameRate = pFrameInfo->nFrameRate;
param.iPicWidth = hp->out_width;
param.iPicHeight = hp->out_height;
param.iTargetBitrate = hp->out_bitrate;
param.iRCMode = RC_QUALITY_MODE;
param.iTemporalLayerNum = 1;
param.iSpatialLayerNum = 1;
param.bEnableDenoise = 0;
param.bEnableBackgroundDetection = 1;
param.bEnableAdaptiveQuant = 1;
// param.bEnableFrameSkip = 0;
param.bEnableLongTermReference = 0;
param.iLtrMarkPeriod = 30;
param.uiIntraPeriod = (unsigned int)pFrameInfo->nFrameRate*2;
param.eSpsPpsIdStrategy = CONSTANT_ID;
param.bPrefixNalAddingCtrl = 0;
param.sSpatialLayers[0].iVideoWidth = param.iPicWidth;
param.sSpatialLayers[0].iVideoHeight = param.iPicHeight;
param.sSpatialLayers[0].fFrameRate = param.fMaxFrameRate;
param.sSpatialLayers[0].iSpatialBitrate = param.iTargetBitrate;
param.sSpatialLayers[0].iMaxSpatialBitrate = param.iMaxBitrate;
hp->encoder_->InitializeExt(¶m);
// hp->encoder_->Initialize(¶m);
//set option, set option during encoding process
// int g_LevelSetting = 0;
// hp->encoder_->SetOption(ENCODER_OPTION_TRACE_LEVEL, &g_LevelSetting);
int videoFormat = videoFormatI420;
hp->encoder_->SetOption(ENCODER_OPTION_DATAFORMAT, &videoFormat);
hp->file = fopen("d:\out.h264","wb+");
}
//printf("Video nStamp:%d size:%d width:%d height:%d fps:%d n",pFrameInfo->nStamp,nSize,pFrameInfo->nWidth,pFrameInfo->nHeight,pFrameInfo->nFrameRate);
avpicture_fill(&hp->in_yuv,(const uint8_t*)pBuf, AV_PIX_FMT_YUV420P,hp->in_width,hp->in_height);
libyuv::I420Scale(hp->in_yuv.data[0],hp->in_yuv.linesize[0],
hp->in_yuv.data[1],hp->in_yuv.linesize[1],
hp->in_yuv.data[2],hp->in_yuv.linesize[2],
hp->in_width,hp->in_height,
hp->out_yuv.data[0],hp->out_yuv.linesize[0],
hp->out_yuv.data[1],hp->out_yuv.linesize[1],
hp->out_yuv.data[2],hp->out_yuv.linesize[2],
hp->out_width,hp->out_height,libyuv::kFilterNone);
SFrameBSInfo info;
memset(&info, 0, sizeof (SFrameBSInfo));
SSourcePicture pic;
memset (&pic, 0, sizeof (SSourcePicture));
pic.iPicWidth = hp->out_width;
pic.iPicHeight = hp->out_height;
pic.iColorFormat = videoFormatI420;
pic.iStride[0] = hp->out_yuv.linesize[0];
pic.iStride[1] = pic.iStride[2] = hp->out_yuv.linesize[1];
pic.pData[0] = hp->out_yuv.data[0];
pic.pData[1] = hp->out_yuv.data[1];
pic.pData[2] = hp->out_yuv.data[2];
int ret = hp->encoder_->EncodeFrame(&pic, &info);
if(info.eFrameType != videoFrameTypeSkip ) {
if(info.eFrameType == videoFrameTypeIDR) {
// printf("key framen");
}
int first_layer = 0;
if(hp->have_spspps) {
first_layer = info.iLayerNum - 1;
} else {
hp->have_spspps = true;
}
for(int i=first_layer;i<info.iLayerNum;i++) {
//printf("Layer:%d NalCount:%dn",i,info.sLayerInfo[i].iNalCount);
int pos = 0;
for (int j = 0; j < info.sLayerInfo[i].iNalCount; j++) {
// printf("%d %d iFrameSizeInBytes:%d NalLengthInByte: %dn",i,j,info.iFrameSizeInBytes, info.sLayerInfo[i].pNalLengthInByte[j]);
fwrite(info.sLayerInfo[i].pBsBuf+pos,*info.sLayerInfo[i].pNalLengthInByte,1,hp->file);
pos+=*info.sLayerInfo[i].pNalLengthInByte;
}
}
//
}
/*
if (encoder_) {
encoder_->Uninitialize();
WelsDestroySVCEncoder (encoder_);
}
*/
}
else
{
}
}