Windows下搭建ffmpeg+VS2008开发环境详细教程【转】
本文转载自:http://www.voidcn.com/article/p-vxdntdgc-bkq.html
由于个人是从事音视频开发相关的工作,所以也把自己的一些过程写下来,方便大家以及自己查看,时间关系就不多瞎说了,具体过程,都是图文教程







遇到问题:
1.编译失败,
Error 1 error LNK2019: unresolved external symbol _av_register_all referenced in function _wmain C:\Users\Andres\Documents\Visual Studio 2013\Projects\PruebaFFMPEG\PruebaFFMPEG\PruebaFFMPEG.obj PruebaFFMPEG
除了要查明c++引用C文件的文件名有变化失败,还要检查
0 down vote accepted
|
It seems that you are trying to link a 32-bit application with 64-bit libraries. Download 32-bit libraries from http://ffmpeg.zeranoe.com/builds/ or create x64 configuration for your solution |
Open Project properties -> click Configuration Manager... -> Active Solution Platform -> New.. -> Select x64 (see screenshot goo.gl/54ND5t) – pogorskiy
2.缺少的头文件
Ffmpeg使用的是C99,但是vs2008不支持c99。在VS2008编译ffmpeg时会用到的两个C99标准的头文件。,所以需要你自己下载。并放至相应目录。对于VS2010来说通常是:C:\ProgramFiles (x86)\Microsoft Visual Studio10.0\VC\include。下载地址:http://download.csdn.net/detail/mfcai_blog/9540995
在cpp文件里调用ffmpeg函数要注意.extern“C”是使C++能够调用C写的库文件的一种方式。如果在c++代码中要使用C库中的函数的话,那么就要使用extern”C”来说明。
一个用C写成的库如果想被C/C++同时可以使用,那在头文件应该加上
#ifdef__cplusplus
extern "C"{
#endif
#ifdef__cplusplus
} // endof extern"C"
#endif
3.
VS2008下配置SDL开发环境:
1.下载SDL-devel-1.2.15-VC.zip(在http://www.libsdl.org/download-1.2.php可见)
2.解压缩SDL-devel-1.2.13-VC8.zip,docs里面包含了官方文档,这将是你学习SDL的主要参考资料。找到你在硬盘上安装VC的位置,类似:C:\Program Files\Microsoft Visual Studio 9.0\VC,打开include文件夹,在里面建立一个新文件夹,取名为SDL,打开这个新的文件夹:C:\Program Files\Microsoft Visual Studio 9.0\VC\include\SDL,然后,将SDL Development Libraries中include文件夹里面的文件全部拷贝到刚才建立起来的那个新文件夹中。
然后,回到VC的.\VC文件夹下,打开lib文件夹:C:\Program Files\Microsoft Visual Studio 9.0\VC\lib,将SDL Development Libraries中lib文件夹下的SDL.lib和SDLmain.lib两个文件拷贝到刚才的那个VC的lib文件夹下
(注意库可以这么取,但是位置不要这么放,要像上面放置ffmpeg库那样去配置)
4.代码示例
#include <stdafx.h> #include <stdio.h> #define __STDC_CONSTANT_MACROS extern "C" { #include "libavcodec/avcodec.h" #include "libavformat/avformat.h" #include "libswscale/swscale.h" #include "libavutil/imgutils.h" }; #include "SDL_include/SDL.h" //Refresh Event #define SFM_REFRESH_EVENT (SDL_USEREVENT + 1) #define SFM_BREAK_EVENT (SDL_USEREVENT + 2) int thread_exit=0; int thread_pause=0; int sfp_refresh_thread(void *opaque){ thread_exit=0; thread_pause=0; while (!thread_exit) { if(!thread_pause){ SDL_Event event; event.type = SFM_REFRESH_EVENT; SDL_PushEvent(&event); } SDL_Delay(40); } thread_exit=0; thread_pause=0; //Break SDL_Event event; event.type = SFM_BREAK_EVENT; SDL_PushEvent(&event); return 0; } int main(int argc, char* argv[]) { AVFormatContext *pFormatCtx; int i, videoindex; AVCodecContext *pCodecCtx; AVCodec *pCodec; AVFrame *pFrame,*pFrameYUV; unsigned char *out_buffer; AVPacket *packet; int ret, got_picture; //------------SDL---------------- int screen_w,screen_h; SDL_Window *screen; SDL_Renderer* sdlRenderer; SDL_Texture* sdlTexture; SDL_Rect sdlRect; SDL_Thread *video_tid; SDL_Event event; struct SwsContext *img_convert_ctx; //char filepath[]="bigbuckbunny_480x272.h265"; char filepath[]="bigbuckbunny_480x272.h264"; av_register_all(); avformat_network_init(); pFormatCtx = avformat_alloc_context(); if(avformat_open_input(&pFormatCtx,filepath,NULL,NULL)!=0){ printf("Couldn't open input stream.\n"); return -1; } if(avformat_find_stream_info(pFormatCtx,NULL)<0){ printf("Couldn't find stream information.\n"); return -1; } videoindex=-1; for(i=0; i<pFormatCtx->nb_streams; i++) if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){ videoindex=i; break; } if(videoindex==-1){ printf("Didn't find a video stream.\n"); return -1; } pCodecCtx=pFormatCtx->streams[videoindex]->codec; pCodec=avcodec_find_decoder(pCodecCtx->codec_id); if(pCodec==NULL){ printf("Codec not found.\n"); return -1; } if(avcodec_open2(pCodecCtx, pCodec,NULL)<0){ printf("Could not open codec.\n"); return -1; } pFrame=av_frame_alloc(); pFrameYUV=av_frame_alloc(); out_buffer=(unsigned char *)av_malloc(av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height,1)); av_image_fill_arrays(pFrameYUV->data, pFrameYUV->linesize,out_buffer, AV_PIX_FMT_YUV420P,pCodecCtx->width, pCodecCtx->height,1); //Output Info----------------------------- printf("---------------- File Information ---------------\n"); av_dump_format(pFormatCtx,0,filepath,0); printf("-------------------------------------------------\n"); img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { printf( "Could not initialize SDL - %s\n", SDL_GetError()); return -1; } //SDL 2.0 Support for multiple windows screen_w = pCodecCtx->width; screen_h = pCodecCtx->height; screen = SDL_CreateWindow("Simplest ffmpeg player's Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_w, screen_h,SDL_WINDOW_OPENGL); if(!screen) { printf("SDL: could not create window - exiting:%s\n",SDL_GetError()); return -1; } sdlRenderer = SDL_CreateRenderer(screen, -1, 0); //IYUV: Y + U + V (3 planes) //YV12: Y + V + U (3 planes) sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING,pCodecCtx->width,pCodecCtx->height); sdlRect.x=0; sdlRect.y=0; sdlRect.w=screen_w; sdlRect.h=screen_h; packet=(AVPacket *)av_malloc(sizeof(AVPacket)); video_tid = SDL_CreateThread(sfp_refresh_thread,NULL,NULL); //------------SDL End------------ //Event Loop for (;;) { //Wait SDL_WaitEvent(&event); if(event.type==SFM_REFRESH_EVENT){ while(1){ if(av_read_frame(pFormatCtx, packet)<0) thread_exit=1; if(packet->stream_index==videoindex) break; } ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet); if(ret < 0){ printf("Decode Error.\n"); return -1; } if(got_picture){ sws_scale(img_convert_ctx, (const unsigned char* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize); //SDL--------------------------- SDL_UpdateTexture( sdlTexture, NULL, pFrameYUV->data[0], pFrameYUV->linesize[0] ); SDL_RenderClear( sdlRenderer ); //SDL_RenderCopy( sdlRenderer, sdlTexture, &sdlRect, &sdlRect ); SDL_RenderCopy( sdlRenderer, sdlTexture, NULL, NULL); SDL_RenderPresent( sdlRenderer ); //SDL End----------------------- } av_free_packet(packet); }else if(event.type==SDL_KEYDOWN){ //Pause if(event.key.keysym.sym==SDLK_SPACE) thread_pause=!thread_pause; }else if(event.type==SDL_QUIT){ thread_exit=1; }else if(event.type==SFM_BREAK_EVENT){ break; } } sws_freeContext(img_convert_ctx); SDL_Quit(); //-------------- av_frame_free(&pFrameYUV); av_frame_free(&pFrame); avcodec_close(pCodecCtx); avformat_close_input(&pFormatCtx); return 0; }
Windows下搭建ffmpeg+VS2008开发环境详细教程【转】的更多相关文章
- Windows下搭建objective C开发环境
摘自:http://blog.csdn.net/zhanghefu/article/details/18320827 最近打算针对iPhone.iPod touch和iPad开发一些应用,所以,需要开 ...
- Windows下搭建Spark+Hadoop开发环境
Windows下搭建Spark+Hadoop开发环境需要一些工具支持. 只需要确保您的电脑已装好Java环境,那么就可以开始了. 一. 准备工作 1. 下载Hadoop2.7.1版本(写Spark和H ...
- windows下搭建nginx+php开发环境
windows下搭建nginx+php开发环境 1.前言 windows下大多我们都是下载使用集成环境,但是本地已经存在一个集成环境,但不适合项目的需求.因此准备再自己搭建一个环境. 2.准备 工具: ...
- 【RN - 基础】之Windows下搭建React Native开发环境
前言 React Native由Facebook公司于2015年F8大会上开源,其主张“Learn once, write everywhere”.React Native的核心设计理念是:既拥有Na ...
- Windows下搭建Android NDK开发环境及命令行编译
首先说明本文内的相关安装操作参考<Pro Android C++ with the NDK>一书. 安装 Windows搭建Android NDK开发环境需要安装如下部分(同时需要配置对应 ...
- WINDOWS 下搭建 OC 集成开发环境
Objective-C是苹果软件的编程语言,想要上机学习.调试,有一个集成开发环境(IDE)方便很多.有三类方法搭建Objective-C的集成开发环境: 1) 使用苹果的平台,集成开发环境使用X ...
- C++开发安卓、windows下搭建Android NDK开发环境
1. NDK(Native Development Kit) 1.1 NDK简介 Android NDK是一套允许开发人员使用本地代码(如C/C++)进行Android APP功能开发的工具,通过这个 ...
- windows下搭建spark+python 开发环境
有时候我们会在windows 下开发spark程序,测试程序运行情况,再部署到真实服务器中运行. 那么本文介绍如何在windows 环境中搭建简单的基于hadoop 的spark 环境. 我的wind ...
- Windows下搭建go语言开发环境 以及 开发IDE (附下载链接)
1.下载 并且 安装 Go安装包 =========================================================== 在CSDN上传了我的版本,供大家下载: = ...
随机推荐
- 5.7 Liquibase:与具体数据库独立的追踪、管理和应用数据库Scheme变化的工具。-mybatis-generator将数据库表反向生成对应的实体类及基于mybatis的mapper接口和xml映射文件(类似代码生成器)
一. liquibase 使用说明 功能概述:通过xml文件规范化维护数据库表结构及初始化数据. 1.配置不同环境下的数据库信息 (1)创建不同环境的数据库. (2)在resource/liquiba ...
- java线程中断
public void Thread.interrupt() // 无返回值 public boolean Thread.isInterrupted() // 有返回值 public static b ...
- P1146 硬币翻转
题目描述 在桌面上有一排硬币,共N枚,每一枚硬币均为正面朝上.现在要把所有的硬币翻转成反面朝上,规则是每次可翻转任意N-1枚硬币(正面向上的被翻转为反面向上,反之亦然).求一个最短的操作序列(将每次翻 ...
- iis 7.5 ftp site用户名不能是 'ftp'?
在windows server 2008 r2上配置一个iis ftp site,创建了一个名为 ftp 的账号,并添加到允许规则中,可总是出现: Connected to ***.***.***.* ...
- 45.4.7 序列:USER_SEQUENCES(SEQ)
45.4.7 序列:USER_SEQUENCES(SEQ) 要显示序列的属性,可以查询USER_SEQUENCES 数据字典视图.该视图也能用公有同义词SEQ 进行查询.USER_SEQUENCES ...
- Visual Studio UI Automation 学习(二)
今天恰好有时间,继续学习了一下UI Automation的知识.看了两篇博客,对UI Automation有了进一步的了解. https://blog.csdn.net/qq_37546891/art ...
- appium处理app与web页面的转换
测微信页面的时候使用谷歌app,进入微信页面的链接 def setUp(self): print("set up env for android testing...") se ...
- 【Web缓存机制系列】2 – Web浏览器的缓存机制-(新鲜度 校验值)
Web缓存的工作原理 所有的缓存都是基于一套规则来帮助他们决定什么时候使用缓存中的副本提供服务(假设有副本可用的情况下,未被销毁回收或者未被删除修改).这些规则有的在协议中有定义(如HTTP协议1.0 ...
- react-native 横向滚动的商品展示
在app中会有这种页面 像这样商品是横向的,而且要滚动,思路是利用 ScrollView 横向的滚动 思路: (a): 横向滚动的整体作为一个组件 ShopCenter {/*** 横向滚动 *** ...
- BZOJ 3036: 绿豆蛙的归宿 期望 + 拓扑排序
随着新版百度空间的下线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿.给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度.绿豆蛙从起点出发,走向终点. 到达每一个顶点时,如果有K条离 ...