安装ffmpeg
本来我打算把进行ffmpeg交叉编译的,不过在交叉编译之前我想先在linux的pc机下把ffmpeg研究透,然后进行交叉编译到arm开发板上就不会手忙脚乱了。这里我主要做的工作是在pc linux下编译ffmpeg源码。
当然我也参考了网上的博客,我主要参考了下面两篇博客:
http://apipi.blog.163.com/blog/static/422663812008101821050402/
http://yezi.iteye.com/blog/139399
编译环境: Wmvare6.5+Fedora14
编译器: gcc 4.5.1
安装包及其版本(感觉有些安装了最后没起作用):
yasm-1.2.0.tar.gz
lame-3.99.5.tar.gz
libogg-1.1.3.tar.gz
libvorbis-1.1.2.tar.gz
x264-snapshot-20070913-2245.tar.bz2
xvidcore-1.1.3.tar.gz
libdts-0.0.2.tar.gz
a52dec-0.7.4.tar.gz
faad2-2.7.tar.gz
faac-1.28.tar.gz
amrnb-6.1.0.4.tar.bz2
amrwb-7.0.0.1.tar.bz2
26104-610.zip
26204-710.zip
1、安装MP3音频编码器,文件包lame-3.99.5.tar.gz
root@localhost ffmpeg]# tar zxvf lame-3.99.5.tar.gz ; rm -rf lame-3.99.5.tar.gz
[root@localhost ffmpeg]# cd lame-3.99.5
[root@localhost lame-3.99.5]# ./configure —enable-shared —prefix=/usr
[root@localhost lame-3.99.5]# make
[root@localhost lame-3.99.5]# make install
2、安装汇编优化器yasm-0.7.2.tar.gz,可能安装x264要用到
[root@localhost lame-3.99.5]# cd ..
[root@localhost ffmpeg]# tar zxvf yasm-0.7.2.tar.gz ; rm -rf yasm-0.7.2.tar.gz
[root@localhost ffmpeg]# cd yasm-0.7.2
[root@localhost yasm-0.7.2]# ./configure —prefix=/uar —enable-shared
[root@localhost yasm-0.7.2]# make
[root@localhost yasm-0.7.2]# make install
3、安装ogg库,libogg-1.1.3.tar.gz
[[root@localhost yasm-0.7.2]# cd ..
[root@localhost ffmpeg]# tar zxvf libogg-1.1.3.tar.gz ; rm -rf libogg-1.1.3.tar.gz ; cd libogg-1.1.3
[root@localhost libogg-1.1.3]# ./configure —prefix=/usr —enable-shared
[root@localhost libogg-1.1.3]# make ; make install
4、安装vorbis编解码器,libvorbis-1.1.2.tar.gz
[root@localhost libogg-1.1.3]# cd ..
[root@localhost ffmpeg]# tar zxvf libvorbis-1.1.2.tar.gz ; rm -rf libvorbis-1.1.2.tar.gz
[root@localhost ffmpeg]# cd libvorbis-1.1.2
[root@localhost libvorbis-1.1.2]# ./configure —prefix=/usr —enable-shared
[root@localhost libvorbis-1.1.2]# make ; make install
可能会出现如下的错误:
gcc -O20 -ffast-math -mno-ieee-fp -D_REENTRANT -fsigned-char -DUSE_MEMORY_H -o .libs/decoder_example decoder_example.o ../lib/.libs/libvorbis.so
/usr/bin/ld: decoder_example.o: undefined reference to symbol ‘ogg_stream_packetout’
/usr/bin/ld: note: ‘ogg_stream_packetout’ is defined in DSO /usr/lib/libogg.so.0 so try adding it to the linker command line
/usr/lib/libogg.so.0: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make[1]: *** [decoder_example] Error 1
make[1]: Leaving directory `/usr/local/pc/ffmpeg/libvorbis-1.1.2/examples’
make: *** [install-recursive] Error 1
这个意思是我们已经安装里vorbis了,不需要重复安装了,我们可以查看/usr/lib或者/usr/local/lib下是否有libvorbis的相关库文件,清除原先的文件
比如我的:
[root@localhost libvorbis-1.1.2]# ls /usr/lib/libvorbis.
libvorbis.a libvorbis.so libvorbis.so.0.3.1
libvorbis.la libvorbis.so.0 libvorbis.so.0.4.4
5、安装x264编码器的库,x264-snapshot-20110104-2245.tar.bz2
[root@localhost libvorbis-1.1.2]# cd ..
[root@localhost ffmpeg]# tar jxvf x264-snapshot-20110104-2245.tar.bz2 ; rm -rf x264-snapshot-20110104-2245.tar.bz2
[root@localhost ffmpeg]# cd x264-snapshot-20110104-2245
[root@localhost x264-snapshot-20110104-2245]# ./configure —prefix=/usr —enable-shared
Found no assembler
Minimum version is yasm-0.6.2
If you really want to compile without asm, configure with —disable-asm.
因为我在不同的目录下都安装了yasm,比如在/usr和/usr/local目录下都安装了yasm,然而这些目录都是全局目录,所以有冲突删除/usr/local目录下安装的yasm相应文件即可配置通过
[root@localhost x264-snapshot-20110104-2245]# make
[root@localhost x264-snapshot-20110104-2245]# make install
因为我想安装高点版本的ffmpeg,后来感觉x264的版本太低了,换了一个版本:x264-snapshot-20130301-2245-stable
[root@localhost x264-snapshot-20130301-2245-stable]# ./configure —prefix=/usr —enable-shared
Found yasm 1.0.0.2319
Minimum version is yasm-1.2.0
If you really want to compile without asm, configure with —disable-asm.
说明yasm的版本低了,可以下一个高一点的版本:http://yasm.tortall.net/releases/Release1.2.0.html
[root@localhost x264-snapshot-20130301-2245-stable]# cd ..
[root@localhost ffmpeg]# tar zxvf yasm-1.2.0.tar.gz ; rm -rf yasm-1.2.0.tar.gz
[root@localhost ffmpeg]# cd yasm-1.2.0
[root@localhost yasm-1.2.0]# ./configure —prefix=/usr
[root@localhost yasm-1.2.0]# make
[root@localhost yasm-1.2.0]# make install
[root@localhost yasm-1.2.0]# cd ../x264-snapshot-20130301-2245-stable/
[root@localhost x264-snapshot-20130301-2245-stable]# ./configure —prefix=/usr —enable-shared
[root@localhost x264-snapshot-20130301-2245-stable]# make
[root@localhost x264-snapshot-20130301-2245-stable]# make install
6、安装xvid编码器,xvidcore-1.1.3.tar.gz
[root@localhost x264-snapshot-20130301-2245-stable]# cd..
[root@localhost ffmpeg]# tar zxvf xvidcore-1.1.3.tar.gz ; rm -rf xvidcore-1.1.3.tar.gz
[root@localhost ffmpeg]# cd xvidcore-1.1.3
[root@localhost xvidcore-1.1.3]# cd build/generic
[root@localhost generic]# ./configure —prefix=/usr —enable-shared
[root@localhost generic]# make
[root@localhost generic]# make install
7、安装dts库,libdts-0.0.2.tar.gz
[root@localhost build]# cd ../../..
[root@localhost ffmpeg]# tar zxvf libdts-0.0.2.tar.gz ; rm -rf libdts-0.0.2.tar.gz
[root@localhost ffmpeg]# cd libdts-0.0.2
[root@localhost libdts-0.0.2]# ./configure —prefix=/usr —enable-shared
[root@localhost libdts-0.0.2]# make
[root@localhost libdts-0.0.2]# make install
8、安装a52,a52dec-0.7.4.tar.gz
[root@localhost libdts-0.0.2]# cd ..
[root@localhost ffmpeg]# tar zxvf a52dec-0.7.4.tar.gz ; rm -rf a52dec-0.7.4.tar.gz
[root@localhost ffmpeg]# cd a52dec-0.7.4
[root@localhost a52dec-0.7.4]# ./configure —prefix=/usr —enable-shared
[root@localhost a52dec-0.7.4]# make
[root@localhost a52dec-0.7.4]# make install
9、安装faad,faad2-2.7.tar.gz
[root@localhost a52dec-0.7.4]# cd ..
[root@localhost ffmpeg]# tar zxvf faad2-2.7.tar.gz ; rm -rf faad2-2.7.tar.gz
[root@localhost ffmpeg]# cd faad2-2.7
[root@localhost faad2-2.7]# ./configure —prefix=/usr —with-mp4v2 —enable-shared
[root@localhost faad2-2.7]# make
[root@localhost faad2-2.7]# make install
10、安装faac编码器,faac-1.28.tar.gz
[root@localhost faad2-2.7]# cd ..
[root@localhost ffmpeg]# tar zxvf faac-1.28.tar.gz ; rm -rf faac-1.28.tar.gz
[root@localhost ffmpeg]# cd faac-1.28
[root@localhost faac-1.28]# ./bootstrap
[root@localhost faac-1.28]# ./configure —prefix=/usr —with-mp4v2 —enable-shared
[root@localhost faac-1.28]# make
可能会出现如下错误:
In file included from mp4common.h0,from 3gp.cpp
mpeg4ip.h58: error: new declaration ‘char* strcasestr(const char*, const char*)’ /usr/include/string.h
28: error: ambiguates old declaration ‘const char* strcasestr(const char*, const char*)’
make[3]: *** [3gp.o] Error 1
make[3]: Leaving directory `/usr/local/pc/ffmpeg/faac-1.28/common/mp4v2’
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/usr/local/pc/ffmpeg/faac-1.28/common’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/pc/ffmpeg/faac-1.28’
make: *** [all] Error 2
解决方法:
修改源文件common/mp4v2/mpeg4ip.h文件
注释掉://char *strcasestr(const char *haystack, const char *needle);这一行
重新编译:
[root@localhost faac-1.28]# make clean ; make
[root@localhost faac-1.28]# make install
11、安装3gp的一些编解码文件,amrnb-6.1.0.4.tar.bz2、amrwb-7.0.0.1.tar.bz2
首先来安装amrnb-6.1.0.4.tar.bz2:
[root@localhost faac-1.28]# cd ..
[root@localhost ffmpeg]# tar jxvf amrnb-6.1.0.4.tar.bz2 ; rm -rf amrnb-6.1.0.4.tar.bz2
[root@localhost ffmpeg]# cd amrnb-6.1.0.4
[root@localhost amrnb-6.1.0.4]# ./configure —prefix=/usr —enable-shared
可能会出现下面的编译错误:
/usr/bin/wget -N http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-610.zip
--2013-01-31 00:35:45— http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-610.zip
Resolving www.3gpp.org… failed: Name or service not known.
wget: unable to resolve host address “www.3gpp.org”
make: *** [26104-610.zip] Error 4
解决方法:
根据打印信息提示,大概意思是缺少:26104-610.zip这个包,根据提示给出的网址可以下载26104-610.zip,然后把这个包拷贝到当前目录,重新编译。
[root@localhost amrnb-6.1.0.4]# make install
安装amrwb-7.0.0.1.tar.bz2:
[root@localhost amrnb-6.1.0.4]# cd ..
[root@localhost ffmpeg]# tar jxvf amrwb-7.0.0.1.tar.bz2 ; rm -rf amrwb-7.0.0.1.tar.bz2
[root@localhost ffmpeg]# cd amrwb-7.0.0.1
[root@localhost amrwb-7.0.0.1]# ./configure —prefix=/usr —enable-shared
/usr/bin/wget -N http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-700.zip
--2013-01-31 01:01:48—
http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-700.zip
Resolving www.3gpp.org… failed: Name or service not known.
wget: unable to resolve host address “www.3gpp.org”
make: *** [26204-700.zip] Error 4
可能会出现与安装amrnb-6.1.0.4.tar.bz2同样的问题,解决方法也是类似的
下载26204-700.zip包,拷贝这个包到当前目录,重新编译
[root@localhost amrwb-7.0.0.1]# make clean ; make
[root@localhost amrwb-7.0.0.1]# make install
12、这一步好像也是关于3gp的,我参照别人的做法
3gp,包括两个包:amrwb_float下载、amr_float下载,安装:解压ffmpeg的源码包后,进入ffmpeg-checkout-20070130/libavcodec/,新建两个新目录amrwb_float和amr_float,然后解压这两个包,把amrwb_float里面的所有文件复制到amrwb_float,把amr_float的所有文件复制到amr_float
[root@localhost amrwb-7.0.0.1]# cd ..
[root@localhost ffmpeg]# tar zxvf ffmpeg-1.0.4.tar.gz ; rm -rf ffmpeg-1.0.4.tar.gz
[root@localhost ffmpeg]# unzip 26104-610.zip ; rm -rf 26104-610.zip
[root@localhost ffmpeg]# mkdir ffmpeg-1.0.4/libavcodec/amrwb_float
[root@localhost ffmpeg]# mkdir ffmpeg-1.0.4/libavcodec/amr_float
[root@localhost ffmpeg]# unzip 26104-610_ANSI_C_source_code.zip -d ffmpeg-1.0.4/libavcodec/amr_float
[root@localhost ffmpeg]# rm -rf 26104-610_ANSI_C_source_code.zip
[root@localhost ffmpeg]# unzip 26204-700.zip ; rm -rf 26204-700.zip
[root@localhost ffmpeg]# unzip 26204-700_ANSI-C_source_code.zip -d ffmpeg-1.0.4/libavcodec/amrwb_float
[root@localhost ffmpeg]# rm -rf 26204-700_ANSI-C_source_code.zip
13、安装ffmpeg
[root@localhost ffmpeg]# cd ffmpeg-1.0.4
[root@localhost ffmpeg-1.0.4]# ./configure —prefix=/usr/local/pc/ffmpeg/ffmpeg-install —enable-gpl —enable-ersion3 —enable-nonfree —enable-shared —enable-pthreads —enable-x11grab —enable-network —enable-libmp3lame —enable-libvorbis —enable-libfaac —enable-libx264 —enable-libxvid —extra-cflags=I/local/include —extra-ldflags=-L/local/lib
[root@localhost ffmpeg-1.0.4]# make
可能会出现下面的错误:
libavcodec/libavcodec.so: undefined reference to `x264_encoder_open_118’
collect2: ld returned 1 exit status
make: *** [ffmpeg_g] Error 1
解决方法:
可能原先我做过交叉编译,在/usr/local目录下面安装了x264,可能有冲突,把x264在/usr/local目录下的一些相关文件卸载掉,编译就会通过
重新编译:
[root@localhost ffmpeg-1.0.4]# make
[root@localhost ffmpeg-1.0.4]# make install
将ffmpeg的可执行文件设置为全局变量:
[root@localhost bin]# vim /root/.bash_profile
修改:
PATH=/usr/local/ssl/bin:/usr/local/pc/ffmpeg/ffmpeg-install/bin:$PATH:$HOME/bin
[root@localhost bin]# source /root/.bash_profile
14、测试
运行ffmpeg测试:
[root@localhost ffmpeg-install]# ffmpeg -i /dev/video0 -y -f video4linux -s 320x240 -vcodec mpeg4 125.mp4
可能会出现下面的错误:
ffmpeg: error while loading shared libraries: libavdevice.so.54: cannot open shared object file: No such file or directory
说明库文件找不到,在网上查找了一些方法:
修改ld.so.conf文件,最后面添加/usr/local/pc/ffmpeg/ffmpeg-install/lib:
[root@localhost etc]# vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/ssl/lib
/usr/local/pc/ffmpeg/ffmpeg-install/lib
保存退出
使配置文件生效:
[root@localhost etc]# ldconfig
完成!!
再次运行测试:
[root@localhost local]# ffmpeg -y -f video4linux2 -s 640x480 -r 30 -b 10000000 -i /dev/video0 -vcodec mpeg4 test.mp4
test.mp4文件可以生成并且也可以用ffplay播放!
安装完成后,删除原来解压的一些文件,因为占用的空间太大了
还没有评论,来说两句吧...