先科普一下profile&level。(這裏討論最經常使用的H264)
H.264有四種畫質級別,分別是baseline, extended, main, high:
一、Baseline Profile:基本畫質。支持I/P 幀,只支持無交錯(Progressive)和CAVLC;
二、Extended profile:進階畫質。支持I/P/B/SP/SI 幀,只支持無交錯(Progressive)和CAVLC;(用的少)
三、Main profile:主流畫質。提供I/P/B 幀,支持無交錯(Progressive)和交錯(Interlaced),
也支持CAVLC 和CABAC 的支持;
四、High profile:高級畫質。在main Profile 的基礎上增長了8x8內部預測、自定義量化、 無損視頻編碼和更多的YUV 格式;
H.264 Baseline profile、Extended profile和Main profile都是針對8位樣本數據、4:2:0格式(YUV)的視頻序列。在相同配置狀況下,High profile(HP)能夠比Main profile(MP)下降10%的碼率。
根據應用領域的不一樣,Baseline profile多應用於實時通訊領域,Main profile多應用於流媒體領域,High profile則多應用於廣電和存儲領域。性能
下圖清楚的給出不一樣的profile&level的性能區別。
profile 編碼
level spa
舉3個例子吧 code
ffmpeg -i input.mp4 -profile:v baseline -level 3.0 output.mp4 ffmpeg -i input.mp4 -profile:v main -level 4.2 output.mp4 ffmpeg -i input.mp4 -profile:v high -level 5.1 output.mp4
若是ffmpeg編譯時加了external的libx264,那就這麼寫: 視頻
ffmpeg -i input.mp4 -c:v libx264 -x264-params "profile=high:level=3.0" output.mp4
從壓縮比例來講,baseline< main < high,對於帶寬比較侷限的在線視頻,可能會選擇high,但有些時候,作個小視頻,但願全部的設備基本都能解碼(有些低端設備或早期的設備只能解碼 baseline),那就犧牲文件大小吧,用baseline。本身取捨吧!blog
蘋果的設備對不一樣profile的支持。 圖片
除了上面提到的,強行配置biterate,或者強行配置profile/level,還有2個參數能夠控制編碼效率。
一個是preset,一個是crf。
preset也挺粗暴,基本原則就是,若是你以爲編碼太快或太慢了,想改改,能夠用profile。
preset有以下參數可用:get
ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow and placebo.
編碼加快,意味着信息丟失越嚴重,輸出圖像質量越差。input
CRF(Constant Rate Factor): 範圍 0-51: 0是編碼毫無丟失信息, 23 is 默認, 51 是最差的狀況。相對合理的區間是18-28.
值越大,壓縮效率越高,但也意味着信息丟失越嚴重,輸出圖像質量越差。it
舉個例子吧。 ffmpeg -i input -c:v libx264 -profile:v main -preset:v fast -level 3.1 -x264opts crf=18
(參考自:https://trac.ffmpeg.org/wiki/Encode/H.264)
和H264的profile&level同樣,爲了應對不一樣應用的需求,HEVC制定了「層級」(tier) 和「等級」(level)。
tier只有main和high。
level有13級,以下所示:
很少說,直接給出怎麼用。(supposed你用libx265編碼) ffmpeg -i input.mp4 -c:v libx265 -x265-params "profile=high:level=3.0" output.mp4