相对正经的ffmpeg及X264插件安装

ffmpeg以及x264插件已经安装过很多次,环境不同遇到问题不同基本根据错误都能解决,今天的一台机子原装过ffmpeg因为业务需要扩展下x264用来预处理视频,根据以往经验下包解压编译配置再重新安装ffmpeg,今天一直出幺蛾子安装都不顺利原来的文档也没排上用场,搜搜帖子发现大多互相copy东拼西凑始终没能解决问题,折腾一晚上最终还是官网看看吧,把已安装的清理干净,因为都是通过编译安装用的操作系统centos,清理时候可以whereis ffmpeg 或者 find / -name ‘ffmpeg’ 找到文件清理,包括x264 ysam也一样处理,清理干净可以根据ffmpeg官网推荐的系统文档查看,以下是把centos/liunx 当下来可以参考(根据选择安装,我安装的时候遇到nasm安装之后还是不能用,后来就调了配置不调用,有空在研究研究),不过这个API里面也有个别小错误安装的时候认真点就能发现,记录下以后留用,

ps yum出现“No module named yum”错误 而且和python有关,后来发现是同事部署识别模型升级了python版本,yum本身也只对2.7以下版本有用,所以此处要调整/usr/bin/yum文件,将第一行由“#!/usr/bin/python”改为“#!/usr/bin/python【2.6】” 这个【】不需要的,要结合你系统原版本号,查看机器有哪些版本的python 可以到/usr/bin去找

Ps 通用是centos的6.5系统版本可能不云服务器商还是有差异的,这次安装是迅达云,之前阿里云还有自己官网下的版本都安装过。

Compile FFmpeg on CentOS

Get the Dependencies

Note: The # indicates that the command should be executed as superuser or root and is only required in this guide for the yum command.

Get the dependencies. These are required for compiling, but you can remove them when you are done if you prefer (except make; it should be installed by default and many things depend on it).

# yum install autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel

In your home directory make a new directory to put all of the source code into:

mkdir ~/ffmpeg_sources

NASM

An assembler used by some libraries. Highly recommended or your resulting build may be very slow.

cd ~/ffmpeg_sources
curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2
tar xjvf nasm-2.13.02.tar.bz2
cd nasm-2.13.02
./autogen.sh
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install

Yasm

An assembler used by some libraries. Highly recommended or your resulting build may be very slow.

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="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install

libx264

H.264 video encoder. See the H.264 Encoding Guide for more information and usage examples.

Requires ffmpeg to be configured with –enable-gpl –enable-libx264.

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

Warning: If you get Found no assembler. Minimum version is nasm-2.13 or similar after running ./configure then the outdated nasm package from the repo is installed. Run yum remove nasm && hash -r and x264 will then use your newly compiled nasm instead. Ensure environment is able to resolve path to nasm binary.

FFmpeg

cd ~/ffmpeg_sources
curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --extra-libs=-lpthread \
  --extra-libs=-lm \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-libfreetype \
  --enable-libx264 \
  --enable-nonfree
make
make install
hash -r

Compilation is now complete and ffmpeg (also ffprobe, ffserver, lame, and x264) should now be ready to use. The rest of this guide shows how to update or remove FFmpeg.

Tip: Keep the ffmpeg_sources directory and all contents if you intend to update as shown below. Otherwise you can delete this directory.

    原文作者:wszn
    原文地址: https://zhuanlan.zhihu.com/p/37403661
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞