1. 程式人生 > >Ubuntu16.04 LTS 安裝FFmpeg

Ubuntu16.04 LTS 安裝FFmpeg

首先在官網上下載最新的FFmpeg壓縮包:

壓縮包的格式是.tar.bz2,解壓壓縮檔案,以ffmpeg-3.3.4為例,這裡需要用到的命令是:

$ tar -jxvf ffmpeg-3.3.4.tar.bz2

然後到解壓下的資料夾下檢視INSTALL.md

$ cat INSTALL.md 

#Installing FFmpeg:


1. Type `./configure` to create the configuration. A list of configure
options is printed by running `configure --help`.


    `configure` can be launched from a directory different from the FFmpeg
sources to build the objects out of tree. To do this, use an absolute
path when launching `configure`, e.g. `/ffmpegdir/ffmpeg/configure`.


2. Then type `make` to build FFmpeg. GNU Make 3.81 or later is required.


3. Type `make install` to install all binaries and libraries you built.


NOTICE
------


 - Non system dependencies (e.g. libx264, libvpx) are disabled by default.
很清楚地說明了上述三個步驟。

所以執行第一步:

$ ./configure

提示:yasm/nasm not found or too old. Use --disable-yasm for a crippled build.

發現沒有安裝yasm,所以安裝yasm:

$ sudo apt-get install yasm
安裝後重新執行上述第一步操作,生成配置檔案

然後進行編譯:

$ make
編譯時會出現一些warning,應該是可以忽略的,只要最後編譯通過並沒有報錯,編譯後安裝:
$ make install
發現問題:

mkdir: cannot create directory ‘/usr/local/share/man/man1’: Permission denied
doc/Makefile:155: recipe for target 'install-man' failed
make: *** [install-man] Error 1

這個錯誤的原因是:建立資料夾是沒有 許可權,所以用超級使用者身份執行:

$ sudo make install
安裝成功後檢視版本:
$ ffmpeg -version

ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
configuration: 
libavutil      55. 58.100 / 55. 58.100
libavcodec     57. 89.100 / 57. 89.100
libavformat    57. 71.100 / 57. 71.100
libavdevice    57.  6.100 / 57.  6.100
libavfilter     6. 82.100 /  6. 82.100
libswscale      4.  6.100 /  4.  6.100
libswresample   2.  7.100 /  2.  7.100

最後發現並沒有編譯出ffplay,在使用ffplay播放視訊的時候沒有找到ffplay.然後檢視configure生成的config.mak檔案,發現其中的關於

FFPLAY的一行前面有感嘆號:

!CONFIG_FFPLAY=yes
也就是在生成配置檔案時由於某些原因並沒有成功生成編譯ffplay的配置,最後查詢原因是由於缺少了兩個庫:

sdl2.0

sdl1.2

$ sudo apt-get install libsdl1.2-dev
其中出現了一個錯誤:

E: Failed to fetch http://202.119.32.195/cache/8/01/cn.archive.ubuntu.com/3991d768c0651a8fda450b69be432e3d/libpcre3-dev_8.38-3.1_amd64.deb  Writing more data than expected (117288 > 113824)


E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
所以按照提示:

$ sudo apt-get install libsdl1.2-dev --fix-missing
安裝成功。接下來安裝sdl2.0:

我下載的是.tar.gz包,下載之後解壓:

$ tar -zxvf SDL2-2.0.6.tar.gz

解壓之後進入資料夾,進行編譯安裝:
$ mkdir build
$ cd build
$ ../configure
$ make
$ sudo make install
這樣就安裝了sdl2.0

最後進入ffmpeg的資料夾進行清理:

$ sudo make uninstall
$ make distclean
清理之後在進行上述的安裝ffmpeg步驟:
$ mkdir build
$ cd ./build
$ ../configure
$ make
$ sudo make install
也可以去看在configure後生成的config.mak檔案中的關於FFPLAY的一行中的!消失:
CONFIG_FFPLAY=yes
最後安裝完成,FFplay就可以使用了!