当前位置: 代码迷 >> 多媒体/流媒体开发 >> Xvid有关问题,请大家帮帮忙,多谢
  详细解决方案

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

热度:6038   发布时间:2013-02-26 00:00:00.0
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;