歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> FFmpeg安裝及encode庫的安裝說明

FFmpeg安裝及encode庫的安裝說明

日期:2017/2/28 13:47:41   编辑:Linux教程

FFmpeg安裝及encode庫的安裝說明

一、安裝ffmpeg

A. 去ffmpeg官網(https://ffmpeg.org/)下載linux的官方源碼包
B. 解壓 tar -jxvf ffmpeg-3.1.4.tar.bz2
C. 進入解壓目錄 cd ffmpeg-3.1.4/
D. 執行 ./configure –enable-shared –prefix=/usr/local/ffmpeg

如果提示出錯

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

If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
[email protected] mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file “config.log” produced by configure as this will help
solve the problem.

E.按照提示需要安裝yasm.
1).wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz 下載源碼包
2).tar zxvf yasm-1.3.0.tar.gz 解壓
3).cd yasm-1.3.0 進入目錄
4)../configure 配置
5).make && make install 編譯安裝

安裝完成後,繼續執行
./configure –enable-shared –prefix=/usr/local/ffmpeg
然後
F. make 這個編譯的時間會很長
G. make install 安裝

最後 檢查安裝是否成功
/usr/local/ffmpeg/bin/ffmpeg –version

報錯如下
/usr/local/ffmpeg/bin/ffmpeg: error while loading shared libraries: libavdevice.so.56: cannot open shared object file: No such file or directory

提示庫文件找不到。
修改文件/etc/ld.so.conf 內容增加/usr/local/ffmpeg/lib/

vim /etc/ld.so.conf

include ld.so.conf.d/*.conf
/usr/local/ffmpeg/lib

保存退出之後 ,執行
ldconfig
使修改生效

執行 /usr/local/ffmpeg/bin/ffmpeg –version

配置環境變量 path
執行 export PATH=/usr/local/ffmpeg/bin/:$PATH
執行 env

則在任何目錄都可以執行 ffmpeg –version

測試執行轉碼:
ffmpeg -i test.avi test.mp4

到這裡ffmpeg的安裝就完成了,但是有很多的視頻編碼ffmpeg在現在的情況下是沒法完成的,因為他有些編碼庫好沒有裝上去,下面就是講編碼庫的安裝

二、安裝ffmpeg的encode庫

聲明:安裝ffmpeg或者encode庫沒有先後順序,可以先安裝ffmpeg的編碼庫 。ffmpeg編譯是需要很長的時間的。這裡根據需要我只講h264 、theora、vp8 這三種編碼的安裝。如需其他的編碼,可以找編碼安裝即可,方式相同
1、安裝h264編碼庫
1).先下載x264的工程代碼,h264 的編碼庫下載地址(git clone git://git.videolan.org/x264.git),linux系統有些是帶git的,如果沒有可以先安裝一個
執行 yum install git

2)進入x264文件夾,./configure –help看看它的幫助信息,我們這裡需要的是x264以.so or .a的形式來支援ffmpeg,所以一般就關注shared和static關鍵詞就可以了。執行./configure –enable-shared –enable-static就行了。
3).完了make && make install就可以了。

你會發現我們在./configure的時候沒有指定前綴–prefix=/usr,很明顯,libx264.so和libx264.a就會復制到/usr/local/lib下去,記住這裡,等下會因為這裡要做一些修改。

重新編譯ffmpeg(也可以先安裝下邊的兩個包,到時候一起編譯,節約時間)
1).進入ffmpeg目錄,./configure –enable-gpl –enable-libx264,然後就生成了新的makefile了。
2).執行make clean 完了之後make 完了之後make install。
3).這樣ffmpeg就被重新編譯了,完了就可以驗證一下,使用ffmpeg工具,把某個視頻文件中的視頻流轉碼成h264格式

如果你看到類似於“libxxx.so找不到”的錯誤提示,解決方法
在/etc/ld.so.conf文件中添加一行/usr/local/lib 保存退出之後ldconfig命令使得剛剛的修改生效,完了再運行轉碼命令試試

參考資料:http://blog.csdn.net/zmlcool/article/details/8141097

2、安裝theora編碼庫
安裝theora編碼庫需要 ogg 的依賴 所以在這之前需要先安裝ogg
1)ogg的源碼包下載地址:http://www.xiph.org/downloads/
2)tar -zxvf libogg-1.3.2.tar.gz 解壓
3)cd libogg-1.3.2/ 進入目錄
4)./configure 配置
5)make 編譯
6)make install 安裝

1) theora下載源碼包,下載地址http://theora.org/downloads/
2) 解壓 tar xvfj libtheora-1.1.1.tar.bz2
3) 進入文件夾 cd libtheora-1.1.1/
4) ./configure 配置
5) make 編譯
6) make install 安裝

到此theora 編碼庫安裝完成

重新編譯ffmpeg(也可以先安裝下邊的兩個包,到時候一起編譯,節約時間)
進入ffmpeg目錄,./configure –enable-gpl –enable-libtheora –enable-libx264,然後就生成了新的makefile了。
執行make clean 完了之後make 完了之後make install。

3、安裝 vp8 編碼庫
1)下載源碼包:https://github.com/webmproject/libvpx/releases/tag/v1.6.0
2)tar -zxvf libvpx-1.6.0.tar.gz.
3)cd libvpx-1.6.0/
4)./configure
5)make
6)make install

Vp8 安裝完成

重新編譯ffmpeg(也可以先安裝下邊的兩個包,到時候一起編譯,節約時間)
進入ffmpeg目錄,
./configure –enable-gpl –enable-libtheora –enable-libx264 –enable-libvpx,然後就生成了新的makefile了。
執行make clean 完了之後make 完了之後make install。

現在ffmpeg能轉的編碼格式如下表,我們剛剛安裝的三個格式都已經在裡面了

三、使用方法

這是我使用的三種格式的轉碼方式

ffmpeg -i test.avi -vcodec libx264 -acodec aac testout.m4v 或者 ffmpeg -i test.avi -vcodec h264 -acodec aac testout.m4v

ffmpeg -i test.avi -vcodec libtheora -acodec vorbis -strict -2 testout.ogv

ffmpeg -i test.avi -vcodec vp8 -acodec vorbis -strict -2 testout.webm

還有這篇 http://www.linuxidc.com/Linux/2016-10/136545.htm,上面有ffmpeg的更具體的使用方法

Linux下編譯FFmpeg之下載源文件並編譯 http://www.linuxidc.com/Linux/2012-02/54565.htm

Linux 編譯升級 FFmpeg 步驟 http://www.linuxidc.com/Linux/2013-08/88190.htm

在Ubuntu下安裝FFmpeg http://www.linuxidc.com/Linux/2012-12/75408.htm

Linux 下編譯FFmpeg 支持x264, x265 http://www.linuxidc.com/Linux/2016-04/129858.htm

VS2013編譯FFmpeg http://www.linuxidc.com/Linux/2016-08/134102.htm

在 Mac OS X 環境中從源代碼編譯安裝 FFmpeg http://www.linuxidc.com/Linux/2015-12/126093.htm

Ubuntu 12.04下編譯ffmpeg http://www.linuxidc.com/Linux/2013-02/78857.htm

Ubuntu 14.04下PPA安裝FFmpeg 2.2.2 http://www.linuxidc.com/Linux/2014-05/101322.htm

FFmpeg 的詳細介紹:請點這裡
FFmpeg 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved