请问谁有6410 H.264编码器初始化的示例代码
参考网上的例子对6410的MFC初始化,但取不到输入缓冲区的地址,希望能找到示例代码,
或者大家帮忙指点一下,先谢谢了。
函数SsbSipH264EncodeGetInBuf(mfcEncodeHandle, frame_size)返回值不正确。
代码如下:
BOOL InitMFCEncode(){
unsigned int uiWidth = 320;
unsigned int uiHeight = 240;
unsigned int uiFramerate = 30;
unsigned int uiBitrate_kbps = 0; //16K, 最大0x7FFF,32767
unsigned int uiGOPNum = 1; // no P picture,没有预测帧
unsigned int frame_size = (uiWidth * uiHeight * 3) >> 1;
mfcEncodeHandle = SsbSipH264EncodeInit(uiWidth, uiHeight, uiFramerate, uiBitrate_kbps,uiGOPNum); //初始化编码器,传入配置参数,获得编码器句柄
if (mfcEncodeHandle == NULL) {
RETAILMSG(1,(L"SsbSipH264EncodeInit Failed.\n"));
return FALSE;
}
mfcEncodeStrmBuf = (unsigned char *) SsbSipH264EncodeGetInBuf(mfcEncodeHandle, frame_size);//此句报错,的返回值为NULL
if (mfcEncodeStrmBuf == NULL) {
RETAILMSG(1,(L"SsbSipH264EncodeGetInBuf Failed.\n"));
SsbSipH264EncodeDeInit(mfcEncodeHandle);
return FALSE;
}
return TRUE;
}
int h264_enc_test()
{
void *handle;
FILE *fp_in, *fp_out;
int ret, i;
unsigned int width, height;
unsigned int frame_rate, bitrate, gop_num;
unsigned int intraqp, qpmax;
float gamma;
unsigned int num_slices;
unsigned int change_param[2], cur_pic_opt[2];
long size;
unsigned char *p_inbuf;
unsigned char *p_outbuf;
fp_in = fopen("\\Storage Card\\newsvga.yuv","rb");
if (fp_in == NULL) {
RETAILMSG(1,(L"File not found\n"));
return 0;
}
fp_out = fopen("\\Storage Card\\news_vga.264", "wb");
if (fp_out == NULL) {
RETAILMSG(1,(L"Cannot open the output file.\n"));
return 0;
}
width = 640;
height = 480;
frame_rate = 25;
bitrate = 1000;
gop_num = 1;
intraqp = 10;
qpmax = 10;
gamma = 0.75;
//////////////////////////////////////
/// 1. Create new instance ///
/// (SsbSipH264EncodeInit) ///
//////////////////////////////////////
handle = SsbSipH264EncodeInit(width, height, frame_rate, bitrate, gop_num, intraqp, qpmax, gamma);
RETAILMSG(1,(L"\n HANDLE = 0x%X.\n", (DWORD) handle));
if (handle == NULL) {
return 0;
}
////////////////////////////////////////////////////////////////////
/// 2. Set some configuration parameter for initialization ///
/// (SsbSipH264EncodeExe) ///
////////////////////////////////////////////////////////////////////
num_slices = 4;
// SsbSipH264EncodeSetConfig(handle, H264_ENC_SETCONF_NUM_SLICES, &num_slices);
////////////////////////////////////////////////
/// 3. Initialize the Encoder Instance ///
/// (SsbSipH264EncodeExe) ///
////////////////////////////////////////////////
if (SsbSipH264EncodeExe(handle) != SSBSIP_H264_ENC_RET_OK) {
RETAILMSG(1,(L"H.264 Encoder Instance Initialization Failed.\n"));
return 0;
}
p_inbuf = SsbSipH264EncodeGetInBuf(handle, 0);
if (p_inbuf == NULL) {
RETAILMSG(1,(L"\n (ERROR)Input buffer is NULL\n"));
return 0;
}
for (i=0; i<650; i++) {
// Reading YUV frame
ret = fread(p_inbuf, 1, (width * height * 3) >> 1, fp_in);
if (ret != ((width * height * 3) >> 1)) {
break;
}
/*
if (i == 27) {
change_param[0] = H264_ENC_PARAM_GOP_NUM;
change_param[1] = 20;
SsbSipH264EncodeSetConfig(handle, H264_ENC_SETCONF_PARAM_CHANGE, &change_param);
change_param[0] = H264_ENC_PARAM_F_RATE;
change_param[1] = (2000 << 16) | 40000;
SsbSipH264EncodeSetConfig(handle, H264_ENC_SETCONF_PARAM_CHANGE, &change_param);
}
else if (i >= 49 && i <= 41) {
cur_pic_opt[0] = H264_ENC_PIC_OPT_IDR;
cur_pic_opt[1] = 1;
SsbSipH264EncodeSetConfig(handle, H264_ENC_SETCONF_CUR_PIC_OPT, &cur_pic_opt);
}
else if (i == 57) {
cur_pic_opt[0] = H264_ENC_PIC_OPT_SKIP;
cur_pic_opt[1] = 1;
SsbSipH264EncodeSetConfig(handle, H264_ENC_SETCONF_CUR_PIC_OPT, &cur_pic_opt);
}
else if (i == 46) {
cur_pic_opt[0] = H264_ENC_PIC_OPT_RECOVERY;
cur_pic_opt[1] = 1;
SsbSipH264EncodeSetConfig(handle, H264_ENC_SETCONF_CUR_PIC_OPT, &cur_pic_opt);
}
*/
ret = SsbSipH264EncodeExe(handle);
RETAILMSG(1,(L"\n Encode, ret=%d\n", ret));
p_outbuf = SsbSipH264EncodeGetOutBuf(handle, &size);
RETAILMSG(1,(L"\n Output Buf = 0x%X, size = %d\n", (DWORD) p_outbuf, size));
fwrite(p_outbuf, 1, size, fp_out);
}
fclose(fp_in);
fclose(fp_out);
RETAILMSG(1,(L"\n $$ Program ends.\n"));
return 0;
}
楼主更新BSP吧,里面有的
myearth,你好,能把你的yuv文件提供出来吗???
网上搜下,搜不到请留邮箱,我也是把一小段的yuv重复copy的
谢谢myearth,编码已经解决一段时间了。请问有解码器初始化的代码吗?
static char outfilename[512];
int decoder_test(char *filename, int dec_type)
{
void *handle;
SSBSIP_MFC_STREAM_INFO stream_info;
FILE *fp_in,*fp_out;
int nLoop, nFrames;
void *pStrmBuf;
int nStrmSize, nReadLeng;
unsigned char *pYUVBuf;
int nYUVLeng;
////////////////////////
// Opening Input File //
////////////////////////
fp_in = fopen(filename, "rb");
if (fp_in == NULL) {
RETAILMSG(1,(L"File not found\n"));
return 0;
}
/* /////////////////////////
// Opening Output File //
/////////////////////////
sprintf(outfilename, "\\Storage Card\\output.yuv");
fp_out = fopen(outfilename,"wb");
if (fp_out == NULL) {
RETAILMSG(1,(L"Cannot open the output file.\n"));
return 0;
}
*/
RETAILMSG(1,(L"### Start Decoding\n"));
/////////////////////////////////////
/// 1. Create new instance ///
/// (SsbSipMfcDecodeInit) ///
/////////////////////////////////////
handle = SsbSipMfcDecodeInit(dec_type);
if (handle == NULL) {
RETAILMSG(1,(L"SsbSipMfcDecodeInit Failed.\n"));
return 0;
}
////////////////////////////////////////////
/// 2. Obtaining the Input Buffer ///
/// (SsbSipMfcDecodeGetInBuf) ///
////////////////////////////////////////////
pStrmBuf = SsbSipMfcDecodeGetInBuf(handle, &nStrmSize);
if (pStrmBuf == NULL) {
RETAILMSG(1,(L"SsbSipMfcDecodeGetInBuf Failed.\n"));
SsbSipMfcDecodeDeInit(handle);
return 0;
}
RETAILMSG(1,(L"\nXXXX pStrmBuf =0x%X. GetCurrentProcessId()=0x%X, nStreamSize = %d\n", pStrmBuf, GetCurrentProcessId(), nStrmSize));
/////////////////////////////////////////////
// Read Video Stream from File //
// (Size of reading is returned //
// by SsbSipMfcDecodeGetInBuf() call) //
/////////////////////////////////////////////
nReadLeng = fread(pStrmBuf, 1, nStrmSize, fp_in);
////////////////////////////////////////////////////////////////
/// 3. Configuring the instance with the config stream ///
/// (SsbSipMfcDecodeExe) ///
////////////////////////////////////////////////////////////////
if (SsbSipMfcDecodeExe(handle, nReadLeng) != SSBSIP_MFC_DEC_RET_OK) {
RETAILMSG(1,(L"MFC Decoder(RING_BUF mode) Configuration Failed.\n"));
return 0;
}
/////////////////////////////////////
/// 4. Get stream information ///
/////////////////////////////////////
SsbSipMfcDecodeGetConfig(handle, MFC_DEC_GETCONF_STREAMINFO, &stream_info);
RETAILMSG(1,(L"\t width=%d height=%d.\n", stream_info.width, stream_info.height));
nFrames = 0;
for (nLoop=0; nLoop < 10000; nLoop++) {
////////////////////////////////////////////
/// 5. Obtaining the Input Buffer ///
/// (SsbSipMfcDecodeGetInBuf) ///
////////////////////////////////////////////
pStrmBuf = SsbSipMfcDecodeGetInBuf(handle, &nStrmSize);
RETAILMSG(1,(L"\t\t---nStrmSize = [%d]\n", nStrmSize));
//////////////////////////////////////////////////
/// Fill the Input Buffer only if required. ///
//////////////////////////////////////////////////
if (nStrmSize > 0) {
RETAILMSG(1,(L"\n *** 1 *** "));
if (feof(fp_in)) {
RETAILMSG(1, (L"\n###############################"));
RETAILMSG(1, (L"\n## END OF FILE ##\n"));
RETAILMSG(1, (L"\n###############################"));
break;
}
RETAILMSG(1,(L"\n *** 2 *** "));
// Read data from file
nReadLeng = fread(pStrmBuf, 1, nStrmSize, fp_in);
RETAILMSG(1,(L"\n *** 3 *** "));
if (nReadLeng == nStrmSize) {
// RETAILMSG(1, (L"\n##################################"));
// RETAILMSG(1, (L"\n# READING ONE UNIT FROM FILE #"));
// RETAILMSG(1, (L"\n##################################\n"));
}
else if (nReadLeng < nStrmSize) {
RETAILMSG(1, (L"\n##########################################"));
RETAILMSG(1, (L"\n## READING THE LAST BLOCK OF FILE ##"));
RETAILMSG(1, (L"\n##########################################"));
}
}
else
nReadLeng = 0;
/////////////////////////////////
/// 6. DECODE ///
/// (SsbSipMfcDecodeExe) ///
/////////////////////////////////
if (SsbSipMfcDecodeExe(handle, nReadLeng) != SSBSIP_MFC_DEC_RET_OK)
break;
/////////////////////////////////////////////
/// 7. Obtaining the Output Buffer ///
/// (SsbSipMfcDecodeGetOutBuf) ///
/////////////////////////////////////////////
pYUVBuf = SsbSipMfcDecodeGetOutBuf(handle, &nYUVLeng);
// if (nLoop > 0 && nLoop < 80)
// fwrite(pYUVBuf, 1, (stream_info.width * stream_info.height * 3) >> 1, fp_out);
RETAILMSG(1,(L"\t [%d] decoded.\n", nLoop));
}
//////////////////////////////////////
/// 8. SsbSipMfcDecodeDeInit ///
//////////////////////////////////////
SsbSipMfcDecodeDeInit(handle);
RETAILMSG(1,(L"\n\n@@@ Program ends.\n"));
fclose(fp_in);
// fclose(fp_out);
return 0;
}
int h264dec_test(char *filename)
{
void *handle;
SSBSIP_H264_STREAM_INFO stream_info;
FILE *fp_in,*fp_out;
int nLoop, nFrames;
void *pStrmBuf;
int nFrameLeng;
unsigned char *pYUVBuf;
int nYUVLeng;
int phy_add_buf_vals[2];
unsigned int post_rotate;
int fram_need_count;
FRAMEX_CTX *pFrameExCtx;
////////////////////////
// Opening Input File //
////////////////////////
//fp_in = fopen(filename, "rb");
fp_in = fopen("\\Storage Card\\ultraviolet-640x480.264", "rb");
//fp_in = fopen("\\Storage Card\\test.264", "rb");
if (fp_in == NULL) {
RETAILMSG(1,(L"File not found\n"));
return 0;
}
/////////////////////////
// Opening Output File //
/////////////////////////
fp_out = fopen("\\My Documents\\Video_Channle25TS.yuv","wb");
if (fp_out == NULL) {
RETAILMSG(1,(L"Cannot open the output file.\n"));
return 0;
}
///////////////////////////////////
// FrameExtractor Initialization //
///////////////////////////////////
pFrameExCtx = FrameExtractorInit(FRAMEX_IN_TYPE_FILE, delimiter_h264, sizeof(delimiter_h264), 1);
FrameExtractorFirst(pFrameExCtx, fp_in);
//////////////////////////////////////
/// 1. Create new instance ///
/// (SsbSipH264DecodeInit) ///
//////////////////////////////////////
handle = SsbSipH264DecodeInit();
if (handle == NULL) {
RETAILMSG(1,(L"H264_Dec_Init Failed.\n"));
return 0;
}
/////////////////////////////////////////////
/// 2. Obtaining the Input Buffer ///
/// (SsbSipH264DecodeGetInBuf) ///
/////////////////////////////////////////////
pStrmBuf = SsbSipH264DecodeGetInBuf(handle, 204800);
if (pStrmBuf == NULL) {
RETAILMSG(1,(L"SsbSipH264DecodeGetInBuf Failed.\n"));
SsbSipH264DecodeDeInit(handle);
return 0;
}
////////////////////////////////////
// H264 CONFIG stream extraction //
////////////////////////////////////
nFrameLeng = ExtractConfigStreamH264(pFrameExCtx, fp_in, pStrmBuf, INPUT_BUFFER_SIZE, NULL);
RETAILMSG(1,(L"n(1) FrameLeng = %d\n", nFrameLeng));
/*
post_rotate = 0x0015;
if (SsbSipH264DecodeSetConfig(handle, H264_DEC_SETCONF_POST_ROTATE, &post_rotate) != SSBSIP_H264_DEC_RET_OK) {
RETAILMSG(1,(L"H.264 Decoder SetConfig failed.\n"));
return 0;
}
RETAILMSG(1,(L"\n*** H264_DEC_SETCONF_POST_ROTATE succeeds.\n"));
*/
////////////////////////////////////////////////////////////////
/// 3. Configuring the instance with the config stream ///
/// (SsbSipH264DecodeExe) ///
////////////////////////////////////////////////////////////////
if (SsbSipH264DecodeExe(handle, nFrameLeng) != SSBSIP_H264_DEC_RET_OK) {
RETAILMSG(1,(L"H.264 Decoder Configuration Failed.\n"));
return 0;
}
/////////////////////////////////////
/// 4. Get stream information ///
/////////////////////////////////////
SsbSipH264DecodeGetConfig(handle, H264_DEC_GETCONF_STREAMINFO, &stream_info);
RETAILMSG(1,(L"\t width=%d height=%d.\n", stream_info.width, stream_info.height));
// SsbSipH264DecodeGetConfig(handle, H264_DEC_GETCONF_FRAM_NEED_COUNT, &fram_need_count);
// RETAILMSG(1,(L"\t %d.\n", fram_need_count));
nFrames = 0;
for (nLoop=0; nLoop < 2000; nLoop++)
{
//////////////////////////////////
/// 5. DECODE ///
/// (SsbSipH264DecodeExe) ///
//////////////////////////////////
if (SsbSipH264DecodeExe(handle, nFrameLeng) != SSBSIP_H264_DEC_RET_OK) {
RETAILMSG(1,(L"\t Decode fail.\n"));
break;
}
//////////////////////////////////////////////
/// 6. Obtaining the Output Buffer ///
/// (SsbSipH264DecodeGetOutBuf) ///
//////////////////////////////////////////////
pYUVBuf = SsbSipH264DecodeGetOutBuf(handle, (long*) &nYUVLeng);
if (pYUVBuf)
printf("pYUVBUF=[0x%08x]\n", pYUVBuf);
else {
printf("pYUVBuf is NULL. nYUVLeng=%d\n", nYUVLeng);
return 0;
}
// if (nLoop < 400)
// fwrite(pYUVBuf, 1, (stream_info.width * stream_info.height * 3) >> 1, fp_out);
RETAILMSG(1,(L"\t [%d] decoded.\n", nLoop));
/////////////////////////////
// Next H.264 VIDEO stream //
/////////////////////////////
nFrameLeng = NextFrameH264(pFrameExCtx, fp_in, pStrmBuf, INPUT_BUFFER_SIZE, NULL);
if (nFrameLeng < 4)
break;
*((unsigned int *) pStrmBuf) = 0x32a047b9;
memset((void *) ((unsigned char *)pStrmBuf + nFrameLeng - 10), 0, 20);
SsbSipH264DecodeGetConfig(handle, H264_DEC_GETCONF_PHYADDR_FRAM_BUF, phy_add_buf_vals);
// RETAILMSG(1, (L"BUF = 0x%X, length = %d, Virtual Addr = 0x%x", phy_add_buf_vals[0], phy_add_buf_vals[1], (unsigned int) pYUVBuf));
}
///////////////////////////////////////
/// 7. SsbSipH264DecodeDeInit ///
///////////////////////////////////////
SsbSipH264DecodeDeInit(handle);
RETAILMSG(1,(L"\n\n@@@ Program ends.\n"));
fclose(fp_in);
fclose(fp_out);
return 0;
}
int h263dec_test(char *filename)
{
void *handle;
SSBSIP_MPEG4_STREAM_INFO stream_info;
FILE *fp_in,*fp_out;
int nLoop, nFrames;
void *pStrmBuf;
int nFrameLeng;
unsigned char *pYUVBuf;
int nYUVLeng;
////////////////////////
// Opening Input File //
////////////////////////
fp_in = fopen(filename, "rb");
if (fp_in == NULL) {
RETAILMSG(1,(L"File not found\n"));
return 0;
}
/////////////////////////
// Opening Output File //
/////////////////////////
fp_out = fopen("\\My Documents\\output.yuv","wb");
if (fp_out == NULL) {
RETAILMSG(1,(L"Cannot open the output file.\n"));
return 0;
}
//////////////////////////////////////
/// 1. Create new instance ///
/// (SsbSipMPEG4DecodeInit) ///
//////////////////////////////////////
handle = SsbSipMPEG4DecodeInit();
if (handle == NULL) {
RETAILMSG(1,(L"SsbSipMPEG4DecodeInit Failed.\n"));
return 0;
}
/////////////////////////////////////////////
/// 2. Obtaining the Input Buffer ///
/// (SsbSipMPEG4DecodeGetInBuf) ///
/////////////////////////////////////////////
pStrmBuf = SsbSipMPEG4DecodeGetInBuf(handle, 200000);
if (pStrmBuf == NULL) {
RETAILMSG(1,(L"SsbSipMPEG4DecodeGetInBuf Failed.\n"));
SsbSipMPEG4DecodeDeInit(handle);
return 0;
}
////////////////////////////////////
// MPEG4 CONFIG stream extraction //
////////////////////////////////////
nFrameLeng = ExtractConfigStreamH263(fp_in, pStrmBuf, INPUT_BUFFER_SIZE, NULL);
////////////////////////////////////////////////////////////////
/// 3. Configuring the instance with the config stream ///
/// (SsbSipMPEG4DecodeExe) ///
////////////////////////////////////////////////////////////////
if (SsbSipMPEG4DecodeExe(handle, nFrameLeng) != SSBSIP_MPEG4_DEC_RET_OK) {
RETAILMSG(1,(L"MPEG4 Decoder Configuration Failed.\n"));
return 0;
}
/////////////////////////////////////
/// 4. Get stream information ///
/////////////////////////////////////
if (SsbSipMPEG4DecodeGetConfig(handle, MPEG4_DEC_GETCONF_STREAMINFO, &stream_info) != SSBSIP_MPEG4_DEC_RET_OK)
return 0;
RETAILMSG(1,(L"\t width=%d height=%d.\n", stream_info.width, stream_info.height));
nFrames = 0;
for (nLoop=0; nLoop < 800; nLoop++)
{
///////////////////////////////////
/// 5. DECODE ///
/// (SsbSipMPEG4DecodeExe) ///
///////////////////////////////////
if (SsbSipMPEG4DecodeExe(handle, nFrameLeng) != SSBSIP_MPEG4_DEC_RET_OK)
break;
//////////////////////////////////////////////
/// 6. Obtaining the Output Buffer ///
/// (SsbSipMPEG4DecodeGetInBuf) ///
//////////////////////////////////////////////
pYUVBuf = SsbSipMPEG4DecodeGetOutBuf(handle, &nYUVLeng);
if (pYUVBuf)
printf("pYUVBUF=[0x%08x]\n", pYUVBuf);
else {
printf("pYUVBuf is NULL\n");
return 0;
}
// if (nLoop > 10 && nLoop < 30)
// fwrite(pYUVBuf, 1, nYUVLeng, fp_out);
RETAILMSG(1,(L"\t [%d] decoded.\n", nLoop));
///////////////////////////
// Next MPEG4 VOP stream //
///////////////////////////
nFrameLeng = NextFrameH263(fp_in, pStrmBuf, INPUT_BUFFER_SIZE, NULL);
if (nFrameLeng < 4)
break;
}
////////////////////////////////////////
/// 7. SsbSipMPEG4DecodeDeInit ///
////////////////////////////////////////
SsbSipMPEG4DecodeDeInit(handle);
RETAILMSG(1,(L"\n\n@@@ Program ends.\n"));
fclose(fp_in);
fclose(fp_out);
return 0;
}
但是 我要做的跟楼主差不多 ,我想问楼主一个问题,
假如解码时期,无法知道视频过来的信息,比如视频的尺寸,那我该如何处理。