首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > 多媒体 >

Xvid有关问题,请大家帮帮忙,多谢

2012-03-22 
Xvid问题,请大家帮帮忙,谢谢我Xvid编码一个图像数据,不知道怎么的编码后输出数据流为0请帮我看看,就是inSt

Xvid问题,请大家帮帮忙,谢谢
我Xvid编码一个图像数据,不知道怎么的编码后输出数据流为0
请帮我看看,就是inStream图形数据,编码后outStream为0,sucess非0

C/C++ code
    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);


[解决办法]
肯定是参数设置错误
看demo程序
你的图像数据是YUV格式么?
[解决办法]
#include "StdAfx.h"
#include "XviDCodec.h"
#include "Helpers.h"
using namespace VideoCodec;





/************************************************************************/
/* XviD Encoder */
/************************************************************************/
CXviDEncoder::CXviDEncoder(void)
{
INIT_REFCOUNT
}

CXviDEncoder::~CXviDEncoder(void)
{
if (encoderCreate.handle)
{
xvid_encore(encoderCreate.handle,XVID_ENC_DESTROY,NULL,NULL);
encoderCreate.handle = NULL;
}
}

long CXviDEncoder::InitEncoder(VideoDecodeFormat& inputFormat,VideoEncodeFormat &outputFormat)
{
inputFormat.colorSpace = RAW_FMT_YUV420P;
outputFormat.codecID = CODECID_XVID;
inputFormat.width = outputFormat.width;
inputFormat.height= outputFormat.height;

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;
}

memset(&encoderCreate,0,sizeof(encoderCreate));
encoderCreate.version = XVID_VERSION;
encoderCreate.profile = XVID_PROFILE_ARTS_L4;
encoderCreate.num_slices = 7;
encoderCreate.width = inputFormat.width;
encoderCreate.height = inputFormat.height;
encoderCreate.fbase = inputFormat.fps;
encoderCreate.fincr = 1;
encoderCreate.max_bframes = outputFormat.bFrameIntervalMax;
encoderCreate.max_key_interval = outputFormat.iFrameIntervalMax;
//encoderCreate.global = XVID_GLOBAL_PACKED;

memset(&singlePlugin,0,sizeof(singlePlugin));
singlePlugin.version = XVID_VERSION;
singlePlugin.bitrate = outputFormat.bitrate * 1000;
singlePlugin.averaging_period = 100;
singlePlugin.reaction_delay_factor = 16;
singlePlugin.buffer = 100;

memset(&encodePlugin,0,sizeof(encodePlugin));
encodePlugin[0].func = xvid_plugin_single;
encodePlugin[0].param = &singlePlugin;

encoderCreate.num_plugins = 1;
encoderCreate.plugins = encodePlugin;


xvid_encore(NULL,XVID_ENC_CREATE,&encoderCreate,NULL);

inputRawFormat = inputFormat;
return 0;
}
long CXviDEncoder::Encode(VideoPacket* inputFrame,VideoPacket *outputFrame)
{
if (!encoderCreate.handle)
{
return RET_FAILED_ENCODE;
}
CHK_VIDEO_CODEC_PACKET(inputFrame,outputFrame,MAX_XVID_ENCODE_BUFFER_SIZE)

memset(&encodeFrame,0,sizeof(encodeFrame));
encodeFrame.version = XVID_VERSION;
encodeFrame.input.csp = XVID_CSP_I420;
encodeFrame.input.plane[0] = inputFrame->data;
encodeFrame.input.stride[0] = inputFrame->width;


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;
}

热点排行