opencv的highgui显示ffmpeg的数据
来源:互联网 发布:c语言常用函数大全 编辑:程序博客网 时间:2024/05/18 00:04
ffmpeg是一个强大的开源的编解码用的库,功能及其强大,但是由于其官方的文档少的可怜,例子少的可怜十分不利于普通初学者学习。我有opencv的基础,opencv的highgui做的界面虽然简单,但是代码也简单。在我不断的探索下,终于可以使用opencv的界面来显示ffmpeg的处理结果了。
下面的ffmpeg代码是参考:http://blog.csdn.net/jia_zhengshen/article/details/10334313来写的,opencv部分有注释。
但是注意程序没有进行内存的清理,所以嘛,如果影片的很大的话,哈哈,你的内存完蛋了。
http://abowman-dog-gadget.googlecode.com/svn/trunk/dog.swf
#include<opencv\cv.h>#include<opencv\highgui.h>#ifdef __cplusplus extern "C" { #endif #include<avcodec.h>#include<avformat.h>#include<libswscale\swscale.h>int main(){IplImage *img ;//= cvCreateImage(av_register_all();avcodec_register_all();avformat_network_init();AVFormatContext *pFormatCtx = NULL;char *filename = "test.flv";if( avformat_open_input(&pFormatCtx,filename,NULL,NULL) !=0)return 1;if( av_find_stream_info(pFormatCtx) <0)return 2;av_dump_format(pFormatCtx,0,filename,0);AVCodecContext *pCodecCtx;int i=-1;int videoStream =-1;for(i=0;i<pFormatCtx->nb_streams;i++){if(pFormatCtx->streams[i]->codec->codec_type== AVMEDIA_TYPE_VIDEO){videoStream = i;break;}}//forif(videoStream ==-1){return 3;}pCodecCtx= pFormatCtx->streams[videoStream]->codec;AVCodec *pCodec ;pCodec = avcodec_find_decoder(pCodecCtx->codec_id);if(pCodec ==NULL)return 4;if(avcodec_open(pCodecCtx,pCodec)<0)return 5;AVFrame *pFrame ;pFrame = avcodec_alloc_frame();AVFrame *pFrameRGB;pFrameRGB= avcodec_alloc_frame();uint8_t *buffer ;int numBytes;numBytes = avpicture_get_size(PIX_FMT_RGB24,pCodecCtx->width,pCodecCtx->height);buffer = (uint8_t *)av_malloc(numBytes*sizeof(char) );avpicture_fill((AVPicture *)pFrameRGB,buffer,PIX_FMT_RGB24,pCodecCtx->width,pCodecCtx->height);int frameFinished;AVPacket packet;i=0;while(av_read_frame(pFormatCtx,&packet)>=0 ){if(packet.stream_index == videoStream ){avcodec_decode_video2(pCodecCtx,pFrame,&frameFinished,&packet);if(frameFinished){SwsContext *pSwsCtx;pSwsCtx = sws_getContext(pCodecCtx->width,pCodecCtx->height,pCodecCtx->pix_fmt,pCodecCtx->width,pCodecCtx->height,AV_PIX_FMT_BGR24,SWS_POINT,NULL,NULL,NULL);sws_scale(pSwsCtx,pFrame->data,pFrame->linesize,0,pCodecCtx->height,pFrameRGB->data,pFrameRGB->linesize);//ffmpeg的从yuv420格式转换到bgr24格式。int w = pCodecCtx->width;int h = pCodecCtx->height;img = cvCreateImageHeader(cvSize(w,h),8,3);img->imageData =(char *)(*( pFrameRGB->data) );//把ffmpeg格式转换到opencv的bgr格式。cvShowImage("img",img);IplImage *imgbgr = cvCreateImage(cvSize(w,h),8,3);//cvCvtColor(img,imgbgr,CV_RGB2BGR);cvCvtColor(img,imgbgr,CV_BGR2HSV);cvShowImage("HSV",imgbgr);cvWaitKey(2);}//得到了一帧frame}//video}//whileprintf("tttttt");}#ifdef __cplusplus } #endif
- opencv的highgui显示ffmpeg的数据
- opencv:简单的HighGui
- 用opencv的highgui要小心
- OpenCV学习笔记---HighGUI的初步
- qt5.7+opencv的一个小坑 highgui
- OpenCV--HighGUI视频读写和显示
- HighGUI的初步认识
- highgui的拓展
- FFmpeg中数据与OpenCV中Mat数据的转换
- opencv c++函数 highgui模块 2 OpenCV的视频输入和相似度测量
- Opencv HighGUI函数_载入,保存,显示图像
- OPENCV的highgui工程在vc6.0下编译出错的解决
- OPENCV的highgui工程在vc6.0下编译出错的解决
- 由opencv with qt的imshow源码的一部分联想到在arm上实现highgui
- ffmpeg解码+opencv显示
- 【Ubuntu+OpenCV】HighGUI之trackbar(滑动条)的创建--学习笔记【2】
- 学习OpenCV——去除imshow的内部细小边框(修改highgui)
- OpenCV库highgui函数在VS2012下的内存泄露问题!
- hdoj 4714 将树转换为环
- ios开发 把视频文件和图片保存到相册
- c#图片比对
- 开源手游暗黑世界客户端部分代码注解续
- Json,Gson,FastJson解析笔记
- opencv的highgui显示ffmpeg的数据
- Java对象创建与销毁
- ABAP屏幕开发 - 设计折叠样式的屏幕(类似MIGO或ME23N的屏幕)
- WebService知识点总结
- 摄像头输出格式
- 计算机学科导论-2013级教学材料
- RMAN Crosscheck 和 Delete 命令的2个实例
- Archlinux2013-07没有/arch/setup的AIF,新安装方式。
- C# ActiveX 开发时反序列化化提示找不到DLL解决方法