centos安装FFmpeg

所有模块自己安装的编译

安装autoconf

wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.xz    
tar xvf autoconf-2.69.tar.xz
cd autoconf-2.69
./configure
make
make install

安装automake

wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.xz  
tar xvf automake-1.15.tar.xz
cd automake-1.15
./configure
make
make install

安装libtool(FAAC需要)

wget http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.xz
tar xvf libtool-2.4.6.tar.xz
cd libtool-2.4.6
./configure
make
make install

安装yasm支持汇编优化(FFmpeg需要)

wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make
make install

安装MP3支持库LAME

wget http://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz  
tar xvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure
make
make install

安装AAC支持库FAAC

wget http://jaist.dl.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.bz2 
tar xvf faac-1.28.tar.bz2
cd faac-1.28
./bootstrap
./configure --with-mp4v2 
#按前文修改mpeg4ip.h内容
make
make install
make时报错:mpeg4ip.h:126: 错误:对‘char* strcasestr(const char, const char)’的新声明

需要修改common/mp4v2/mpeg4ip.h第123行至129行内容

#ifdef __cplusplus
extern "C" {
#endif
char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif

修改为

#ifdef __cplusplus
extern "C++" {
#endif
const char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif

主要提示:可能受限于FFmpeg版本的缘故,安装了AAC库,在ffmpeg-3.2.4版本下编译ffmpeg,使用--enable-libfaac选项时,会报找不到libfaac错误。百度了一番,看了FFmpeg的WiKi百科,发现它使用libfdk-aac库替代libfaac库,安装后测试果然解决问题。

wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
tar xzvf fdk-aac.tar.gz
cd mstorsjo-fdk-aac*
autoreconf -fiv
./configure --disable-shared --with-pic
#--with-pic 很重要,一定要带上,不然在编译FFmpeg时会报错
make
make install

安装AMR支持库opencore-amr

wget http://jaist.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.3.tar.gz
tar xvf opencore-amr-0.1.3.tar.gz
cd opencore-amr-0.1.3
./configure
make
make install

安装通用音乐音频编码格式支持库libvorbis

支持库libvorbis需要依赖libogg,先安装libogg库

先安装libogg库
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.xz
tar xvf libogg-1.3.2.tar.xz
cd libogg-1.3.2
./configure
make
make install
再安装libvorbis库
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.xz
tar xvf libvorbis-1.3.5.tar.xz
cd libvorbis-1.3.5
./configure
make
make install
安装libvorbis出现以下错误
*** Could not run Ogg test program, checking why...
*** The test program compiled, but did not run. This usually means
*** that the run-time linker is not finding Ogg or finding the wrong
*** version of Ogg. If it is not finding Ogg, you'll need to set your
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
*** to the installed location  Also, make sure you have run ldconfig if that
*** is required on your system
***
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH
configure: error: must have Ogg installed!
yum install libogg

安装x264库支持H.264视频转码

git clone git://git.videolan.org/x264.git
cd x264
./configure --enable-shared
make
make install

安装Xvid库支持MPEG-4转码

wget http://downloads.xvid.org/downloads/xvidcore-1.3.3.tar.bz2
tar xvf xvidcore-1.3.3.tar.bz2
cd xvidcore/build/generic
./configure
make
make install

安装Theora视频压缩支持库

wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.xz
tar xvf libtheora-1.1.1.tar.xz
cd libtheora-1.1.1
./configure
make
make install

安装NUT支持库

该软件需要用svn获取源代码,svn可以直接用yum install svn来装。 安装时64位Linux系统需要修改文件config.mak

# 在最后一个CFLAGS下一行增加:
CFLAGS += -fPIC

否则安装FFmpeg make时报错:

/usr/local/lib/libnut.a: could not read symbols: Bad value
svn co svn://svn.mplayerhq.hu/nut/src/trunk libnut
cd libnut
make
make install

安装VP8/VP9编解码支持库

#git clone http://git.chromium.org/webm/libvpx.git
#直接获取比较好,没装git
wget -O libvpx.zip https://codeload.github.com/webmproject/libvpx/zip/master
unzip libvpx.zip
cd libvpx
./configure --enable-shared
make
make install
出现错误

提示没有安装nasm包,当然也可以在./configure --disable-asm,但是我们在这里将nasm包安装起来。

$ ./configure --enable-shared
Found no assembler
Minimum version is nasm-2.13
If you really want to compile without asm, configure with --disable-asm.
wget 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 nasm-2.13.01
./configure
make && make install
make install

安装FFmpeg最新版

wget http://ffmpeg.org/releases/ffmpeg-3.2.4.tar.bz2
tar xvf ffmpeg-3.2.4.tar.bz2
cd ffmpeg-3.2.4
#老版本的--enable-libfaac,已替换为--enable-libfdk-aac
./configure --enable-version3 --enable-libvpx --enable-libfdk-aac --enable-libmp3lame --enable-libvorbis --enable-libx264 --enable-libxvid --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads --enable-libnut --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-shared
make
#若出现下述错误,在此修改config.mak文件,然后再make,切记别重新configure
make install
若make的时候,报以下错误
/usr/bin/ld: libavcodec/mqc.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
libavcodec/mqc.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
#config.mak L75加入 -fPIC,然后重新编译
#直接替换,顺序可能不一样
HOSTCFLAGS=-O3 -g -std=c99 -Wall -fPIC

添加动态链接库配置

echo '/usr/local/lib' >> /etc/ld.so.conf.d/local.conf
#更新缓存
ldconfig

yum安装模块安装ffmpeg 3.1

安装rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

wget -c ftp://195.220.108.108/linux/dag/redhat/el6/en/x86_64/dag/RPMS/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm -Uhv rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm 

安装依赖

yum install automake autoconf make gcc gcc-c++ libtool zlib zlib-devel curl curl-devel alsa-lib alsa-lib-devel gettext gettext-devel expat expat-devel nasm pkgconfig bzip2 -y

安装 yasm,gnutls, lame,faac

yum install yasm yasm-devel gnutls gnutls-devel  lame lame-devel faac faac-devel -y

卸载系统自带的,如果不卸载,可能在安装ffmpeg时会出现版本问

yum remove x264 x264-deve

安装最新的x264

wget -c ftp://ftp.videolan.org/pub/x264/snapshots/x264-snapshot-20120718-2245-stable.tar.bz2
tar jxvf x264-snapshot-20120718-2245-stable.tar.bz2
cd x264-snapshot-20120718-2245-stable
./configure --enable-shared  --enable-static
make 
make install

安装ffmpeg-3.1

wget http://www.ffmpeg.org/releases/ffmpeg-3.1.tar.gz
tar -zxvf ffmpeg-3.1.tar.gz
cd ffmpeg-3.1
./configure --prefix=/usr/local/ --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-zlib --enable-bzlib --enable-libmp3lame --enable-libx264 --enable-pic --enable-libfaac
make
make install

添加动态链接库配置

vi /etc/ld.so.conf
# 加入以下两行,如果有就不用加了
include ld.so.conf.d/*.conf
/usr/local/lib/
# 更新缓存
ldconfig

配置ffmpeg全局变量

vi /etc/profile
export FFMPEG=/usr/local/ffmpeg

检查安装是否安装OK

ffmpeg -version

[root@iZ2ze0bp6do7s3u6jz6dsfZ ffmpeg-3.1]# ffmpeg -version
ffmpeg version 3.1 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-16)
configuration: --prefix=/usr/local/ --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-zlib --enable-bzlib --enable-libmp3lame --enable-libx264 --enable-pic --enable-libfaac
libavutil      55. 27.100 / 55. 27.100
libavcodec     57. 48.101 / 57. 48.101
libavformat    57. 40.101 / 57. 40.101
libavdevice    57.  0.101 / 57.  0.101
libavfilter     6. 46.102 /  6. 46.102
libswscale      4.  1.100 /  4.  1.100
libswresample   2.  1.100 /  2.  1.100
libpostproc    54.  0.100 / 54.  0.100

遇到的问题

x264-snapshot-20120718-2245-stable ./configure --enable-shared --enable-static

➜  x264-snapshot-20120718-2245-stable ./configure --enable-shared  --enable-static
Found no assembler
Minimum version is yasm-1.0.0
If you really want to compile without asm, configure with --disable-asm.

意思是说你有一个老版本的yasm(似乎是编译器?)装在你的系统里面,所以该升级他了。

git clone git://github.com/yasm/yasm.git
cd yasm
./autogen.sh
./configure
make
make install

纯yum安装

Update the system

sudo yum install epel-release -y
sudo yum update -y
sudo shutdown -r now

Install the Nux Dextop YUM repo

There are no official FFmpeg rpm packages for CentOS for now. Instead, you can use a 3rd-party YUM repo, Nux Dextop, to finish the job.

On CentOS 7
sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
For CentOS 6
sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm

Install FFmpeg and FFmpeg development packages

sudo yum install ffmpeg ffmpeg-devel -y

Test drive

ffmpeg -version

参考文章