Ubuntu Desktop 编译 ffmpeg (简略的写写)

关于ffmpeg

FFmpeg是一個自由軟體,能够執行音訊和視訊多種格式的錄影、轉檔、串流功能,包含了libavcodec——這是一個用於多個專案中音訊和視訊的解碼器函式庫,以及libavformat——一個音訊與視訊格式轉換函式庫。html

--以上内容摘自 https://zh.wikipedia.org/wiki/FFmpeggit

 

环境

Ubuntu Desktop 16.04 LTSgithub

 

FFmpeg配置

1.关于yasm

在安装ffmpeg以前,仍是先安装下yasm吧shell

(其实,也能够不装,在编译ffmpeg的时候加上 --disable-yasm 参数便可)编程

那么yasm是作什么用的呢?ubuntu

Yasm is a complete rewrite of the NASM assembler under the “new” BSD License (some portions are under other licenses, see COPYING for details).架构

Yasm currently supports the x86 and AMD64 instruction sets, accepts NASM and GAS assembler syntaxes, outputs binary, ELF32, ELF64, 32 and 64-bit Mach-O, RDOFF2, COFF, Win32, and Win64 object formats, and generates source debugging information in STABS, DWARF 2, and CodeView 8 formats.ide

Yasm can be easily integrated into Visual Studio 2005/2008 and 2010 for assembly of NASM or GAS syntax code into Win32 or Win64 object files.ui

以上是yasm官网的解释spa

其实就是英特尔X86架构下的汇编器和反汇编器,能够用来编写16位、32位(IA-32)和64位(x86-64)的程序。

 

2.安装yasm

wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar -zxf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make
sudo make install
sudo ldconfig

 

3.编译ffmpeg

tar -jxf ffmpeg-4.0.1.tar.bz2 #我这里已经下载好了
cd ffmpeg-4.0.1/
./configure --prefix=/usr/local/ffmpeg --enable-shared
make
sudo make install

--enable-shared 参数听说是容许其编译产生动态库,在之后的编程中要用到这个几个动态库。

 

4.给ffmpeg设置环境变量

sudo vi /etc/profile

加入如下内容:

FFMPEG=/usr/local/ffmpeg
export PATH="$FFMPEG/bin:$PATH"

使修改当即生效

source /etc/profile6

 

5.为了防止执行程序找不到库文件

能够将/usr/local/ffmpeg/lib目录设置到LD_LIBRARY_PATH环境变量

 

6.找不到库文件

环境变量设置完成后

ffmpeg -version

检查下安装是否有问题

正常状况是显示这个

ffmpeg -version
ffmpeg version 4.0.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr/local/ffmpeg --enable-shared
libavutil      56. 14.100 / 56. 14.100
libavcodec     58. 18.100 / 58. 18.100
libavformat    58. 12.100 / 58. 12.100
libavdevice    58.  3.100 / 58.  3.100
libavfilter     7. 16.100 /  7. 16.100
libswscale      5.  1.100 /  5.  1.100
libswresample   3.  1.100 /  3.  1.100

 

若出现 ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file 错误

修改/etc/ld.so.conf 在最后一行加上

/usr/local/ffmpeg/lib

例如

include /etc/ld.so.conf.d/*.conf
/usr/local/ffmpeg/lib #在后面加上这段

再执行

sudo ldconfig 

并修改 /usr/local/ffmpeg/lib目录下的文件权限为777

检查下库是否加载到

ldd $(which ffmpeg)
ffmpeg -version

 

我是在Ubuntu的桌面版安装的,若是你是server版,可能会缺乏不少库。请参考这里 在Ubuntu Server上编译FFmpeg

比较完整的编译安装,请参考官网文档 Compile FFmpeg for Ubuntu, Debian, or Mint

相关文章
相关标签/搜索