两个礼拜急死了ffmpeg官网上下的库,debug模式下没错,release模式下动态库序数无法定位,求大神可怜啊

时间:2021-07-19 03:32:44
#include "stdafx.h"
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
};
#include <afx.h>
int _tmain(int argc, _TCHAR* argv[])
{
CFile file[5];
BYTE *szTxt[5];

int nWidth = 0;
int nHeight= 0;

int nDataLen=0;

int nLen;

CString csFileName;
for (int fileI = 1; fileI <= 5; fileI ++)
{
csFileName.Format(_T("D:\\%d.bmp"), fileI);
file[fileI - 1].Open(csFileName,CFile::modeRead | CFile::typeBinary);
nLen = file[fileI - 1].GetLength();

szTxt[fileI -1] = new BYTE[nLen];
file[fileI - 1].Read(szTxt[fileI - 1], nLen);
file[fileI - 1].Close();

//BMP bmi;//BITMAPINFO bmi;
//int nHeadLen = sizeof(BMP);
BITMAPFILEHEADER bmpFHeader;
BITMAPINFOHEADER bmpIHeader;
memcpy(&bmpFHeader,szTxt[fileI -1],sizeof(BITMAPFILEHEADER));

int nHeadLen = bmpFHeader.bfOffBits - sizeof(BITMAPFILEHEADER);
memcpy(&bmpIHeader,szTxt[fileI - 1]+sizeof(BITMAPFILEHEADER),nHeadLen);

nWidth = bmpIHeader.biWidth;// 464;// bmi.bmpInfo.bmiHeader.biWidth;// ;
nHeight = bmpIHeader.biHeight;//362;// bmi.bmpInfo.bmiHeader.biHeight;// ;

szTxt[fileI - 1] += bmpFHeader.bfOffBits;
nDataLen = nLen-bmpFHeader.bfOffBits;
}
//avcodec_init();
av_register_all();
avcodec_register_all();
AVFrame *m_pRGBFrame =  new AVFrame[1];  //RGB帧数据  
AVFrame *m_pYUVFrame = new AVFrame[1];;  //YUV帧数据
AVCodecContext *c= NULL;
AVCodecContext *in_c= NULL;
AVCodec *pCodecH264; //编码器
uint8_t * yuv_buff;//

//查找h264编码器
pCodecH264 = avcodec_find_encoder(CODEC_ID_H264);
if(!pCodecH264)
{
fprintf(stderr, "h264 codec not found\n");
exit(1);
}

c= avcodec_alloc_context3(pCodecH264);
c->bit_rate = 3000000;// put sample parameters 
c->width =nWidth;// 
c->height = nHeight;// 

// frames per second 
AVRational rate;
rate.num = 1;
rate.den = 25;
c->time_base= rate;//(AVRational){1,25};
c->gop_size = 10; // emit one intra frame every ten frames 
c->max_b_frames=1;
c->thread_count = 1;
c->pix_fmt = PIX_FMT_YUV420P;//PIX_FMT_RGB24;

//av_opt_set(c->priv_data, /*"preset"*/"libvpx-1080p.ffpreset", /*"slow"*/NULL, 0);
//打开编码器
if(avcodec_open2(c,pCodecH264,NULL)<0)
TRACE("不能打开编码库");

int size = c->width * c->height;

yuv_buff = (uint8_t *) malloc((size * 3) / 2); // size for YUV 420 

//将rgb图像数据填充rgb帧
uint8_t * rgb_buff = new uint8_t[nDataLen];

//图象编码
int outbuf_size=100000;
uint8_t * outbuf= (uint8_t*)malloc(outbuf_size); 
int u_size = 0;
FILE *f=NULL; 
char * filename = "D:\\myData.h264";
f = fopen(filename, "wb");
if (!f)
{
TRACE( "could not open %s\n", filename);
exit(1);
}

//初始化SwsContext
SwsContext * scxt = sws_getContext(c->width,c->height,PIX_FMT_BGR24,c->width,c->height,PIX_FMT_YUV420P,SWS_POINT,NULL,NULL,NULL);

AVPacket avpkt;

//AVFrame *pTFrame=new AVFrame
for (int i=0;i<250;++i)
{

//AVFrame *m_pYUVFrame = new AVFrame[1];

int index = (i / 25) % 5;
memcpy(rgb_buff,szTxt[index],nDataLen);

avpicture_fill((AVPicture*)m_pRGBFrame, (uint8_t*)rgb_buff, PIX_FMT_RGB24, nWidth, nHeight);

//将YUV buffer 填充YUV Frame
avpicture_fill((AVPicture*)m_pYUVFrame, (uint8_t*)yuv_buff, PIX_FMT_YUV420P, nWidth, nHeight);

// 翻转RGB图像
m_pRGBFrame->data[0]  += m_pRGBFrame->linesize[0] * (nHeight - 1);
m_pRGBFrame->linesize[0] *= -1;                   
m_pRGBFrame->data[1]  += m_pRGBFrame->linesize[1] * (nHeight / 2 - 1);
m_pRGBFrame->linesize[1] *= -1;
m_pRGBFrame->data[2]  += m_pRGBFrame->linesize[2] * (nHeight / 2 - 1);
m_pRGBFrame->linesize[2] *= -1;


//将RGB转化为YUV
sws_scale(scxt,m_pRGBFrame->data,m_pRGBFrame->linesize,0,c->height,m_pYUVFrame->data,m_pYUVFrame->linesize);

int got_packet_ptr = 0;
av_init_packet(&avpkt);
avpkt.data = outbuf;
avpkt.size = outbuf_size;
u_size = avcodec_encode_video2(c, &avpkt, m_pYUVFrame, &got_packet_ptr);
if (u_size == 0)
{
fwrite(avpkt.data, 1, avpkt.size, f);
}
}

fclose(f); 
delete []m_pRGBFrame;
delete []m_pYUVFrame;
delete []rgb_buff;
free(outbuf);
avcodec_close(c);
av_free(c);

return 0;
}


代码是网上拷贝的,在debug模式下没有问题,由于要用到动态库,在release模式下报错序数XX无法定位于动态库avcodec-55.dll,
动态库和头文件全部是从FFMPEG官网下载的.求大神指导啊,两个礼拜也没搞定

8 个解决方案

#1



#include "stdafx.h"
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
};
#include <afx.h>
int _tmain(int argc, _TCHAR* argv[])
{
CFile file[5];
BYTE *szTxt[5];

int nWidth = 0;
int nHeight= 0;

int nDataLen=0;

int nLen;

CString csFileName;
for (int fileI = 1; fileI <= 5; fileI ++)
{
csFileName.Format(_T("D:\\%d.bmp"), fileI);
file[fileI - 1].Open(csFileName,CFile::modeRead | CFile::typeBinary);
nLen = file[fileI - 1].GetLength();

szTxt[fileI -1] = new BYTE[nLen];
file[fileI - 1].Read(szTxt[fileI - 1], nLen);
file[fileI - 1].Close();

//BMP bmi;//BITMAPINFO bmi;
//int nHeadLen = sizeof(BMP);
BITMAPFILEHEADER bmpFHeader;
BITMAPINFOHEADER bmpIHeader;
memcpy(&bmpFHeader,szTxt[fileI -1],sizeof(BITMAPFILEHEADER));

int nHeadLen = bmpFHeader.bfOffBits - sizeof(BITMAPFILEHEADER);
memcpy(&bmpIHeader,szTxt[fileI - 1]+sizeof(BITMAPFILEHEADER),nHeadLen);

nWidth = bmpIHeader.biWidth;// 464;// bmi.bmpInfo.bmiHeader.biWidth;// ;
nHeight = bmpIHeader.biHeight;//362;// bmi.bmpInfo.bmiHeader.biHeight;// ;

szTxt[fileI - 1] += bmpFHeader.bfOffBits;
nDataLen = nLen-bmpFHeader.bfOffBits;
}
//avcodec_init();
av_register_all();
avcodec_register_all();
AVFrame *m_pRGBFrame =  new AVFrame[1];  //RGB帧数据  
AVFrame *m_pYUVFrame = new AVFrame[1];;  //YUV帧数据
AVCodecContext *c= NULL;
AVCodecContext *in_c= NULL;
AVCodec *pCodecH264; //编码器
uint8_t * yuv_buff;//

//查找h264编码器
pCodecH264 = avcodec_find_encoder(CODEC_ID_H264);
if(!pCodecH264)
{
fprintf(stderr, "h264 codec not found\n");
exit(1);
}

c= avcodec_alloc_context3(pCodecH264);
c->bit_rate = 3000000;// put sample parameters 
c->width =nWidth;// 
c->height = nHeight;// 

// frames per second 
AVRational rate;
rate.num = 1;
rate.den = 25;
c->time_base= rate;//(AVRational){1,25};
c->gop_size = 10; // emit one intra frame every ten frames 
c->max_b_frames=1;
c->thread_count = 1;
c->pix_fmt = PIX_FMT_YUV420P;//PIX_FMT_RGB24;

//av_opt_set(c->priv_data, /*"preset"*/"libvpx-1080p.ffpreset", /*"slow"*/NULL, 0);
//打开编码器
if(avcodec_open2(c,pCodecH264,NULL)<0)
TRACE("不能打开编码库");

int size = c->width * c->height;

yuv_buff = (uint8_t *) malloc((size * 3) / 2); // size for YUV 420 

//将rgb图像数据填充rgb帧
uint8_t * rgb_buff = new uint8_t[nDataLen];

//图象编码
int outbuf_size=100000;
uint8_t * outbuf= (uint8_t*)malloc(outbuf_size); 
int u_size = 0;
FILE *f=NULL; 
char * filename = "D:\\myData.h264";
f = fopen(filename, "wb");
if (!f)
{
TRACE( "could not open %s\n", filename);
exit(1);
}

//初始化SwsContext
SwsContext * scxt = sws_getContext(c->width,c->height,PIX_FMT_BGR24,c->width,c->height,PIX_FMT_YUV420P,SWS_POINT,NULL,NULL,NULL);

AVPacket avpkt;

//AVFrame *pTFrame=new AVFrame
for (int i=0;i<250;++i)
{

//AVFrame *m_pYUVFrame = new AVFrame[1];

int index = (i / 25) % 5;
memcpy(rgb_buff,szTxt[index],nDataLen);

avpicture_fill((AVPicture*)m_pRGBFrame, (uint8_t*)rgb_buff, PIX_FMT_RGB24, nWidth, nHeight);

//将YUV buffer 填充YUV Frame
avpicture_fill((AVPicture*)m_pYUVFrame, (uint8_t*)yuv_buff, PIX_FMT_YUV420P, nWidth, nHeight);

// 翻转RGB图像
m_pRGBFrame->data[0]  += m_pRGBFrame->linesize[0] * (nHeight - 1);
m_pRGBFrame->linesize[0] *= -1;                   
m_pRGBFrame->data[1]  += m_pRGBFrame->linesize[1] * (nHeight / 2 - 1);
m_pRGBFrame->linesize[1] *= -1;
m_pRGBFrame->data[2]  += m_pRGBFrame->linesize[2] * (nHeight / 2 - 1);
m_pRGBFrame->linesize[2] *= -1;


//将RGB转化为YUV
sws_scale(scxt,m_pRGBFrame->data,m_pRGBFrame->linesize,0,c->height,m_pYUVFrame->data,m_pYUVFrame->linesize);

int got_packet_ptr = 0;
av_init_packet(&avpkt);
avpkt.data = outbuf;
avpkt.size = outbuf_size;
u_size = avcodec_encode_video2(c, &avpkt, m_pYUVFrame, &got_packet_ptr);
if (u_size == 0)
{
fwrite(avpkt.data, 1, avpkt.size, f);
}
}

fclose(f); 
delete []m_pRGBFrame;
delete []m_pYUVFrame;
delete []rgb_buff;
free(outbuf);
avcodec_close(c);
av_free(c);

return 0;
}

#2


严重怀疑你没编译生成release版的dll

#3


引用 2 楼 zhao4zhong1 的回复:
严重怀疑你没编译生成release版的dll


我没有编译啊,我从FFMPEG官网下载的,网站上并没有说这个动态库是debug版本啊
ffmpeg-20140512-git-5460ab7-win32-dev这个名称。
请问ffmpeg官网的编译库可以直接用吗?我自己在windows下编译我谱

#5


引用 4 楼 gpshq 的回复:
http://blog.csdn.net/bing87496988/article/details/25061659


你是神仙吗?

#6


引用 5 楼 u010450027 的回复:
Quote: 引用 4 楼 gpshq 的回复:

http://blog.csdn.net/bing87496988/article/details/25061659


你是神仙吗?

最近也在搞,有机会可以多交流一下。

#7


引用 6 楼 gpshq 的回复:
Quote: 引用 5 楼 u010450027 的回复:

Quote: 引用 4 楼 gpshq 的回复:

http://blog.csdn.net/bing87496988/article/details/25061659


你是神仙吗?

最近也在搞,有机会可以多交流一下。

我会多请叫的,我已经关注你啦,十分感谢,两个礼拜光研究这个问题了,终于解决了很开心

#8


引用 4 楼 gpshq 的回复:
http://blog.csdn.net/bing87496988/article/details/25061659

正解

#1



#include "stdafx.h"
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
};
#include <afx.h>
int _tmain(int argc, _TCHAR* argv[])
{
CFile file[5];
BYTE *szTxt[5];

int nWidth = 0;
int nHeight= 0;

int nDataLen=0;

int nLen;

CString csFileName;
for (int fileI = 1; fileI <= 5; fileI ++)
{
csFileName.Format(_T("D:\\%d.bmp"), fileI);
file[fileI - 1].Open(csFileName,CFile::modeRead | CFile::typeBinary);
nLen = file[fileI - 1].GetLength();

szTxt[fileI -1] = new BYTE[nLen];
file[fileI - 1].Read(szTxt[fileI - 1], nLen);
file[fileI - 1].Close();

//BMP bmi;//BITMAPINFO bmi;
//int nHeadLen = sizeof(BMP);
BITMAPFILEHEADER bmpFHeader;
BITMAPINFOHEADER bmpIHeader;
memcpy(&bmpFHeader,szTxt[fileI -1],sizeof(BITMAPFILEHEADER));

int nHeadLen = bmpFHeader.bfOffBits - sizeof(BITMAPFILEHEADER);
memcpy(&bmpIHeader,szTxt[fileI - 1]+sizeof(BITMAPFILEHEADER),nHeadLen);

nWidth = bmpIHeader.biWidth;// 464;// bmi.bmpInfo.bmiHeader.biWidth;// ;
nHeight = bmpIHeader.biHeight;//362;// bmi.bmpInfo.bmiHeader.biHeight;// ;

szTxt[fileI - 1] += bmpFHeader.bfOffBits;
nDataLen = nLen-bmpFHeader.bfOffBits;
}
//avcodec_init();
av_register_all();
avcodec_register_all();
AVFrame *m_pRGBFrame =  new AVFrame[1];  //RGB帧数据  
AVFrame *m_pYUVFrame = new AVFrame[1];;  //YUV帧数据
AVCodecContext *c= NULL;
AVCodecContext *in_c= NULL;
AVCodec *pCodecH264; //编码器
uint8_t * yuv_buff;//

//查找h264编码器
pCodecH264 = avcodec_find_encoder(CODEC_ID_H264);
if(!pCodecH264)
{
fprintf(stderr, "h264 codec not found\n");
exit(1);
}

c= avcodec_alloc_context3(pCodecH264);
c->bit_rate = 3000000;// put sample parameters 
c->width =nWidth;// 
c->height = nHeight;// 

// frames per second 
AVRational rate;
rate.num = 1;
rate.den = 25;
c->time_base= rate;//(AVRational){1,25};
c->gop_size = 10; // emit one intra frame every ten frames 
c->max_b_frames=1;
c->thread_count = 1;
c->pix_fmt = PIX_FMT_YUV420P;//PIX_FMT_RGB24;

//av_opt_set(c->priv_data, /*"preset"*/"libvpx-1080p.ffpreset", /*"slow"*/NULL, 0);
//打开编码器
if(avcodec_open2(c,pCodecH264,NULL)<0)
TRACE("不能打开编码库");

int size = c->width * c->height;

yuv_buff = (uint8_t *) malloc((size * 3) / 2); // size for YUV 420 

//将rgb图像数据填充rgb帧
uint8_t * rgb_buff = new uint8_t[nDataLen];

//图象编码
int outbuf_size=100000;
uint8_t * outbuf= (uint8_t*)malloc(outbuf_size); 
int u_size = 0;
FILE *f=NULL; 
char * filename = "D:\\myData.h264";
f = fopen(filename, "wb");
if (!f)
{
TRACE( "could not open %s\n", filename);
exit(1);
}

//初始化SwsContext
SwsContext * scxt = sws_getContext(c->width,c->height,PIX_FMT_BGR24,c->width,c->height,PIX_FMT_YUV420P,SWS_POINT,NULL,NULL,NULL);

AVPacket avpkt;

//AVFrame *pTFrame=new AVFrame
for (int i=0;i<250;++i)
{

//AVFrame *m_pYUVFrame = new AVFrame[1];

int index = (i / 25) % 5;
memcpy(rgb_buff,szTxt[index],nDataLen);

avpicture_fill((AVPicture*)m_pRGBFrame, (uint8_t*)rgb_buff, PIX_FMT_RGB24, nWidth, nHeight);

//将YUV buffer 填充YUV Frame
avpicture_fill((AVPicture*)m_pYUVFrame, (uint8_t*)yuv_buff, PIX_FMT_YUV420P, nWidth, nHeight);

// 翻转RGB图像
m_pRGBFrame->data[0]  += m_pRGBFrame->linesize[0] * (nHeight - 1);
m_pRGBFrame->linesize[0] *= -1;                   
m_pRGBFrame->data[1]  += m_pRGBFrame->linesize[1] * (nHeight / 2 - 1);
m_pRGBFrame->linesize[1] *= -1;
m_pRGBFrame->data[2]  += m_pRGBFrame->linesize[2] * (nHeight / 2 - 1);
m_pRGBFrame->linesize[2] *= -1;


//将RGB转化为YUV
sws_scale(scxt,m_pRGBFrame->data,m_pRGBFrame->linesize,0,c->height,m_pYUVFrame->data,m_pYUVFrame->linesize);

int got_packet_ptr = 0;
av_init_packet(&avpkt);
avpkt.data = outbuf;
avpkt.size = outbuf_size;
u_size = avcodec_encode_video2(c, &avpkt, m_pYUVFrame, &got_packet_ptr);
if (u_size == 0)
{
fwrite(avpkt.data, 1, avpkt.size, f);
}
}

fclose(f); 
delete []m_pRGBFrame;
delete []m_pYUVFrame;
delete []rgb_buff;
free(outbuf);
avcodec_close(c);
av_free(c);

return 0;
}

#2


严重怀疑你没编译生成release版的dll

#3


引用 2 楼 zhao4zhong1 的回复:
严重怀疑你没编译生成release版的dll


我没有编译啊,我从FFMPEG官网下载的,网站上并没有说这个动态库是debug版本啊
ffmpeg-20140512-git-5460ab7-win32-dev这个名称。
请问ffmpeg官网的编译库可以直接用吗?我自己在windows下编译我谱

#4


#5


引用 4 楼 gpshq 的回复:
http://blog.csdn.net/bing87496988/article/details/25061659


你是神仙吗?

#6


引用 5 楼 u010450027 的回复:
Quote: 引用 4 楼 gpshq 的回复:

http://blog.csdn.net/bing87496988/article/details/25061659


你是神仙吗?

最近也在搞,有机会可以多交流一下。

#7


引用 6 楼 gpshq 的回复:
Quote: 引用 5 楼 u010450027 的回复:

Quote: 引用 4 楼 gpshq 的回复:

http://blog.csdn.net/bing87496988/article/details/25061659


你是神仙吗?

最近也在搞,有机会可以多交流一下。

我会多请叫的,我已经关注你啦,十分感谢,两个礼拜光研究这个问题了,终于解决了很开心

#8


引用 4 楼 gpshq 的回复:
http://blog.csdn.net/bing87496988/article/details/25061659

正解