Linux下ffmpeg的完整安装

xiaoxiao2025-04-29  13

最近在做一个企业项目, 期间需要将用户上传的视频转成flv格式或mp4格式并用flash插件在前端播放, 我决定采用ffmpeg (http://www.ffmpeg.org/ )实现. 当然以前也用过ffmpeg, 但是没有安装额外的库, 只是源代码下简单地 ./configure, 最后发现好多功能都用不了, 比如最流行的x264编码器. 所以决心完整地安装一下ffmpeg, 经过两天痛苦地折腾, 终于成功了, 现在将过程记录下来. 主要参考了 [1] 和 [2] 两篇博文, 其中 [1] 是2007年写成的, 其中所提到的依赖库版本比较老, 本人安装的都是相应最新的版本.

 

首先要安装各种解码器  1、lame  lame-3.99.5.tar.gz  Url:http://sourceforge.net/project/showfiles.php?group_id=290&package_id=309  安装方法如下:

1 tar -zxvf lame-3.99.5.tar.gz 2 cd lame-3.99.5 3 ./configure --enable-shared 4 make 5 make install

2、libogg  libogg-1.3.1.tar.gz  Url:http://www.xiph.org/downloads/  安装方法如下:

1 ./configure 2 make 3 make install

3、libvorbis  libvorbis-1.3.3.tar.gz  Url:http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz

(libvorbis依赖于libogg, 所以libogg必须先于libvorbis安装) 安装方法如下:

1 ./configure 2 make 3 make install

 

在编译的时候会提示这个错误

说我们必须安装ogg,可事实我们已经在前面安装了ogg了。

原因在哪里,当然是动态库的查找路径了, 我的解决办法是在 /etc/ld.so.conf.d/目录下创建一个名为local-libraries.conf的文件,内容很简单,只有一行: /usr/local/lib 然后执行ldconfig -v 

4、xvid  xvidcore-1.3.2.tar.gz  Url:http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz  安装方法如下:

1 tar zvxf xvidcore-1.3.2.tar.gz 2 cd xvidcore-1.3.2/build/generic 3 ./configure4 make 5 make install

5、x264  latest_x264.tar.bz2 (其中包含的目录是 x264-snapshot-20131023-2245) 建议安装最新的x264

# git clone http://git.videolan.org/git/x264.git Url:http://www.videolan.org/developers/x264.html ftp://ftp.videolan.org/pub/videolan/x264/snapshots/  安装方法如下:

1   git clone http://git.videolan.org/git/x264.git 2     ./configure  //./configure --includedir=/usr/local/include --libdir=/usr/local/lib --enable-shared 3     make  4     make install 

出现错误:

Found no assembler Minimum version is nasm-2.13 If you really want to compile without asm, configure with --disable-asm.

提示没有安装nasm包,当然也可以在./configure --disable-asm,但是我们在这里将nasm包安装起来。 地址:http://www.nasm.us/pub/nasm/releasebuilds/2.13.01/nasm-2.13.01.tar.xz  安装方法:

#tar -vxf nasm-2.13.01.tar.xz #cd cd nasm-2.13.01 #./configure #make && make install

安装完毕nasm之后,继续安装x264.  

#cd ../x264-snapshot-20170615-2245/ #./configure #make && make instal

6、libdca libdca-0.0.5.tar.bz2 Url: http://www.videolan.org/developers/libdca.html 安装方法:

1 tar -jxvf libdca-0.0.5.tar.bz2 2 cd libdca-0.0.5 3 ./configure 4 make 5 make install

7、a52  a52dec-0.7.4.tar.gz           (这个库从2002年就没有更新过了)http://liba52.sourceforge.net/downloads.html        安装方法:

1 ./configure 2 make 3 make install

8、faad2  faad2-2.7.tar.gz http://www.audiocoding.com/downloads.html  安装方法

0 autoreconf -vif 1 tar axf faad2-2.7.tar.bz2 2 ./configure --with-mp4v2 --enable-shared 3 make 4 make install

9、faac  faac-1.28.tar.gz http://www.audiocoding.com/downloads.html 安装方法:

1 tar zxvf faac-1.28.tar.gz 2 cd faac-1.28 3 ./bootstrap 4 ./configure 5 make 6 make install

可能报错:

/home/xuxuequan/Ingenicwork/toolchain/mips-gcc472-glibc216-32bit/mips-linux-gnu/libc/usr/include/string.h:365:26: error:ambiguates old declaration 'const char* strcasestr(const char*, const char*)'

 解决方法:

在文件 /common/mp4v2/mpeg4ip.h  line 126注释掉如下语句即可:126 //char *strcasestr(const char *haystack, const char *needle);

重新执行上面编译安装

10、amr-nb  amrnb-10.0.0.0.tar.bz2 http://ftp.penguin.cz/pub/users/utx/amr/ ( 从此处下载最新版本 ) 安装方法:

1 ./configure. 2 make 3 make install

11、amr-wb  amrwb-7.0.0.1.tar.bz2 http://ftp.penguin.cz/pub/users/utx/amr/ ( 从此处下载最新版本 ) 安装方法:

1 ./configure 2 make 3 make install

12、最关键的一步, 安装ffmpeg

ffmpeg-2.6.3.tar.bz2  建议下载最新版

# wget http://ffmpeg.org/releases/ffmpeg-2.6.3.tar.bz2 --no-check-certificate # ./configure --prefix=/usr/local/ffmpeg --enable-libmp3lame --enable-libvorbis --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-postproc --enable-ffplay

报错:

 ERROR: libopencore_amrnb not found

https://sourceforge.net/projects/opencore-amr/files/opencore-amr/

下载opencore-amr-0.1.3.tar.gz

执行

./configure && make && sudo make install

重新编译可能报错:

ERROR: x265 not found using pig-config

原因是需要设置 PKG_CONFIG_PATH,通过pkg-config去指定路径自动寻找需要链接的依赖库,同时,就不需要使用

--extra-cflags=-I、

--extra-cxxflags=-I、

--extra-ldflags=-L来指定依赖库路径

使用方法:

在./configure之前输入export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH (此路径为.pc文件所在路径),可使用

echo $PKG_CONFIG_PATH查看 --------------------- 

使用git安装最新的x264 和ffmpeg

安装完后运行 /usr/local/ffmpeg/bin/ffmpeg --version 报错 :

usr/local/ffmpeg/bin/ffmpeg: error while loading shared libraries: libopencore-amrwb.so.0: cannot open shared object file: No such file or directory

解决办法:

vi /etc/ld.so.conf

加入:/usr/local/lib

执行ldconfig

配置环境变量:

#vim /etc/profile.d/ffmpeg.sh export ffmpeg_Home=/usr/local/ffmpeg export PATH=$PATH:$ffmpeg_Home/bin source /etc/profile.d/ffmpeg.sh  # ffmpeg -version ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-23) configuration: --prefix=/usr/local/ffmpeg --enable-libmp3lame --enable-libvorbis --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-postproc --enable-ffplay libavutil      56. 14.100 / 56. 14.100 libavcodec     58. 18.100 / 58. 18.100 libavformat    58. 12.100 / 58. 12.100 libavdevice    58.  3.100 / 58.  3.100 libavfilter     7. 16.100 /  7. 16.100 libswscale      5.  1.100 /  5.  1.100 libswresample   3.  1.100 /  3.  1.100 libpostproc    55.  1.100 / 55.  1.100

 

转载请注明原文地址: https://www.6miu.com/read-5029447.html

最新回复(0)