Xvid问题,请大家帮帮忙,谢谢
我Xvid编码一个图像数据,不知道怎么的编码后输出数据流为0
请帮我看看,就是inStream图形数据,编码后outStream为0,sucess非0
if(!this->m_EnHandle) { return -1; } xvid_enc_frame_t efXvid; xvid_enc_stats_t esXvid; memset(&efXvid,0,sizeof(efXvid)); memset(&esXvid,0,sizeof(esXvid)); esXvid.version=XVID_VERSION; efXvid.version=XVID_VERSION; efXvid.bitstream=outStream; //加码数据流 efXvid.length=-1; efXvid.input.csp=csp; efXvid.input.plane[0]=inStream; efXvid.input.stride[0]=stride; int sucess=xvid_encore(this->m_EnHandle,XVID_ENC_ENCODE,&efXvid,&esXvid);
encodeFrame.bitstream = outputFrame->data;
encodeFrame.length = outputFrame->lenght;
encodeFrame.vol_flags = 0;
encodeFrame.vop_flags = 0;
encodeFrame.motion = 0;
encodeFrame.type = XVID_TYPE_AUTO;
encodeFrame.quant = 0;
memset(&encodeState,0,sizeof(encodeState));
encodeState.version = XVID_VERSION;
int err = xvid_encore(encoderCreate.handle,XVID_ENC_ENCODE,&encodeFrame,&encodeState);
if (err<0)
{
return err;
}
outputFrame->width = inputFrame->width;
outputFrame->height = inputFrame->height;
outputFrame->lenght = err;
outputFrame->frameType = encodeState.type; //library same type define as xvid
ParasEncodeStream(outputFrame);
return 0;
}
long CXviDEncoder::ControlExtensionInfo(void* Data,unsigned int DataType,bool bSet)
{
return 0;
}
long CXviDEncoder::GetEncodeBlockSize()
{
return Helpers::GetPicSize(inputRawFormat.width,inputRawFormat.height,RAW_FMT_YUV420P);
}
long CXviDEncoder::ParasEncodeStream(VideoPacket* outputFrame)
{
//00 00 xx start code
unsigned char* pByte = (unsigned char*)outputFrame->data;
unsigned char silceCount = 0;
for (unsigned short index = 0; index<outputFrame->lenght-3;++index)
{
if(pByte[index]==0x00 && pByte[index+1]==0x00)
{
outputFrame->sliceOffset[silceCount] = index;
if (silceCount)
{
outputFrame->sliceLenght[silceCount - 1] = index - outputFrame->sliceOffset[silceCount-1];
}
index += 2;
silceCount++;
}
}
if (silceCount)
{
outputFrame->sliceCount = silceCount;
outputFrame->sliceLenght[silceCount-1] = (unsigned short)(outputFrame->lenght - outputFrame->sliceOffset[silceCount-1]);
}
return silceCount;
}
/************************************************************************/
/* XviD Decoder */
/************************************************************************/
CXviDDecoder::CXviDDecoder(void)
{
INIT_REFCOUNT
decoder = NULL;
}
CXviDDecoder::~CXviDDecoder(void)
{
if (decoder)
{
xvid_decore(decoder,XVID_DEC_DESTROY,NULL,NULL);
decoder = NULL;
}
}
long CXviDDecoder::InitDecoder(VideoEncodeFormat& inputFormat, VideoDecodeFormat& outputFormat)
{
xvid_gbl_init_t xvidGblInit;
memset(&xvidGblInit, 0, sizeof(xvidGblInit));
xvidGblInit.version = XVID_VERSION;
xvidGblInit.debug = XVID_DEBUG_ERROR;
xvidGblInit.cpu_flags = 0;
int err = xvid_global(NULL,XVID_GBL_INIT,&xvidGblInit,NULL);
if (err<0)
{
return err;
}
xvid_dec_create_t decoderCreate;
memset(&decoderCreate,0,sizeof(decoderCreate));
decoderCreate.width = inputFormat.width;
decoderCreate.height = inputFormat.height;
decoderCreate.version = XVID_VERSION;
err = xvid_decore(NULL,XVID_DEC_CREATE,&decoderCreate,NULL);
if (err<0)
{
return err;
}
decoder = decoderCreate.handle;
outputFormat.width = inputFormat.width;
outputFormat.height = inputFormat.height;
outputFormat.colorSpace = RAW_FMT_YUV420P;
return 0;
}
long CXviDDecoder::Decode(VideoPacket* inputFrame,VideoPacket *outputFrame)
{
if (!decoder)
{
return RET_FAILED_DECODE;
}
CHK_VIDEO_CODEC_PACKET(inputFrame,outputFrame,MAX_XVID_DECODE_BUFFER_SIZE)
memset(&decodeFrame,0,sizeof(decodeFrame));
decodeFrame.version = XVID_VERSION;
decodeFrame.bitstream = inputFrame->data;
decodeFrame.length = inputFrame->lenght;
decodeFrame.output.csp = XVID_CSP_I420;
decodeFrame.output.plane[0] = outputFrame->data;
decodeFrame.output.stride[0] = inputFrame->width;
memset(&decodeState,0,sizeof(decodeState));
decodeState.version = XVID_VERSION;
int err = xvid_decore(decoder,XVID_DEC_DECODE,&decodeFrame,NULL);
if (err<0)
{
return err;
}
outputFrame->colorSpace = RAW_FMT_YUV420P;
outputFrame->width = inputFrame->width;
outputFrame->height = inputFrame->height;
outputFrame->lenght = outputFrame->width * outputFrame->height * 3 / 2;
return 0;
}