CentOS 6.x 平臺安裝配置ffmpeg
阿新 • • 發佈:2017-11-16
ffmpeg centos6.x
一、介紹
FFmpeg 是Fast Forward Mpeg的簡寫,是一套可以用來記錄、轉換數字音頻、視頻,並能將其轉化為流的開源計算機程序。采用LGPL或GPL許可證。它提供了錄制、轉換以及流化音視頻的完整解決方案。它包含了非常先進的音頻/視頻編解碼庫libavcodec,為了保證高可移植性和編解碼質量,libavcodec裏很多code都是從頭開發的。
FFmpeg在Linux平臺下開發,但它同樣也可以在其它操作系統環境中編譯運行,包括Windows、Mac OS X等。這個項目最早由Fabrice Bellard發起,2004年至2015年間由Michael Niedermayer主要負責維護。許多FFmpeg的開發人員都來自MPlayer項目,而且當前FFmpeg也是放在MPlayer項目組的服務器上。項目的名稱來自MPEG視頻編碼標準,前面的"FF"代表"Fast Forward"。 ---摘自百度
二、安裝
ffmpeg要實現的功能:對短視頻進行轉碼、打水印、去除logo等 1、安裝yasm yasm 是x86平臺的一個匯編優化器, 可以加快ffmpeg x264的編譯 下載地址:http://yasm.tortall.net/releases/Release1.3.0.html #tar xf yasm-1.3.0.tar.gz #cd yasm-1.3.0 #./configure #make && make install 2、安裝依賴包 #yum install libart_lgpl libass-devel freetype-devel opus-devel libvorbis-devel libvpx-devel -y 3、安裝x264 H.264是ITU(International Telecommunication Union,國際通信聯盟)和MPEG(Motion Picture Experts Group,運動圖像專家組) 聯合制定的視頻編碼標準。而x264是一個開源的H.264/MPEG-4 AVC視頻編碼函數庫[1] ,是最好的有損視頻編碼器 #wget http://download.videolan.org/x264/snapshots/last_stable_x264.tar.bz2 #tar xvf last_stable_x264.tar.bz2 #cd x264-snapshot-20171114-2245-stable/ #./configure --enable-shared #make && make install 執行完make install 之後的輸出 install -d /usr/local/bin install x264 /usr/local/bin install -d /usr/local/include install -d /usr/local/lib install -d /usr/local/lib/pkgconfig install -m 644 ./x264.h /usr/local/include install -m 644 x264_config.h /usr/local/include install -m 644 x264.pc /usr/local/lib/pkgconfig ln -f -s libx264.so.148 /usr/local/lib/libx264.so install -m 755 libx264.so.148 /usr/local/lib 4、安裝x265 x265是一個用於編碼符合高效率視頻編碼(HEVC/H.265)標準的視頻的開源自由軟件及函數庫。x265與x264項目類似 x265使用GNU通用公共許可證(GPL)2授權或商業許可證授權提供 下載地址:http://ftp.videolan.org/pub/videolan/x265/ #tar xf x265_2.5.tar.gz #cd x265_2.5/build/linux #bash make-Makefiles.bash #等出現提示界面,輸入g 退出 #make #執行完成之後,庫便在當前目錄下生成了 #ll total 10288 drwxr-xr-x. 2 root root 4096 Nov 16 10:59 cmake -rw-r--r--. 1 root root 16987 Nov 16 10:58 CMakeCache.txt drwxr-xr-x. 9 root root 4096 Nov 16 11:01 CMakeFiles -rw-r--r--. 1 root root 4747 Nov 16 10:58 cmake_install.cmake drwxr-xr-x. 3 root root 4096 Nov 16 10:59 common drwxr-xr-x. 3 root root 4096 Nov 16 10:59 encoder -rw-r--r--. 1 root root 5523420 Nov 16 11:01 libx265.a lrwxrwxrwx. 1 root root 14 Nov 16 11:01 libx265.so -> libx265.so.130 -rwxr-xr-x. 1 root root 4820615 Nov 16 11:01 libx265.so.130 -rw-r--r--. 1 root root 14807 Nov 16 10:59 Makefile -rwxr-xr-x. 1 root root 110 Jul 13 19:20 make-Makefiles.bash -rwxr-xr-x. 1 root root 982 Jul 13 19:20 multilib.sh -rwxr-xr-x. 1 root root 102954 Nov 16 11:01 x265 -rw-r--r--. 1 root root 1426 Nov 16 10:58 x265_config.h -rw-r--r--. 1 root root 479 Nov 16 10:58 x265.def -rw-r--r--. 1 root root 244 Nov 16 10:58 x265.pc #make install [ 64%] Built target common [ 88%] Built target encoder [ 88%] Built target x265-shared [100%] Built target cli [100%] Built target x265-static Install the project... -- Install configuration: "Release" -- Installing: /usr/local/lib/libx265.a -- Installing: /usr/local/include/x265.h -- Installing: /usr/local/include/x265_config.h -- Installing: /usr/local/lib/libx265.so.130 -- Installing: /usr/local/lib/libx265.so -- Installing: /usr/local/lib/pkgconfig/x265.pc -- Installing: /usr/local/bin/x265 -- Removed runtime path from "/usr/local/bin/x265" 補充:x264和x265的對比 265相當於對圖像進行了有重點的編碼,從而降低了整體的碼率,編碼效率就相應提高了。 畫質對比:265比264皮膚更細膩; 壓縮比對比:壓縮率更高,節省三分之一; 硬件支持:瑞芯微 RK3188 支持265的快播盒子已經上市; 同等畫質體積僅為三分之二、帶寬節省三分之一、畫質更細膩等諸多優勢; 解碼難度是264的3倍。 H.265的幀內預測模式支持33種方向(H.264只支持8種),並且提供了更好的運動補償處理和矢量預測方法。 大有H.264當時的風采,壓縮效率依然提升了一倍,解碼難度輕描淡寫地增加了3倍 5、開始編譯安裝ffmpeg 下載地址:http://ffmpeg.org/download.html #tar xf ffmpeg-3.4.tar.bz2 #cd ffmpeg-3.4 #./configure --prefix=/opt/app/ffmpeg3 --enable-shared --enable-filter=delogo --enable-gpl --enable-libass --enable-libfreetype --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree 如果出現error 如下: ERROR: x265 not found using pkg-config 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 "ffbuild/config.log" produced by configure as this will help solve the problem. 原因是需要設置PKG_CONFIG_PATH,通過pkg-config去指定路徑自動尋找需要鏈接的依賴庫,解決方法如下: #export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH (此路徑為.pc文件所在路徑),可使用 #echo $PKG_CONFIG_PATH 查看 /usr/local/lib/pkgconfig:/usr/local/lib/ 然後重新編譯就ok了! 繼續執行 #make #需要較長的時間,30分鐘左右 #make install 6、查看版本 #/opt/app/ffmpeg3/bin/ffmpeg /opt/app/ffmpeg3/bin/ffmpeg: error while loading shared libraries: libavdevice.so.57: cannot open shared object file: No such file or directory 原因是lib目錄未加載到鏈接到系統庫中,系統ld目錄列表在/etc/ld.so.conf中,打開文件會發現,裏面引用了/etc/ld.so.conf.d/下面所有的.conf文件 解決方法; #vim /etc/ld.so.conf.d/ffmpeg.conf 然後添加一行內容: /opt/app/ffmpeg3/lib 保存並退出,執行 #ldconfig 使配置生效,再次執行 ./ffmpeg -version 顯示就正常了 如果再提示error while loading shared libraries: libx265.so.130: cannot open shared object file: No such file or directory 解決方法和上面一樣: #vim /etc/ld.so.conf.d/ffmpeg.conf /opt/app/ffmpeg3/lib/ /usr/local/lib/ #添加一行,因為x265的lib庫是在/usr/local/lib目錄 再次執行#ldconfig命令,再次查看ffmpeg 版本就正常了。 #/opt/app/ffmpeg3/bin/ffmpeg -version ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18) configuration: --prefix=/opt/app/ffmpeg3 --enable-shared --enable-filter=delogo --enable-gpl --enable-libass --enable-libfreetype --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat 57. 83.100 / 57. 83.100 libavdevice 57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 libpostproc 54. 7.100 / 54. 7.100 7、其它模塊 ffmpeg 可以編譯進很多模塊,根據自己的需要來添加,比如安裝lame 下載地址: https://sourceforge.net/projects/lame/files/lame/3.100/ #tar xf lame-3.100.tar.gz #cd lame #./configure #make #make install 然後編譯ffmpeg的時候添加--enable-libmp3lame即可。
三、ffmpeg的用法
#./ffmpeg --help #查看ffmpeg的用法 一個例子: #ffmpeg -i logo.mp4 -vf delogo=1:1:20:20:1 a.mp4 -y #按照一定尺寸調整mp4視頻 網上參考鏈接: http://coders.blog.51cto.com/3203119/1566314 https://www.cnblogs.com/wainiwann/p/4128154.html
其他參考鏈接:
https://www.cnblogs.com/freeweb/p/6897907.html
https://bitbucket.org/multicoreware/x265/wiki/Home
本文出自 “知識體系” 博客,請務必保留此出處http://linuxg.blog.51cto.com/4410110/1982314
CentOS 6.x 平臺安裝配置ffmpeg