FFmpeg : Compiling FFmpeg

https://trac.ffmpeg.org/wiki#CompilingFFmpeg

Why to compile from source

Binary packages are usually provided by third party packagers for many platforms, but in some cases they are not an option for several reasons:

  • The binary packages is outdated or contains critical bugs or is missing required features which are available in the later version of the software.
  • You need to customize the build, for example to support a particular installation layout, to get platform-specific optimizations or to link against particular libraries which are not supported in the binary package.
  • You want to customize the software by editing the source code.
    In all these cases building a package from source looks like the best solution.

Overview

Most source packages installation assumes the following steps:

  • configuration (with a configure script)
  • compilation (with make)
  • installation (with make install)

Configuration will allow creation of the necessary files required by the following compilation step, and is done through a configure script usually provided by the source package. During configuration it is possible to define the install prefix and the enabled components.

Compilation usually consists of running make after the configuration step completes. In this phase the required libraries and binaries are generated.

Installation will install binaries and libraries in the path specified during the configuration step. Note that this step is not really required since you can use the binaries compiled in the compilation path.

For a vanilla compilation and install you will usually run the following commands:

./configure
make
make install

This will compile the project files in the source directory, and will install the libraries in /usr/local. The third step may require super-user rights (so it may need to be replaced by sudo make install), since /usr/local cannot be modified by regular users.

Install path

A package consists of several related files which are installed in several directories.
The configure step usually allows the user to specify the so-called install prefix, and is usually specified through the configure option configure --prefix=PREFIX, where PREFIX usually is by default /usr/local. The prefix specifies the common directory where all the components are installed.

The following directories are usually involved in the installation:

  • PREFIX/bin: contains the generated binaries (e.g. ffmpeg, ffplay, ffprobe etc. in the case of FFmpeg)
  • PREFIX/include: contains the library headers (e.g. libavutil/avstring.h, libavcodec/avcodec.h, libavformat/avformat.h etc. in case of FFmpeg) required to compile applications linked against the package libraries
  • PREFIX/lib: contains the generated libraries (e.g. libavutil, libavcodec, libavformat etc. in the case of FFmpeg)
  • PREFIX/share: contains various system-independent components; especially documentation files and examples

By specifying the prefix it is possible to define the installation layout.

By using a shared prefix like /usr/local/, different packages will be installed in the same directory, so in general it will be more difficult to revert the installation.

Using a prefix like /opt/PROJECT/, the project will be installed in a dedicated directory, and to remove from the system you can simply remove the /opt/PREFIX path. On the other hand, such installation will require to edit all the environment variables to point to the custom path.

Environment variables

Several variables defined in the environment affect your package install.
In particular, depending on your installation prefix, you may need to update some of these variables in order to make sure that the installed components can be found by the system tools.

The list of environment variables can be shown through the command env.

A list of the affected variables follows:

PATH: defines the list of :-separated paths where the system looks for binaries. For example if you install your package in /usr/local/, you should update the PATH so that it will contain /usr/local/bin. This can be done for example through the command export PATH=/usr/local/bin:PATH. LD_LIBRARY_PATH: contains the :-separated paths where the system looks for libraries. For example if you install your package in /usr/local/, you should update the LD_LIBRARY_PATH so that it will contain /usr/local/lib. This can be done for example through the command export LD_LIBRARY_PATH=/usr/local/lib:LD_LIBRARY_PATH. This variable is sometimes deprecated in favor of the use of ldconfig.
CFLAGS: contains flags used by the C compiler, and usually includes preprocessing directives like -IPREFIX/include or compilation flags. Custom CFLAGS are usually prefixed to the source package compiler flags by the source package build system. Alternatively many build systems allow to specify the configure option -extra-cflags.
LDFLAGS: these are directives used by the linker, and usually include linking directives like -LPREFIX/lib needed to find libraries installed in custom paths. Custom LDFLAGS are usually prefixed to the source package linker flags by the source package build system. Alternatively, many build systems allow to specify the configure option -extra-ldflags.
PKG_CONFIG_PATH: contains the :-separated paths used by pkg-config to detect the pkg-config files used by many build systems to detect the custom CFLAGS/LDFLAGS used by a specific library.
In case you installed a package in a non standard path, you need to update these environment libraries so that system tools will be able to detect the package components. This is especially required when running a configure script for a package relying on other installed libraries/headers/tools.

Environment variables are usually defined in the profile file, for example .profile defined in the user directory for sh/bash users, and in /etc/profile. This file can be edited to permanently set the custom environment. Alternatively, the variables can be set in a script or in a particular shell session.

Remember to export the variables to the child process, e.g. using the export command. Read the fine documentation of your shell for more detailed information.

LD_LIBRARY_PATH and ldconfig

When you link a library depending on other libraries
the tools will look for the libraries to link in a list of standard paths (typically /usr/lib) and in other paths which are set in the system.
Some systems rely on the LD_LIBRARY_PATH library. Alternatively, you may set the global path through the ldconfig utility, which is done editing the /etc/ld.so.conf system configuration file.
Note that on some systems the LD_LIBRARY_PATH variable defined in the shell profile is reset for security reasons, so you may need to reset it per-session or per-script.

Configuration prerequisites and distribution packages

When configuring a package, you may be required to check for the presence of some required libraries and headers. Many distribution will provide binary packages for the required libraries, so you may rely on these packages rather than compile and install from scratch.

In general, for a library you will need the library package and the development package associated to that library. The library package contains only the library, the development package will contain also the headers and the other files which are required for compiling a package depending on those libraries. On Debian-based distribution systems, the development packages have the -dev suffix, on RedHat?-based distribution systems, they have the -devel suffix. Some distributions, such as Arch Linux, do not separate their packages and the standard package will also contain the necessary development files.

For example on Debian, if you want to configure FFmpeg with --enable-libmp3lame, you will need to install the libmp3lame development package named libmp3lame-dev.

You should also make sure that the library version provided by the distribution is compatible with the one required by the configured source package. If the required package is more recent than the library version provided by your distribution, you may need to install from source.

Post-installation troubleshooting

First of all verify that the binaries, headers and libraries have been installed in the supposed location (along the PREFIX path). To verify the binaries install you can simply run a command with the tool name, and verify the complete path with which -a, which will show all the tools with the given name available in the system.

Extra care must be paid in case you have several installations of the same package in order to avoid conflicts.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,219评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,363评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,933评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,020评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,400评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,640评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,896评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,597评论 0 199
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,327评论 1 244
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,581评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,072评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,399评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,054评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,083评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,849评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,672评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,585评论 2 270

推荐阅读更多精彩内容

  • 有人问我还是原来的我吗 ?我该怎么说呢 ,就像以前我爱喝可乐 ,但现在我情愿喝白开水 。以前和我天天在一起,感情好...
    W落月屋梁B阅读 160评论 0 0
  • 慢慢的,我发现我对事物的思考越来越少。 最近,脑子经常处于拒绝思考的状态,只能做简单的机械运动,一点儿不都想考虑背...
    张文昭阅读 923评论 0 0
  • 闫荣:产品战略规划十步法 ——《产品心经》 什么是战略?战略的本质就是选择,就是有所为有所不为。 通俗一点解释,战...
    鼎优威腾智库阅读 583评论 0 0
  • 本文主要通过RSA加解密实践,来讲述不对称秘钥的特点。 不对称秘钥和RSA 不对称秘钥算法,也叫公钥密码算法。不对...
    redexpress阅读 1,529评论 0 1