码迷,mamicode.com
首页 > 系统相关 > 详细

linux 编译ffmpeg 支持x264, x265

时间:2015-06-02 20:10:02      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:ffmpeg   x264   265   

1. 前言

本教程涉及的ffmpeg, x264, x265


2. 环境依赖

2.1 删除系统中安装的ffmpeg等库

<span style="font-size:14px;">sudo apt-get --purge remove ffmpeg mplayer x264 x265</span>

2.2 安装依赖库

<span style="font-size:14px;">sudo apt-get update
sudo apt-get -y --force-yes install autoconf automake build-essential libass-dev libfreetype6-dev libgpac-dev   libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev   libxcb-xfixes0-dev pkg-config texi2html zlib1g-dev</span>

注: 服务器版本可忽略

libsdl1.2-dev libva-dev libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev


2.3 下载源代码

(1) ffmpeg

<span style="font-size:14px;">git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg</span>

(2) x264
<span style="font-size:14px;"></span><pre name="code" class="plain"><pre name="code" class="plain"><pre name="code" class="plain">git clone git://git.videolan.org/x264.git




(3) x265
<span style="font-size:14px;"></span><pre name="code" class="plain">hg clone https://bitbucket.org/multicoreware/x265


(4) yasm

yasm 是x86平台的一个汇编优化器, 能够加快ffmpeg x264的编译

<span style="font-size:14px;">wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xzvf yasm-1.3.0.tar.gz
</span>

3. 编译

3.1 配置编译输出目录

<span style="font-size:14px;">export FFMPEG_PATH="YOUR_PATH"
export PATH="$FFMPEG_PATH/bin:$PATH"</span>
例如我输出目录为$HOME/ffmpeg_2.6.3/build_out

那么:

<span style="font-size:14px;">export FFMPEG_PATH="$HOME/ffmpeg_2.6.3/build_out"</span>

3.1 yasm

<span style="font-size:14px;"></span><pre name="code" class="plain">cd yasm-1.3.0
./configure --prefix="$HOME/" 
make
make install

或者安装已有的库(yasm version ≥ 1.3.0)

<span style="font-size:14px;">sudo apt-get install yasm</span>


3.2 x264

在配置ffmpeg config时需要加入--enable-gpl --enable-libx264

<span style="font-size:14px;"><tt>cd x264*
./configure --prefix="$FFMPEG_PATH" --enable-shared --enable-static
make -j4
make install
make clean</tt></span>
或者安装已有的库(yasm version ≥ 1.3.0)
<span style="font-size:14px;"><tt>sudo apt-get install libx264-dev</tt></span>


3.3 x265

<span style="font-size:14px;"><tt>cd x265/build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$FFMPEG_PATH" -DENABLE_SHARED:bool=off ../../source
make -j4
make install
make clean
</tt></span>

3.4 aac

在配置ffmpeg config时需要加入 --enable-libfdk_aac (如果开启--enable-gpl同时需要开启 --enable-nonfree )

<span style="font-size:14px;"><tt>PKG_CONFIG_PATH="$FFMPEG_PATH/lib/pkgconfig" ./configure   --prefix="$FFMPEG_PATH"   --pkg-config-flags="--static"   --extra-cflags="-I$FFMPEG_PATH/include"   --extra-ldflags="-L$FFMPEG_PATH/lib"   --enable-gpl   --enable-libass   --enable-libfaac   --enable-libfreetype   --enable-libmp3lame   --enable-libtheora   --enable-libvorbis   --enable-libx264   --enable-libx265   --enable-nonfree   --enable-shared   --enable-postproc   --enable-x11grab   --enable-bzlib   --enable-libxvid   --enable-zlib   --disable-debug </tt></span>

4. 将ffmpeg添加到环境变量

4.1 将ffmpeg添加到环境变量

<span style="font-size:14px;"><tt>vim ~/.bashrc</tt></span>
在最后添加


<span style="font-size:14px;"><tt>export FFMPEG_PATH="/home/guohe/workspace/ffmpeg_2.6.3/build_out"
export PATH="$FFMPEG_PATH/bin:$PATH"</tt></span>

4.2 添加链接库

编译完成之后调用 ffmpeg 会出现 error while loading shared libraries: xxx

解决这种问题有2中方法:

(1) 修改/etc/ld.so.conf

<span style="font-size:14px;"><tt>vim /etc/ld.so.conf</tt></span>

在最后添加
$FFMPEG_PATH/lib

然后执行

<span style="font-size:14px;"><tt>sudo ldconfig</tt></span>

(2) 修改LD_LIBRARY_PATH

<span style="font-size:14px;"><tt>vim ~/.bashrc</tt></span>
在最后添加
<span style="font-size:14px;"><tt>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$FFMPEG_PATH/ib</tt></span>







linux 编译ffmpeg 支持x264, x265

标签:ffmpeg   x264   265   

原文地址:http://blog.csdn.net/matrix_laboratory/article/details/46334137

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!