ffmpeg解码 内存增加,该如何解决
发布时间:2011-06-27 19:30:56 文章来源:www.iduyao.cn 采编人员:星星草
ffmpeg解码 内存增加
void main()
{
av_register_all();//注册库中所有可能有用的文件格式和编码器
testff();
testff();//每重新调用一次,内存增加
testff();
}
void testff()
{
const char *filename="test.264";
AVFormatContext *ic;
// ic=av_alloc_format_context();
//打开文件
if (av_open_input_file(&ic,filename,NULL,0,NULL)!=0)
{
printf("can not open file%s\n",filename);
exit(1);
}
//取出流信息
if (av_find_stream_info(ic)<0)
{
printf("can not find suitable codec parameters\n");
exit(1);
}
int i;
int videoindex=-1;
for (i=0;i<ic->nb_streams;i++)
{
if (ic->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
{
videoindex=i;
}
}
if (videoindex==-1)
{
printf("can not find video stream\n");
exit(1);
}
AVCodecContext *vCodeCtx;
vCodeCtx=ic->streams[videoindex]->codec;//取得视频编码的上下文指针
AVCodec *vCodec;
vCodec=avcodec_find_decoder(vCodeCtx->codec_id);//寻找合适编码器
if (vCodec==NULL)
{
printf("cannot find suitable video decoder\n");
exit(1);
}
//打开该视频编码器
if (avcodec_open(vCodeCtx,vCodec)<0)
{
printf("cannot open the video decoder\n");
exit(1);
}
AVPacket pack;
int frameFinished;
int len;
int ret;
//////////////////////////////////////////////////////////////////////////
// Allocate an AVFrame structure
AVFrame *pFrameRGB=avcodec_alloc_frame();
AVFrame *pFrameEnc= avcodec_alloc_frame();
if(pFrameRGB==NULL)
return -1;
// Determine required buffer size and allocate buffer
int numBytes=avpicture_get_size(PIX_FMT_RGB24, vCodeCtx->width,vCodeCtx->height);
unsigned char* bufferRGB=(unsigned char *)malloc(numBytes);
// Assign appropriate parts of buffer to image planes i n pFrameRGB
avpicture_fill((AVPicture *)pFrameRGB, bufferRGB, PIX_FMT_RGB24,
vCodeCtx->width, vCodeCtx->height);
i=0;
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//读取输入视频,进行处理
/////////////////////////////////////////////////////////////////////////////////////////////////////////
while (av_read_frame(ic,&pack)>=0)//从输入文件读取一个包
{
if (pack.stream_index==videoindex)//判断是否为当前视频流中的包
{
len=avcodec_decode_video(vCodeCtx,pFrameEnc,&frameFinished,pack.data,pack.size);
if (len<0)
{
printf("error while decoding\n");
exit(0);
}
if (frameFinished)
{
// encode the image
// Convert the image into YUV format that SDL uses
static struct SwsContext *img_convert_ctx;
if(img_convert_ctx == NULL)
{
int w = vCodeCtx->width;
int h = vCodeCtx->height;
img_convert_ctx = sws_getContext(w, h,
vCodeCtx->pix_fmt,
w, h, PIX_FMT_RGB24, SWS_BICUBIC,
NULL, NULL, NULL);
if(img_convert_ctx == NULL)
{
fprintf(stderr, "Cannot initialize the conversion context!\n");
exit(1);
}
}
int ret = sws_scale(img_convert_ctx, pFrameEnc->data, pFrameEnc->linesize, 0,
vCodeCtx->height, pFrameRGB->data, pFrameRGB->linesize);
#if 0 // this use to be true, as of 1/2009, but apparently it is no longer true in 3/2009
if(ret) {
fprintf(stderr, "SWS_Scale failed [%d]!\n", ret);
continue;
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
DSHOW push
推模式,ConnectDirect 的,为什么我一直反回错误
下级级用的是HAALI的一个东西,用CMemStream拉模式的时候是可以连接的
...
-
ffmpeg编码后视频速度不正确,质量也不好,求助,求助,求助,求助啊
对采集到得摄像头图像进行编码保存,发现得到的视频质量不好,而且速度不...
-
请问怎么在live555中接收jpeg
请问,我现在想接收一个服务器发送的jpeg 不知道怎么用live555做一个客户端, 接收它并显示。
请问应...
-
XP SP3 YUV420 的fiter依赖 在线等答案……
链接时媒体类型为WMMEDIASUBTYPE_I420
有的XP可以播放出来
有的就不行,请问不能播放...
-
如何获取通过麦克风来获取当前说话的音量?
使用Wave系统API采集音频输入的数据,当数据缓存区满了后,收到消息取得数据后,如何根据这里...
-
RFC3984 有没有完整的中文版本呢?
搜了几个 都是一半英文一半中文的。哎 郁闷!
------解决方案--------------------
英文的凑合...
-
介绍一个学习directshow和com、atl技术的网站
有一个学习directshow和com、atl技术的网站,还可以下视频教程,共享给大家: http://www...
-
攻击帖:jrtplib、live555是个垃圾,刚开始搞流媒体就用这玩意就是找s
不解释~
来丢我砖头吧~~
我分太多了用不完~ 支持的散分~~~
...
-
50分,寻找《Visual C++音频/视频处理技术及工程实践》的随书光盘?
急于使用其中的几个例程。若哪位好心人能够提供,非常感谢!!我的QQ:52...
-
h264的高宽比怎么获取?
我看标准里面只有样点的高宽比啊。
还有,bit rate可以读出来吗?
------解决方案--------------------
是要...