Linux编译安装ffmpeg

# https://trac.ffmpeg.org/wiki/CompilationGuide/Centos
yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel
mkdir ~/ffmpeg_sources
export FFMPEG_ROOT=/usr/local/ffmpeg

# YASM汇编器,x264和FFmpeg使用的x86优化的汇编器,必须,否则编译极慢!
cd ~/ffmpeg_sources
curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xzvf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure --prefix="$FFMPEG_ROOT"
make && make install

# NASM汇编器,x264和其他工具需要,推荐,否则编译极慢!
cd ~/ffmpeg_sources
curl -O -L https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/nasm-2.13.03.tar.bz2
tar xjvf nasm-2.13.03.tar.bz2
cd nasm-2.13.03/
./autogen.sh
./configure --prefix="$FFMPEG_ROOT"
make && make install

# libx264,H.264视频编码器。需要ffmpeg在./configure时使用--enable-gpl --enable-libx264
cd ~/ffmpeg_sources
git clone --depth 1 http://git.videolan.org/git/x264
cd x264/
PKG_CONFIG_PATH="$FFMPEG_ROOT/lib/pkgconfig" ./configure --prefix="$FFMPEG_ROOT" --enable-static
make && make install

# libx265,H.265/HEVC视频编码器。需要ffmpeg在./configure时使用--enable-gpl --enable-libx265
cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$FFMPEG_ROOT" -DENABLE_SHARED:bool=off ../../source
make && make install

# libfdk_aac,AAC音频编码器。需要ffmpeg在./configure时使用--enable-libfdk-aac,若有--enable-gpl需加--enable-nonfree
cd ~/ffmpeg_sources
git clone --depth 1 https://github.com/mstorsjo/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$FFMPEG_ROOT" --disable-shared
make && make install

# libmp3lame,MP3音频编码器。需要ffmpeg在./configure时使用--enable-libmp3lame
cd ~/ffmpeg_sources
curl -O -L http://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
tar xzvf lame-3.100.tar.gz
cd lame-3.100
./configure --prefix="$FFMPEG_ROOT" --disable-shared --enable-nasm
make && make install

# libopus,Opus音频编码/解码器。需要ffmpeg在./configure时使用--enable-libopus
cd ~/ffmpeg_sources
curl -O -L https://archive.mozilla.org/pub/opus/opus-1.2.1.tar.gz
tar xzvf opus-1.2.1.tar.gz
cd opus-1.2.1
./configure --prefix="$FFMPEG_ROOT" --disable-shared
make && make install

# libogg,Ogg比特流库。libtheora和libvorbis的必要依赖。
cd ~/ffmpeg_sources
curl -O -L http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.gz
tar xzvf libogg-1.3.3.tar.gz
cd libogg-1.3.3
./configure --prefix="$FFMPEG_ROOT" --disable-shared
make && make install

# libvorbis,Vorbis音频编码器。依赖libogg。需要ffmpeg在./configure时使用--enable-libvorbis
cd ~/ffmpeg_sources
curl -O -L http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz
tar xzvf libvorbis-1.3.5.tar.gz
cd libvorbis-1.3.5
./configure --prefix="$FFMPEG_ROOT" --with-ogg="$FFMPEG_ROOT" --disable-shared
make && make install

# libtheora,Theora视频编码器。依赖libogg。需要ffmpeg在./configure时使用--enable-libtheora
cd ~/ffmpeg_sources
curl -O -L https://ftp.osuosl.org/pub/xiph/releases/theora/libtheora-1.1.1.tar.gz
tar xzvf libtheora-1.1.1.tar.gz
cd libtheora-1.1.1
./configure --prefix="$FFMPEG_ROOT" --with-ogg="$FFMPEG_ROOT" --disable-shared
make && make install

# libvpx,VP8/VP9视频编码/解码器。需要ffmpeg在./configure时使用--enable-libvpx
cd ~/ffmpeg_sources
git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
cd libvpx
./configure --prefix="$FFMPEG_ROOT" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
make && make install

# 1、编译安装
cd ~/ffmpeg_sources
curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
PKG_CONFIG_PATH="$FFMPEG_ROOT/lib/pkgconfig" ./configure \
  --prefix="$FFMPEG_ROOT" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$FFMPEG_ROOT/include" \
  --extra-ldflags="-L$FFMPEG_ROOT/lib" \
  --extra-libs=-lpthread \
  --extra-libs=-lm \
  --enable-gpl \
  --enable-libfdk_aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libvorbis \
  --enable-libtheora \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree
make && make install
hash -r

# 2、动态链接库
echo '/usr/local/ffmpeg/lib' >> /etc/ld.so.conf
ldconfig

# 3、环境变量
echo 'export FFMPEG_ROOT="/usr/local/ffmpeg"' >> /etc/profile
echo 'export PATH="$FFMPEG_ROOT/bin:$PATH"' >> /etc/profile
source /etc/profile

# 4、测试运行
ffmpeg -version


你可能感兴趣的:(Linux,ffmpeg)