第一部分:基礎知識簡介
1. FFmpeg介紹
FFmpeg是一個完整的,跨平臺的解決方案,用於記錄,轉換和流化音視頻.其中FF表明Fast Forwordnode
2. FFmpeg的組件
包含libavcodec,libavutil,libavformat,libavfilter,libavdevice,libscale和libswresample,以及ffmpeg,ffplay和ffprobe,如圖所示vim
[lidengyin@ldy ~]$ ffmpeg --version ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39) configuration: --prefix=/usr/local/ffmpeg --enable-libx264 --enable-gpl libavutil 56. 22.100 / 56. 22.100 libavcodec 58. 35.100 / 58. 35.100 libavformat 58. 20.100 / 58. 20.100 libavdevice 58. 5.100 / 58. 5.100 libavfilter 7. 40.101 / 7. 40.101 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100 libpostproc 55. 3.100 / 55. 3.100
3. 所支持的協議
從直播角度來講FFmpeg支持HTTP,RTSP,RTMP協議bash
4. 實例
- To set the video bitrate of the output file to 64 kbit/s(要將輸出文件的視頻比特率設置爲64 kbit / s):
ffmpeg -i input.avi -b:v 64k -bufsize 64k output.avi
- To force the frame rate of the output file to 24 fps(要將輸出文件的幀速率強制爲24 fps,請執行如下操做):
ffmpeg -i input.avi -r 24 output.avi
- To force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24fps(要將輸入文件的幀速率(僅對原始格式有效)強制爲1 fps,將輸出文件的幀速率強制爲24 fps):
ffmpeg -r 1 -i input.m2v -r 24 output.avi
轉碼流程以下:ide
ffmpeg調用libavformat庫(包含解複用器)以讀取輸入文件並從中獲取包含編碼數據的數據包。當有多個輸入文件時,請ffmpeg嘗試經過跟蹤任何活動輸入流上的最低時間戳來使它們保持同步。
post
而後,已編碼的數據包將傳遞到解碼器(除非爲流選擇了流複製,不然請參見說明)。解碼器產生未壓縮的幀(原始視頻/ PCM音頻/ …),能夠經過過濾進一步處理(請參閱下一節)。過濾後,將幀傳遞到編碼器,由編碼器對其進行編碼並輸出編碼後的數據包。最後,這些被傳遞到複用器,該複用器將編碼的數據包寫入輸出文件。ui
第二部分:安裝部分
1. 下載
wget https://johnvansickle.com/ffmpeg/release-source/ffmpeg-4.1.tar.xz
2. 解壓
sudo tar -Jxvf ffmpeg-4.1.tar.xz -C /usr/local/software/
3. 配置
sudo ./configure --prefix=/usr/local/ffmpeg sudo make & make install
4. 添加ffmpeg到環境變量
sudo vim /etc/profile
找到文件尾部,插入this
export FFMEPG=/usr/local/ffmpeg export PATH=${FFMEPG}/bin:${PATH}
生效編碼
source /etc/profile
5. ./configure出現的問題,安裝yasm
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 ffmpeg-user@ffmpeg.org 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.
- 壓縮包
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
- 解壓
tar zxvf yasm-1.3.0.tar.gz -c /usr/local/software/yasm
- 配置,編譯,安裝
sudo ./configure
- 編譯
sudo make
- 安裝
sudo make install
6. 修改文件/etc/ld.so.conf
sudo vim /etc/ld.so.conf
在最後加入spa
include ld.so.conf.d/*.conf /usr/local/ffmpeg/lib/
7. 查看版本
ffmpeg -version
[lidengyin@ldy ~]$ ffmpeg --version ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39) configuration: --prefix=/usr/local/ffmpeg --enable-libx264 --enable-gpl libavutil 56. 22.100 / 56. 22.100 libavcodec 58. 35.100 / 58. 35.100 libavformat 58. 20.100 / 58. 20.100 libavdevice 58. 5.100 / 58. 5.100 libavfilter 7. 40.101 / 7. 40.101 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100 libpostproc 55. 3.100 / 55. 3.100
8. libx264安裝(這裏開始必須切換root)
從新編譯配置以及編譯安裝FFmepg,將新的libx264配置到FFmepg.net
./configure --prefix=/usr/local/ffmpeg --enable-libx264 --enable-gpl #啓用libx264,libx264須要gpl #提示ERROR,libx264 not found, x264須要咱們本身安裝,而並非FFmpeg所默認包含的庫
由於X264會依賴NASM的彙編加速,所以這裏先安裝NASM.若是不安裝NASM,會報錯:
Minimun version is nasm-2.13
(1)安裝NASM
(2)安裝x264
(3)配置x264環境變量
(4)必定要用root,我在安裝的時候大量報錯,由於權限不足