您当前的位置:首页 > 计算机 > 系统应用 > Linux

在CentOS上编译安装FFmpeg

时间:10-22来源:作者:点击数:

在CentOS编译安装ffmpeg比较麻烦,以前也搞过多次,由于博客调整,特重新记录一下,以备不时之需。

使用yum安装ffmpeg和相关软件

快速安装 ffmpeg

直接安装:

yum install ffmpeg ffmpeg-devel

若没有找到相应包,需要先加入要应的包。

将下列代码命名为 dag.repo 放在 /etc/yum.repos.d 目录 下。

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1

然后再执行上方的安装命令。

安装 ffmpeg-php 扩展

wget /path/to/this/file/ffmpeg-php-0.5.2.1.tbz2
tar -xjf ffmpeg-0.5.2.1.tbz2
phpize
./configure
make
make install

修改 php.ini 文件

安装完成后,将会在/usr/local/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so 看到php扩展文件。

打开php.ini文件,加入下面两行

[ffmpeg]
extension=ffmpeg.so

重启WEB服务器。使用phpinfo即可看到ffmpeg相关信息。

// #test.php

<?php

phpinfo()

?>

php 使用方法

<?php
$extension = "ffmpeg";
$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
$extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;

// load extension
if(!extension_loaded($extension)) {
    dl($extension_soname) or die("Can't load extension $extension_fullname\n");
}
?>

安装 Mplayer 和 Mencoder

yum install mplayer mencoder

常见问题

常见问题及解决方案请参考这里:http://www.mysql-apache-php.com/ffmpeg-install.htm

自行编译安装 ffmpeg

安装依赖项

yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel

安装相应软件包

可以建立目录存放软件包

mkdir ~/ffmpeg_sources

注意:以下软件包请有选择的安装,如果不需要请在./configure时移除或关闭相关选项

安装 yasm

Yasm是一个完全重写的NASM汇编。目前,它支持x86和AMD64指令集。 x264 和 FFmpeg都使用Yasm.

cd ~/ffmpeg_sources
git clone --depth 1 git://github.com/yasm/yasm.git
cd yasm
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install
make distclean

wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar zxf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install
make distclean
. ~/.bash_profile

安装 x264

H.264 编码器。http://trac.ffmpeg.org/wiki/Encode/H.264

cd ~/ffmpeg_sources
git clone --depth 1 git://git.videolan.org/x264
cd x264
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make
make install
make distclean

wget ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
tar jxf last_x264.tar.bz2
cd x264-snapshot-20130311-2245/
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-shared
make
make install
make distclean

需要ffmpeg配置./configure --enable-gpl --enable-libx264

注:由于libx264的code有GPL信息,所以,支持libx264时,需要–enable-gpl,ffmpeg在license方面还是比我们国内的人更重视

安装 x265

H.265/HEVC编码器.http://trac.ffmpeg.org/wiki/Encode/H.265

cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make
make install

需要ffmpeg配置./configure --enable-gpl --enable-libx265

安装 libfdk_aac

AAC音频编码器,Fraunhofer AAC library

cd ~/ffmpeg_sources
git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --enable-shared
make
make install
make distclean

需要ffmpeg配置--enable-libfdk_aac ,如果指定了--enable-gpl还要配置--enable-nonfree

安装 libmp3lame

Mp3音频编码器

wget http://iweb.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar zxf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-shared --enable-nasm
make
make install
make distclean

需要ffmpeg配置--enable-libmp3lame

安装 libopus

Opus 音频编解码器

cd ~/ffmpeg_sources
git clone git://git.opus-codec.org/opus.git
cd opus
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

wget http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz
tar zxf opus-1.0.3.tar.gz
cd opus-1.0.3
./configure --prefix="$HOME/ffmpeg_build" --enable-shared
make
make install
make distclean

需要ffmpeg配置--enable-libopus

安装 libogg库

libogg是Ogg流库,libtheora、libvorbis需要libogg库,speex需要它。

cd ~/ffmpeg_sources
curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
tar xzvf libogg-1.3.2.tar.gz
cd libogg-1.3.2
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

安装 libvorbis库

Vorbis音频编码器,需要libogg库。http://trac.ffmpeg.org/wiki/CompilationGuide/Centos#libogg

cd ~/ffmpeg_sources
curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
tar xzvf libvorbis-1.3.4.tar.gz
cd libvorbis-1.3.4
LDFLAGS="-L$HOME/ffmeg_build/lib" CPPFLAGS="-I$HOME/ffmpeg_build/include" ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

需要ffmpeg配置--enable-libvorbis

安装 libvpx

VP8/VP9视频编码器

cd ~/ffmpeg_sources
git clone --depth 1 http://git.chromium.org/webm/libvpx.git
cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --enable-examples
make
make install
make clean

需要ffmpeg配置--enable-libvpx

编译安装 ffmpeg

cd ~/ffmpeg_sources
git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd ffmpeg
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265
make
make install
make distclean
hash -r

注:

  • 编译完成后ffmpeg,ffprobe,ffserver,lame,x264都可以使用。
  • 编译安装时可以参考Windows Build:http://ffmpeg.zeranoe.com/builds/
  • 如果还需要持续更新请保留ffmpeg_sources目录。

##其它可选软件包

安装 OpenCORE AMR

wget http://iweb.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.3.tar.gz
tar zxf opencore-amr-0.1.3.tar.gz
./configure --prefix="$HOME/ffmpeg_build"  –enable-shared
make
make install

需要ffmpeg配置--enable-libopencore-amrnb 和/或 --enable-libopencore-amrwb

安装 VisualOn AAC

注:github的tag和master版均无法autoconf,用zeranoe版代替

wget wget http://ffmpeg.zeranoe.com/builds/source/external_libraries/vo-aacenc-0.1.3.tar.xz
xz -d vo-aacenc-0.1.3.tar.xz
tar xf vo-aacenc-0.1.3.tar
cd vo-aacenc-0.1.3
./configure --prefix="$HOME/ffmpeg_build" 
make
make install

也可

wget http://iweb.dl.sourceforge.net/project/opencore-amr/vo-aacenc/vo-aacenc-0.1.3.tar.gz

需要ffmpeg配置--enable-libvo-aacenc

安装 VisualOn AMR-WB

注:github的tag和master版均无法autoconf,用zeranoe版代替

wget http://ffmpeg.zeranoe.com/builds/source/external_libraries/vo-amrwbenc-0.1.2.tar.xz
xz -d vo-amrwbenc-0.1.2.tar.xz
tar xf vo-amrwbenc-0.1.2.tar
cd vo-amrwbenc-0.1.2
./configure --prefix="$HOME/ffmpeg_build"

需要ffmpeg配置--enable-libvo-amrwbenc

安装 frei0r

先安装新版autoconf,这会覆盖掉系统中的旧版本哦

wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
tar zxf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure --prefix="$HOME/ffmpeg_build" 
make
make install
wget http://files.dyne.org/frei0r/releases/frei0r-plugins-1.4.tar.gz
tar zxf frei0r-plugins-1.4.tar.gz
cd frei0r-plugins-1.4
./configure --prefix="$HOME/ffmpeg_build" 
make
make install

安装 gnutls

注意:/etc/ld.so.conf要加上lib64。并且不要使用yum remove gnutls gnutls-devel

首先安装nettle:

wget http://www.lysator.liu.se/~nisse/archive/nettle-2.5.tar.gz
tar zxf nettle-2.5.tar.gz
cd nettle-2.5
./configure --prefix="$HOME/ffmpeg_build"  –enable-shared
make
make install

然后安装gnutls新版:

wget ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1/gnutls-3.1.9.1.tar.xz
xz -d gnutls-3.1.9.1.tar.xz
tar xf gnutls-3.1.9.1.tar
cd gnutls-3.1.9.1
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure –enable-shared
make
make install

安装 rtmpdump

wget http://rtmpdump.mplayerhq.hu/download/rtmpdump-2.3.tgz
tar zxf rtmpdump-2.3.tgz
cd rtmpdump-2.3
make
make install

安装 schroedinger

注:先安装好orc库

wget http://code.entropywave.com/download/orc/orc-0.4.17.tar.gz
tar zxf orc-0.4.17.tar.gz
cd orc-0.4.17
./configure --prefix="$HOME/ffmpeg_build" 
make
make install
/sbin/ldconfig
wget http://diracvideo.org/download/schroedinger/schroedinger-1.0.11.tar.gz
tar zxf schroedinger-1.0.11.tar.gz
cd schroedinger-1.0.11
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure
make
make install

安装 soxr

注:新版libsoxr貌似与当前ffmpeg不兼容,用旧版

yum install -y xz
wget http://hivelocity.dl.sourceforge.net/project/soxr/soxr-0.1.0-Source.tar.xz
xz -d soxr-0.1.0-Source.tar.xz
tar xf soxr-0.1.0-Source.tar
cd soxr-0.1.0-Source
./go
cd Release/
make
make install
/sbin/ldconfig

安装 speex

音频编码解码器。需要安装libogg库

yum install speex-devel

wget http://downloads.xiph.org/releases/speex/speex-1.2rc1.tar.gz
tar zxf speex-1.2rc1.tar.gz
cd speex-1.2rc1
./configure --prefix="$HOME/ffmpeg_build" 
make
make install

ffmpeg ./configure 添加 --enable-libspeex

安装 libfreetype

字体呈现库,使用drawtext http://ffmpeg.org/ffmpeg-filters.html#drawtext-1

yum install freetype-devel

ffmpeg ./configure 添加 --enable-libfreetype

安装 libsdl库

wget http://www.libsdl.org/release/SDL-1.2.15.tar.gz
tar zxf SDL-1.2.15.tar.gz
cd SDL-1.2.15
./configure --prefix="$HOME/ffmpeg_build" 
make
make install
/sbin/ldconfig

安装 theora

Theora视频编码器,需要需要libogg,libvorbis和libsdl库

wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2
tar zjf libtheora-1.1.1.tar.bz2
./configure  --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-examples --enable-shared --disable-sdltest --disable-vorbistest
make
make install
make distclean

ffmpeg ./configure 添加 --enable-libtheora

安装 twolame

wget http://downloads.sourceforge.net/twolame/twolame-0.3.13.tar.gz
tar zxf twolame-0.3.13
.tar.gz
cd twolame-0.3.13
./configure --prefix="$HOME/ffmpeg_build" 
make
make install
/sbin/ldconfig

安装 xvid

wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
tar zxf xvidcore-1.3.2.tar.gz
cd xvidcore
cd build/generic
./configure --prefix="$HOME/ffmpeg_build" 
make
make install

更新FFmpeg及相关组件

更新依赖项

删除旧文件,更新依赖项

rm -rf ~/ffmpeg_build ~/bin/{ffmpeg,ffprobe,ffserver,lame,vsyasm,x264,yasm,ytasm}
# yum install autoconf automake cmake gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel

更新 x264

cd ~/ffmpeg_sources/x264
make distclean
git pull

然后运行

./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make
make install
make distclean

更新 x265

cd ~/ffmpeg_sources/x265
rm -rf ~/ffmpeg_sources/x265/build/linux/*
hg update
cd ~/ffmpeg_sources/x265/build/linux

然后运行

cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make
make install

更新 libfdk_aac

cd ~/ffmpeg_sources/libfdk_aac
make distclean
git pull

然后运行

cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

更新 libvpx

cd ~/ffmpeg_sources/libvpx
make clean
git pull

然后运行

cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples
make
make install
make clean

更新FFmpeg

cd ~/ffmpeg_sources/ffmpeg
make distclean
git pull

然后运行

cd ffmpeg
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265
make
make install
make distclean
hash -r

还原所有本文安装内容

rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffserver,lame,vsyasm,x264,yasm,ytasm}
# yum erase autoconf automake cmake gcc gcc-c++ git libtool mercurial nasm pkgconfig zlib-devel
hash -r

注:如安装其它软件包需要自行删除

自动安装shell

https://gist.github.com/gboudreau/f24aed76b4cc91bfb2c1

#!/bin/sh
 
# Based on instructions found here: http://wiki.razuna.com/display/ecp/FFMpeg+Installation+on+CentOS+and+RedHat#FFMpegInstallationonCentOSandRedHat-InstallX264
 
if [ "`/usr/bin/whoami`" != "root" ]; then
    echo "You need to execute this script as root."
    exit 1
fi
 
cat > /etc/yum.repos.d/centos.repo<<EOF
[centos]
name=CentOS-6 – Base
baseurl=http://mirror.centos.org/centos/6/os/x86_64/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
enabled=1
priority=1
protect=1
includepkgs=SDL SDL-devel gsm gsm-devel libtheora theora-tools libdc1394 libdc1394-devel libraw1394-devel
EOF
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
 
rpm -Uhv http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum -y update
 
yum -y install glibc gcc gcc-c++ autoconf automake libtool git make nasm pkgconfig
yum -y install SDL-devel a52dec a52dec-devel alsa-lib-devel faac faac-devel faad2 faad2-devel
yum -y install freetype-devel giflib gsm gsm-devel imlib2 imlib2-devel lame lame-devel libICE-devel libSM-devel libX11-devel
yum -y install libXau-devel libXdmcp-devel libXext-devel libXrandr-devel libXrender-devel libXt-devel
yum -y install libogg libvorbis vorbis-tools mesa-libGL-devel mesa-libGLU-devel xorg-x11-proto-devel zlib-devel
yum -y install libtheora theora-tools
yum -y install ncurses-devel
yum -y install libdc1394 libdc1394-devel
yum -y install amrnb-devel amrwb-devel opencore-amr-devel
 
cd /opt
wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
tar xzvf xvidcore-1.3.2.tar.gz && rm -f xvidcore-1.3.2.tar.gz
cd xvidcore/build/generic
./configure --prefix="$HOME/ffmpeg_build" && make && make install
 
cd /opt
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz
tar xzvf libogg-1.3.1.tar.gz && rm -f libogg-1.3.1.tar.gz
cd libogg-1.3.1
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && make && make install
 
cd /opt
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
tar xzvf libvorbis-1.3.4.tar.gz && rm -f libvorbis-1.3.4.tar.gz
cd libvorbis-1.3.4
./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared && make && make install
 
cd /opt
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz
tar xzvf libtheora-1.1.1.tar.gz && rm -f libtheora-1.1.1.tar.gz
cd libtheora-1.1.1
./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-examples --disable-shared --disable-sdltest --disable-vorbistest && make && make install
 
cd /opt
wget http://downloads.sourceforge.net/opencore-amr/vo-aacenc-0.1.2.tar.gz
tar xzvf vo-aacenc-0.1.2.tar.gz && rm -f vo-aacenc-0.1.2.tar.gz
cd vo-aacenc-0.1.2
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && make install
 
yum -y remove yasm
cd /opt
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzfv yasm-1.2.0.tar.gz && rm -f yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && make install
export "PATH=$PATH:$HOME/bin" 
 
cd /opt
git clone http://git.chromium.org/webm/libvpx.git
cd libvpx
git checkout tags/v1.3.0
./configure --prefix="$HOME/ffmpeg_build" --disable-examples && make && make install
 
cd /opt
git clone git://git.videolan.org/x264.git
cd x264
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static && make install
 
export LD_LIBRARY_PATH=/usr/local/lib/:$HOME/ffmpeg_build/lib/
echo /usr/local/lib >> /etc/ld.so.conf.d/custom-libs.conf
echo $HOME/ffmpeg_build/lib/ >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
 
cd /opt
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
git checkout release/2.2
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig"
export PKG_CONFIG_PATH
./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" \
--extra-libs=-ldl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx --enable-libfaac \
--enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libvo-aacenc --enable-libxvid --disable-ffplay \
--enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads --arch=x86_64 && make install
 
# Test the resulting ffmpeg binary
cp $HOME/bin/ffmpeg /usr/bin/
ffmpeg -v
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门