下面是我搭建FFmpeg学习环境的步骤。html
从http://www.ffmpeg.org/download.html下载最新的FFmpeg版本,个人版本是ffmpeg-2.7.2。
python
编译:linux
tar -xf ffmpeg-2.7.2.tar.bz2 mkdir build cd build/ ../ffmpeg-2.7.2/configure --enable-shared make sudo make install
在build/config.mak中能够看到将动态库和静态库安装到什么位置了:git
# Automatically generated by configure - do not modify! ifndef FFMPEG_CONFIG_MAK FFMPEG_CONFIG_MAK=1 FFMPEG_CONFIGURATION= --enable-shared prefix=/usr/local LIBDIR=$(DESTDIR)${prefix}/lib SHLIBDIR=$(DESTDIR)${prefix}/lib INCDIR=$(DESTDIR)${prefix}/include BINDIR=$(DESTDIR)${prefix}/bin DATADIR=$(DESTDIR)${prefix}/share/ffmpeg DOCDIR=$(DESTDIR)${prefix}/share/doc/ffmpeg MANDIR=$(DESTDIR)${prefix}/share/man PKGCONFIGDIR=$(DESTDIR)${prefix}/lib/pkgconfig SRC_PATH=/home/pengdl/work/study/FFmpeg/ffmpeg-2.7.2 ... ...
能够看到,拷贝到了/usr/local/lib下。api
ls /usr/local/lib icu libavdevice.a libavfilter.so.5 libavutil.a libswresample.so.1 ocaml tmp lib64OpenglRender.so libavdevice.so libavfilter.so.5.16.101 libavutil.so libswresample.so.1.2.100 openssl libavcodec.a libavdevice.so.56 libavformat.a libavutil.so.54 libswscale.a p4v libavcodec.so libavdevice.so.56.4.100 libavformat.so libavutil.so.54.27.100 libswscale.so pkgconfig libavcodec.so.56 libavfilter.a libavformat.so.56 libswresample.a libswscale.so.3 python2.7 libavcodec.so.56.41.100 libavfilter.so libavformat.so.56.36.100 libswresample.so libswscale.so.3.1.101 python3.4
下面写个简单的测试程序,分别用静态库和动态库测试,两者的区别主要在Makefile上。工具
测试文件 demo.c学习
#include <stdio.h> #include <libavcodec/avcodec.h>
int main(int argc, const char *argv[]) { printf("%s\n", avcodec_configuration()); return 0; }
Makefile的内容以下:开发工具
LIBS_DIR=-L/usr/local/lib LIBS=-lavcodec LIBS+=-lavfilter LIBS+=-lavdevice LIBS+=-lswresample LIBS+=-lswscale LIBS+=-lavformat LIBS+=-lavutil INC=-I/usr/local/include INC+=-I/usr/local/include/libavcodec INC+=-I/usr/local/include/libavdevice INC+=-I/usr/local/include/libavfilter INC+=-I/usr/local/include/libavformat INC+=-I/usr/local/include/libavutil INC+=-I/usr/local/include/libswresample INC+=-I/usr/local/include/libswscale demo:demo.o gcc demo.o -o $@ $(LIBS_DIR) $(LIBS) demo.o:demo.c gcc $(INC) -c $^ -o $@ clean: rm demo
运行:测试
ls -lh demo -rwxrwxr-x 1 pengdl pengdl 8.5K 12月 31 16:11 demo ./demo --arch=amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version='6:11-1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --disable-avserver --enable-bzlib --enable-libdc1394 --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
现将/usr/local/lib下的动态库移动到其余位置,Makefile的内容以下:ui
LIBS_DIR=-L/usr/local/lib LIBS=-lavcodec LIBS+=-lavfilter LIBS+=-lavdevice LIBS+=-lswresample LIBS+=-lswscale LIBS+=-lavformat LIBS+=-lavutil LIBS+=-lpthread LIBS+=-lm INC=-I/usr/local/include INC+=-I/usr/local/include/libavcodec INC+=-I/usr/local/include/libavdevice INC+=-I/usr/local/include/libavfilter INC+=-I/usr/local/include/libavformat INC+=-I/usr/local/include/libavutil INC+=-I/usr/local/include/libswresample INC+=-I/usr/local/include/libswscale demo:demo.o gcc demo.o -o $@ $(LIBS_DIR) $(LIBS) demo.o:demo.c gcc $(INC) -c $^ -o $@ clean: rm demo
注意,其中静态库的顺序若是排列有问题,会致使编译错误,如将libavutil放在libavcodec的前面,就会致使编译错误。
运行:
ls -lh demo -rwxrwxr-x 1 pengdl pengdl 3.8M 12月 31 16:08 demo pengdl@pengdl-HP:~/work/study/FFmpeg/FFmpeg/demo$ ./demo --enable-shared
在win7下使用的开发工具VS2013,个人win7是64位的。
能够从http://ffmpeg.zeranoe.com/builds/下载须要的动态库和静态库,这里须要注意的是32位和64位要搞清楚。
下载若是所示的两个,shared的下载包里有ffmpeg的动态库,dev的下载包里有静态库。
ffmpeg-20151231-git-4160900-win32-dev.7z
ffmpeg-20151231-git-4160900-win32-shared.7z
打开vs2013,新建一个控制台应用程序,将shared包里bin目录下的动态库拷贝到C:\Windows\system下,以下图:
将dev下的lib和include拷贝到工程目录下,以下图:
右击工程名,选择属性,做以下设置:
1. C/C++ --> 附加包含目录 ---> 设置为include 或者设置为include的绝对路径 E:\VC++\FFmpeg\testFFmpeg_32\testFFmpeg\include
2. 连接器 --> 常规 ---> 附加库目录 ---> 设置为lib 或者 设置为lib的绝对路径 E:\VC++\FFmpeg\testFFmpeg_32\testFFmpeg\lib
3. 连接器 --> 输入 ---> 附加依赖项 ---> 设置为刚才添加的静态库
点击肯定。
测试程序 testFFmpeg.cpp :
#include "stdafx.h"
//Windows
extern "C" { #include "libavcodec/avcodec.h" }; int _tmain(int argc, _TCHAR* argv[]) { printf("\n<<Configuration>>\n%s", avcodec_configuration()); return 0; }
运行
点击 调试 ---> 开始执行(不调试) 或者 Ctrl + F5
下面是用到的两个下载包:
ffmpeg-20151231-git-4160900-win64-dev.7z
ffmpeg-20151231-git-4160900-win64-shared.7z
配置方法与32位相似,不一样的是创建的工程须要是x64位的,同时再将用到的动态库拷贝到 C:\Windows\system 下。
完。