FFmpeg学习起步 您所在的位置:网站首页 摩斯电码学习 FFmpeg学习起步

FFmpeg学习起步

2024-02-03 03:33| 来源: 网络整理| 查看: 265

 

下面是我搭建FFmpeg学习环境的步骤。

一、在Ubuntu下

从http://www.ffmpeg.org/download.html下载最新的FFmpeg版本,我的版本是ffmpeg-2.7.2。

编译:

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中可以看到将动态库和静态库安装到什么位置了:

# 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下。

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 #include int main(int argc, const char *argv[]) { printf("%s\n", avcodec_configuration()); return 0; } 1、动态库

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 2、静态库

现将/usr/local/lib下的动态库移动到其他位置,Makefile的内容如下:

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

 

二、在wind7下

在win7下使用的开发工具VS2013,我的win7是64位的。

可以从http://ffmpeg.zeranoe.com/builds/下载需要的动态库和静态库,这里需要注意的是32位和64位要搞清楚。

1、32位

下载如果所示的两个,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\n%s", avcodec_configuration()); return 0; }

 

运行

点击 调试 ---> 开始执行(不调试) 或者 Ctrl + F5

2、64位

下面是用到的两个下载包:

ffmpeg-20151231-git-4160900-win64-dev.7z

ffmpeg-20151231-git-4160900-win64-shared.7z

 

配置方法与32位类似,不同的是建立的工程需要是x64位的,同时再将用到的动态库拷贝到 C:\Windows\system 下。

 

完。

本文来自博客园,作者:摩斯电码,未经同意,禁止转载



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有