从零开始编译属于你的FFmpeg
一、前提:
编译FFmpeg可以是初学者,尤其是对C语言项目,Linux编译不熟悉的的初学者的一道门槛。
我曾经找过很多博客,文章,有些能编译成功,有些则不能。编译通过,能够运行也是云里雾里的。其实最好最权威的编译教程应该是官方提供的。
在这里:
http://trac.ffmpeg.org/wiki/CompilationGuide
强烈建议参考官网步骤一步步编译,本文只是作者的操作记录而已。
注意:如果你只需要FFmpeg的安装包或者可运行的二进制文件,你不需要自己编译源代码,下面的地址有提供:
http://ffmpeg.org/download.html#LinuxBuilds
1.1 下面是我的编译环境:
- Ubuntu 14.04
- ffmpeg-3.3.1 稳定版,下载地址:http://ffmpeg.org/releases/ffmpeg-3.3.1.tar.bz2
- 务必确定自己的 apt 的源是国内的镜像地址,比如阿里云的源,否则apt安装依赖库卡的要死~
二、准备步骤:
2.1 检查自己的gcc版本
输入命令:
gcc -v
检查结果:gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
原因
官方提示:
Linux
Attention: If you are using gcc-4.2 please read ticket 1464 first, and try to update your compiler. A message to that effect is printed on running configure off the master branch.
Compiling FFmpeg on Ubuntu / Debian / Mint
Compiling FFmpeg on CentOS / RHEL / Fedora
小结:gcc-4.2 好像有bug,所以避免使用这个版本的gcc编译
2.2 获取安装编译需要的依赖(Get the Dependencies)
参考官方指南:
Copy and paste the whole code box for each step. First install the dependencies:(复制粘贴下面的命令,安装依赖)
sudo apt-get update
sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev \
libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \
libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev
//Note: Server users can omit the ffplay and x11grab dependencies: libsdl2-dev libva-dev libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev.
小结:这里只需要复制粘贴命令到bash 里面执行即可
2.3 创建FFmpeg源码目录:
Now make a directory for the source files that will be downloaded later in this guide:
(在home/your_user_name 创建ffmpeg_sources这个目录用于下载FFmpeg的源码)
mkdir ~/ffmpeg_sources
三、编译与安装
3.1 官方教程:
You can compile ffmpeg to your liking. If you do not require certain encoders you may skip the relevant section and then remove the appropriate ./configure option in FFmpeg. For example, if libopus is not needed, then skip that section and then remove --enable-libopus from the Install FFmpeg section.
This guide is designed to be non-intrusive and will create several directories in your home directory:
ffmpeg_sources – Where the source files will be downloaded. This can be deleted if desired when finished with the guide.
ffmpeg_build – Where the files will be built and libraries installed. This can be deleted if desired when finished with the guide.
bin – Where the resulting binaries (ffmpeg, ffplay, ffserver, x264, and yasm) will be installed.
You can easily undo any of this as shown in Reverting Changes Made by This Guide.
中文翻译:
您可以根据自己的喜好编译ffmpeg。如果您不需要某些编码器,可以跳过下面指南中关于这个编码器的部分,然后在FFmpeg 中删除相应的./configure选项。例如,如果不需要libopus,请跳过该部分,然后从Install FFmpeg部分删除--enable-libopus。
本指南希望做到非侵入性,并只会在您的主目录(/home/your_user_name)中创建几个目录
ffmpeg_sources - 源文件将在哪里下载。如果需要,可以在导板完成后删除。
ffmpeg_build - 文件将在哪里构建和库安装。如果需要,可以在导板完成后删除。
bin - 将安装结果二进制文件(ffmpeg,ffplay,ffserver,x264和yasm)。
您可以轻松地撤消任何这一点,如“本指南”中的“ 恢复更改”所示。
3.2 安装yasm 用于FFmpeg官方教程:
Yasm
- 直接安装yasm
An assembler for x86 optimizations used by x264 and FFmpeg. Highly recommended or your resulting build may be very slow.
If your repository provides yasm version ≥ 1.2.0 then you can install that instead of compiling:
sudo apt-get install yasm
// 不直接安装yasm,你可以选择编译yasm源码,安装(建议直接安装即可,跳过这里)
//Otherwise you can compile:
cd ~/ffmpeg_sources
wget 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
中文翻译:
Yasm
一个在x86平台的优化的汇编程序,用于 x264库和FFmpeg。强烈推荐使用,否则你生成编码的速度可能非常慢
如果你的系统提供版本号>1.02.0的yasm,你可以直接安装,否则你需要自己编译新版本的yasm
3.1.1 关于yasm的补充说明
yasm是汇编编译器,因为ffmpeg中为了提高效率用到了汇编指令,比如MMX和SSE
Ubuntu下直接使用:sudo apt-get install yasm 安装
小结:
这里需要安装yasm,我采取直接安装的方法,省去了自己编译源码使用的麻烦。实测Ubuntu 14.04 apt-get install yasm的版本是1.2.0的
3.3 下载FFmpeg各种编码器(可选,我自己跳过这一步,切记如果你需要下面的编码器,务必自己下载)
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.
If your repository provides libx264-dev version ≥ 118 then you can install that instead of compiling:
sudo apt-get install libx264-dev
//Otherwise you can compile:
cd ~/ffmpeg_sources
wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
tar xjvf last_x264.tar.bz2
cd x264-snapshot*
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --disable-opencl
PATH="$HOME/bin:$PATH" make
make install
libx265
H.265/HEVC video encoder. See the H.265 Encoding Guide for more information and usage examples.
If your repository provides libx265-dev version ≥ 68 then you can install that instead of compiling:
sudo apt-get install libx265-dev
//Otherwise you can compile:
sudo apt-get install cmake mercurial
cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make
make install
libfdk-aac
AAC audio encoder. See the AAC Audio Encoding Guide for more information and usage examples.
Requires ffmpeg to be configured with --enable-libfdk-aac (and --enable-nonfree if you also included --enable-gpl).
If your repository provides libfdk-aac-dev then you can install that instead of compiling:
sudo apt-get install libfdk-aac-dev
//Otherwise you can compile:
cd ~/ffmpeg_sources
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 --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
libmp3lame
MP3 audio encoder.
Requires ffmpeg to be configured with --enable-libmp3lame.
If your repository provides libmp3lame-dev version ≥ 3.98.3 then you can install that instead of compiling:
sudo apt-get install libmp3lame-dev
//Otherwise you can compile:
sudo apt-get install nasm
cd ~/ffmpeg_sources
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix="$HOME/ffmpeg_build" --enable-nasm --disable-shared
make
make install
libopus
Opus audio decoder and encoder.
Requires ffmpeg to be configured with --enable-libopus.
If your repository provides libopus-dev version ≥ 1.1 then you can install that instead of compiling:
sudo apt-get install libopus-dev
//Otherwise you can compile:
cd ~/ffmpeg_sources
wget http://downloads.xiph.org/releases/opus/opus-1.1.4.tar.gz
tar xzvf opus-1.1.4.tar.gz
cd opus-1.1.4
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
libvpx
VP8/VP9 video encoder and decoder. See the VP8 Video Encoding Guide for more information and usage examples.
Requires ffmpeg to be configured with --enable-libvpx.
If your repository provides libvpx-dev version ≥ 0.9.7 then you can install that instead of compiling:
sudo apt-get install libvpx-dev
//Otherwise you can compile:
cd ~/ffmpeg_sources
wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.6.1.tar.bz2
tar xjvf libvpx-1.6.1.tar.bz2
cd libvpx-1.6.1
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests
PATH="$HOME/bin:$PATH" make
make install
小结:
FFmpeg 默认支持部分编码器,但是有一些并不属于FFmpeg的编码器,需要我们自己按照官方的指南下载源码编译,FFMPEG才能支持。由于暂时不学习编码器,~这一部分可耻跳过。注意这里跳过以后 下面的编译参数需要同步修改,去掉不支持的编码器
3.4 下载并编译FFmpeg的源码:
官方指南:
ffmpeg
cd ~/ffmpeg_sources
wget http://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" \
--bindir="$HOME/bin" \
--enable-gpl \
--enable-libass \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libtheora \
--enable-libvorbis \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-nonfree
PATH="$HOME/bin:$PATH"
make
make install
hash -r
小结:官方提供的配置 --enable-xxxxx 这种选项,如果你没有需要这一个编码器,或者压根就没下载安装,把这个参数去掉即可
更新 FFmpeg (Updating FFmpeg )
Development of FFmpeg is active and an occasional update can give you new features and bug fixes. First you need to delete (or move) the old files:
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffplay,ffserver,x264,x265}
Now just follow the guide from the beginning.
撤销所有的上面的指南对系统的所有改动(Reverting Changes Made by This Guide)
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffplay,ffserver,x264,x265,nasm}
sudo apt-get autoremove autoconf automake build-essential cmake libass-dev libfreetype6-dev \
libmp3lame-dev libopus-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev \
libvorbis-dev libvpx-dev libx264-dev libxcb1-dev libxcb-shm0-dev ibxcb-xfixes0-dev mercurial texinfo zlib1g-dev
sed -i '/ffmpeg_build/c\' ~/.manpath
hash -r
个人实践补充:
第一步下载并解压源码:
wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjvf ffmpeg-snapshot.tar.bz2
下载源码的方式很多,官方指南中的 使用wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2t 去官方网址下载发型版本的快照版本
恩,直接到官网 http://ffmpeg.org/download.html#LinuxBuilds 下载源码压缩包,在复制粘贴到ffmpeg_sources也是一样的。
如果是正式产品使用可以考虑使用发行版本中的稳定版,比如这个:
http://ffmpeg.org/releases/ffmpeg-3.3.1.tar.bz2 截止2017.5.31
我是在windows下使用百度云离线下载了ffmpeg-3.3.1.tar.bz2 ,再copy到linux下的,比较快~
开始编译:
由于上面我没有下载部分编码器,所以在官方的./configure 后面的参数做了修改,去掉了不支持编码器
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" \
--bindir="$HOME/bin" \
--enable-gpl \
--enable-libass \
--enable-libfreetype \
--enable-libtheora \
--enable-libvorbis \
--enable-nonfree
PATH="$HOME/bin:$PATH" make
make install
hash -r
安装了h264 +aac编码库后,配置的参数:
/configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--bindir="$HOME/bin" \
--enable-gpl \
--enable-libass \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libtheora \
--enable-libvorbis \
--enable-libx264 \
--enable-nonfree
编译成功,在当前用户的 /home/用户名下,
可以找到 bin 文件夹 ffmpeg_build 文件夹
bin文件夹
ffmpeg的几个二进制可执行文件(程序),每一个都可以直接运行
ffmpeg_build 文件夹
FFmpeg编译中产生的链接库,头文件,还有一些其他文档,如果你需要对FFmpeg二次开发,需要使用到这里的东西
四、总结:
不要在浪费时间去百度各种FFmpeg编译教程了,直接官网走下来,行云流水,如果你遇到问题,可以看看我的文章~。
从零开始编译属于你的FFmpeg的更多相关文章
- ffmpeg源码编译安装(Compile ffmpeg with source) Part 2 : 扩展安装
在Ubuntu,Debian,Mint上编译ffmpeg 本文主要为在Ubuntu,Debian和Mint上编译安装ffmpeg和库文件以及一些扩展的编解码器.当然这与从源中安装无关. 请首先看一下通 ...
- 用mingw-w64 编译 x64 位的ffmpeg
http://blog.sina.com.cn/s/blog_6125d067010168dt.html 工作中用到了ffmpeg x64. 发现编译出来x64的ffmpeg,很不容易.特记录下来.原 ...
- Linux下编译带x264的ffmpeg的配置方法,包含SDL2
一.环境准备 ffmpeg下载:http://www.ffmpeg.org/download.html x264下载:http://download.videolan.org/x264/snapsho ...
- ffmpeg源码编译安装(Compile ffmpeg with source) Part 1 : 通用部分
本页内容包含了在Unix/Linux中用源码包编译的通用的结构 可能不仅仅适用于ffmpeg 为啥使用源码包编译 编译源码可以扩展功能, 实现相对于自己平台的最优化, 还可以自定义的修改 概述 大部分 ...
- Ubuntu/Debian下编译PC版的ffmpeg
1.安装git: 在命令行下执行 sudo apt-get install git-core 2.下载最新版本的ffmpeg: git clone git://source.ffmpeg.org/ff ...
- Msys2+mingw-w64 编译VS2013使用的ffmpeg静态库注意事项
1.环境准备 第一步:从http://sourceforge.net/projects/msys2/下载msys2的安装程序安装msys2; 第二步:通过msys2的包管理工具pacman安装ming ...
- Ubuntu编译Android使用的FFmpeg
本文介绍在Ubuntu平台编译FFmpeg库,用于Android使用.前提需要配置好NDK的环境.可以参考之前的文章Android NDK环境搭建. 下载FFmpeg 在官网下载FFmpeg源码,ht ...
- FFmpeg编译:mac下编译iOS平台的FFmpeg库(支持armv7, arm64, i386, x86_64)
环境:FFmpeg 3.4.6Xcode 10.3macOS 10.14.6iOS SDK 12.4 一.准备工作 1. 下载FFmpeg我这里使用的是3.4.6版本的FFmpeg,可以从FFmpeg ...
- 从零开始编译Poco C++和VS2015环境配置
Poco C++是一个C++的开源框架,详细介绍可以问百度介绍更详细,这里我就记录下我从零编译poco-1.9.0和配置 VS2015的环境,以备不时之需. 步骤:一.安装cmake: 二.编译poc ...
随机推荐
- 【python】10分钟教你用Python做个打飞机小游戏超详细教程
更多精彩尽在微信公众号[程序猿声] 我知道你们一定想先看效果如何 00 目录 整体框架 开始之前-精灵类Sprite 子弹类class Bullet 玩家飞机类class Player 敌机类clas ...
- TX1 文字界面启动与root用户自动登录设置
设置默认文字启动界面 更改/boot/extlinux/extlinux.conf文件,在最后一行的末尾添加 text. 设置自动登录 在/etc/init/tty1.conf文件末尾添加: exec ...
- swift pod 第三方库异常的处理
Xcode8—Swift开发使用Cocoapods引入第三方库异常处理方法 参考: http://www.jianshu.com/p/23f13be525a0 //podfile文件如下 platf ...
- phpmyadmin更改用户名和密码
我是用的xampp集成环境,wampp也差不多.另外没有配图,希望读者可以在实践的过程中有所思考,本文的主旨就是:找一个不叫root但和root一样厉害的人来管理数据库. 1,做个准备 首先创建一个和 ...
- MAC office2016 安装及激活(试了一下,靠谱, 非常感谢原作者)
转载地址:https://blog.csdn.net/jxq0816/article/details/77248462 非常感谢原作者. 一.安装包下载地址 http://officecdn.micr ...
- Django Cannot assign "A1": "B1" must be a "C1" instance. 错误信息
常见报错 Cannot assign “A1”: “B1” must be a “C1” instance. 告诉我们 必须使用 C1 模型类的 实例,而不是具体的参数值. 这个错误信息,是我写入数据 ...
- PHP报错
php.ini ; 错误日志 log_errors = On ; 显示错误 display_errors = Off ; 日志路径 error_log = "/usr/local/lnmp/ ...
- 神马是代码简单的cmd模式,这就是!
小狼正在研究 “怎么查找连在一起的同色方块?”算法问题 ,突然感觉我是不是需要一种开发模式,不然感觉自己的代码好乱的. 可能是研究算法吧,导致小狼的思路特别清晰,加上也用了差不多1年的nodejs.s ...
- 【研究】Struts2-048漏洞
1.1 漏洞背景 2017年7月7日,Apache Struts发布最新的安全公告,Apache Struts2-strus1-plugin插件存在远程代码执行的高危漏洞,漏洞编号为CVE-2017- ...
- Python入门笔记——(1)数字与表达式
一.算术运算 整除:// 取余:% 乘方:** (a ** b = pow(a, b)) 十六进制表示:0x...,八进制表示0... round(x [, n]):对x从小数点第n位取四舍五入结果, ...