NALU格式

音視頻編碼在流媒體和網絡領域占有重要地位;流媒體編解碼流程大致如下圖所示:

image

x264原理解析

參考鏈接: x264百度詞條;H264基本原理;

H264簡介

H.264從1999年開始,到2003年形成草案,最后在2007年定稿有待核實。在ITU的標準里稱為H.264,在MPEG的標準里是MPEG-4的一個組成部分–MPEG-4 Part 10,又叫Advanced Video Codec,因此常常稱為MPEG-4 AVC或直接叫AVC。x264主要使用算法為H264編解碼算法,下面對H264算法進行解析;

H264 編解碼解析

參考鏈接: H264 編解碼協議詳解;深入淺出理解視頻編碼H264結構;詳細文檔;H264編解碼框圖;

H264編碼原理:

在音視頻傳輸過程中,視頻文件的傳輸是一個極大的問題;一段分辨率為19201080,幀率是25的視頻,對于傳輸帶寬的要求是:1920108025/8/1024/1024=6.179MB,意味著視頻每秒帶寬為6.179MB這基本是不肯能的。因此視頻壓縮和編碼技術應運而生。
對于視頻文件來說,視頻由單張圖片幀所組成,每秒25/32幀,但是圖片幀的像素塊之間存在相似性,因此視頻幀圖像可以進行圖像壓縮;H264采用了16
16的分塊大小對,視頻幀圖像進行相似比較和壓縮編碼。如下圖所示:

image

除此之外,對于一段連續的幀圖像來說,前一幀和后一幀之間的關聯度和相似性很高,只記錄當前幀和下一幀與當前幀之間的幀數據差,能夠快速的幫助我們實現視頻壓縮編解碼。為了方便圖像之間的壓縮,將原圖像當前幀設置為Fn,下一幀設置為Fn-1;對Fn進行幀內相似壓縮編碼,使用估計函數進行重新映射(圖像還原);再利用當前幀對圖和幀差信息對下一幀圖片進行估計和還原。具體編碼框架如下圖:

image

在上圖中,輸入的幀或場Fn以宏塊為單位被編碼器處理。首先,按幀內或者幀間預測編碼的方法進行處理。假設採用幀間預測編碼,其預測值PRED是由當前片中前面已編碼的參考圖像經運動補償(MC)后得到,當中參考圖像用F’n-1表示。預測值PRED和當前塊相減后,產生一個殘差塊Dn,經塊變換、量化后產生一組量化后的變換系數X,再經熵編碼,與解碼所需的一些頭信息一起組成壓縮后的碼流,經NAL(網絡自適應層)供傳輸和存儲用。

在進行編碼過后H264也提供了相應的解碼方式,解碼流程如下圖:

image

將編碼器的NAL輸出的H264比特流經熵解碼得到量化后的一組變換系數X,再經反量化、反變換,得到殘差D’n。利用從該比特流中解碼出的頭信息,解碼器就產生一個預測塊PRED,它和編碼器中的原始PRED是同樣的。當該解碼器產生的PRED與殘差D’n相加后,就得到了uF’n,再經濾波后,最后就得到濾波后的解碼輸出圖像F’n

H264中的I幀、P幀和B幀

正如上文所說;H264除了使用幀內壓縮之外,還使用了幀間壓縮;H264采用了獨特的I幀、P幀和B幀策略來實現,連續幀之間的壓縮;

[圖片上傳失敗...(image-381d84-1564739618983)]

如上圖所示;

  • I幀:自身可以通過視頻解壓算法解壓成一張單獨的完整的圖片。
  • P幀:需要參考前面的I幀或P幀,還原成完整的圖片。
  • B幀:需要同時參考前面和后面的I幀或P幀,來實現圖片的還原。
    H.264基準類中,僅使用I幀和P幀以實現低延時,因此是網絡攝像機和視頻編碼器的理想選擇。
    注意:每當讀取到一個新的I幀時,解碼器會更新殘差信息,刪除之前的東西,防止錯誤。

H264編碼結構解析

H264除了實現了對視頻的壓縮處理之外,為了方便網絡傳輸,提供了對應的視頻編碼和分片策略;類似于網絡數據封裝成IP幀,在H264中將其稱為組(gop)、片(slice)、宏塊(Macroblock)這些一起組成了H264的碼流分層結構;H264將其組織成為序列(GOP)、圖片(pictrue)、片(Slice)、宏塊(Macroblock)、子塊(subblock)五個層次。

image

H264將視頻分為連續的幀進行傳輸,在連續的幀之間使用I幀、P幀和B幀。同時對于幀內而言,將圖像分塊為片、宏塊和字塊進行分片傳輸;通過這個過程實現對視頻文件的壓縮包裝。

image

在進行H264分包策略解析之前,我們需要先來了解一下H264的原始碼流結構

H264 網絡包

參考鏈接: 從零了解H264結構;H264碼流結構分析;

H264在提出視頻分片壓縮策略的同時,也提出了網絡分包發送策略。其詳細分包發送策略如下:

image

下面我們從網絡分包的角度對H264原始碼流進行分析;

H.264原始碼流(裸流)是由一個接一個NALU組成,它的功能分為兩層,VCL(視頻編碼層)和 NAL(網絡提取層);

  1. VCL:包括核心壓縮引擎和塊,宏塊和片的語法級別定義,設計目標是盡可能地獨立于網絡進行高效的編碼;
  2. NAL:負責將VCL產生的比特字符串適配到各種各樣的網絡和多元環境中,覆蓋了所有片級以上的語法級別。

在VCL進行數據傳輸或存儲之前,這些編碼的VCL數據,被映射或封裝進NAL單元。(NALU)

一個NALU = 一組對應于視頻編碼的NALU頭部信息 + 一個原始字節序列負荷(RBSP,Raw Byte Sequence Payload).

NALU結構單元的主體結構如下所示;一個原始的H.264 NALU單元常由[StartCode] [NALU Header] [NALU Payload]三部分組成,其中 Start Code 用于標示這是一個NALU 單元的開始,必須是"00 00 00 01" 或"00 00 01",除此之外基本相當于一個NAL header + RBSP;

[圖片上傳失敗...(image-278870-1564739618983)]

NAL Header

由三部分組成,forbidden_bit(1bit),nal_reference_bit(2bits)(優先級),nal_unit_type(5bits)(類型)

[圖片上傳失敗...(image-7f0e7f-1564739618983)]

image
image

舉例如下:

00 00 00 01 06:  SEI信息   
00 00 00 01 67:  0x67&0x1f = 0x07 :SPS
00 00 00 01 68:  0x68&0x1f = 0x08 :PPS
00 00 00 01 65:  0x65&0x1f = 0x05: IDR Slice

NAL解碼流程如下圖

image
RBSP

NALU主體為RBSP;RBSP的主要結構如下:

[圖片上傳失敗...(image-31d2b9-1564739618983)]

[圖片上傳失敗...(image-7b427c-1564739618983)]

注意:SODB是RBSP的原始幀

  • SODB 數據比特串 -> 是編碼后的原始數據
  • RBSP 原始字節序列載荷 -> 在原始編碼數據的后面添加了 結尾比特。一個 bit“1”若干比特“0”,以便字節對齊。
    [圖片上傳失敗...(image-d6e30a-1564739618981)]
再解H264中的分包策略

正如圖3所示,NALU主體中包含了片頭和片上數據


1幀 = n個片
1片 = n個宏塊
1宏塊 = 16x16yuv數據

片是H.264提出的新概念,通過編碼圖片后切分通過高效的方式整合出來的概念。一張圖片有一個或者多個片,而片由NALU裝載并進行網絡傳輸的。但是NALU不一定是切片,這是充分不必要條件,因為 NALU 還有可能裝載著其他用作描述視頻的信息;片的種類如下表所示

意義
I 片 只包含I宏塊
P 片 包含P和I宏塊
B 片 包含B和I宏塊
SP 片 包含P 和/或 I宏塊,用于不同碼流之間的切換
SI 片 一種特殊類型的編碼宏塊

宏塊是視頻信息的主要承載者。一個編碼圖像通常劃分為多個宏塊組成.包含著每一個像素的亮度和色度信息。視頻解碼最主要的工作則是提供高效的方式從碼流中獲得宏塊中像素陣列。

一個宏塊 = 一個16*16的亮度像素 + 一個8×8Cb + 一個8×8Cr彩色像素塊組成。(YCbCr 是屬于 YUV 家族的一員,在YCbCr 中 Y 是指亮度分量,Cb 指藍色色度分量,而 Cr 指紅色色度分量)

宏塊分類 意義
I 宏塊 利用從當前片中已解碼的像素作為參考進行幀內預測
P 宏塊 利用前面已編碼圖像作為參考進行幀內預測,一個幀內編碼的宏塊可進一步作宏塊的分割:即16×16.16×8.8×16.8×8亮度像素塊。如果選了8×8的子宏塊,則可再分成各種子宏塊的分割,其尺寸為8×8,8×4,4×8,4×4
B 宏塊 利用雙向的參考圖像(當前和未來的已編碼圖像幀)進行幀內預測

句法元素的分層結構有助于更有效地節省碼流。例如,再一個圖像中,經常會在各個片之間有相同的數據,如果每個片都同時攜帶這些數據,勢必會造成碼流的浪費。更為有效的做法是將該圖像的公共信息抽取出來,形成圖像一級的句法元素,而在片級只攜帶該片自身獨有的句法元素。

image
image
宏塊分類 意義
mb_type 確定該 MB 是幀內或幀間(P 或 B)編碼模式,確定該 MB 分割的尺寸
mb_pred 確定幀內預測模式(幀內宏塊)確定表 0 或表 1 參考圖 像,和每一宏塊分割的差分編碼的運動矢量(幀間宏塊,除 8×8 宏塊分割的幀內 MB)
sub_mb_pred (只對 8×8MB 分割的幀內 MB)確定每一子宏塊的子宏 塊分割,每一宏塊分割的表 0 和/或表 1 的參考圖象;每一 宏塊子分割的差分編碼運動矢量。
coded_block_pattern 指出哪個 8×8 塊(亮度和彩色)包 編碼變換系數
mb_qp_delta 量化參數的改變值
residual 預測后對應于殘差圖象取樣的編碼變換系數
I,P,B幀與pts/dts
幀的分類 中文 意義
I幀 幀內編碼幀,又稱intra picture I 幀通常是每個 GOP(MPEG 所使用的一種視頻壓縮技術)的第一個幀,經過適度地壓縮,做為隨機訪問的參考點,可以當成圖象。I幀可以看成是一個圖像經過壓縮后的產物
P幀 前向預測編碼幀,又稱predictive-frame 通過充分將低于圖像序列中前面已編碼幀的時間冗余信息來壓縮傳輸數據量的編碼圖像,也叫預測幀
B幀 雙向預測幀,又稱bi-directional interpolated prediction frame 既考慮與源圖像序列前面已編碼幀,也顧及源圖像序列后面已編碼幀之間的時間冗余信息來壓縮傳輸數據量的編碼圖像,也叫雙向預測幀

I,P,B幀的不同

  • I frame:自身可以通過視頻解壓算法解壓成一張單獨的完整的圖片。
  • P frame:需要參考其前面的一個I frame 或者B frame來生成一張完整的圖片。
  • B frame:則要參考其前一個I或者P幀及其后面的一個P幀來生成一張完整的圖片。

pts/dts

名稱 意義
PTS(Presentation Time Stamp) PTS主要用于度量解碼后的視頻幀什么時候被顯示出來。
DTS(Decode Time Stamp) DTS主要是標識內存中的bit流再什么時候開始送入解碼器中進行解碼。
image

主要區別:DTS主要用戶視頻的解碼,在解碼階段使用。PTS主要用于視頻的同步和輸出,在display的時候使用。再沒有B frame的時候輸出順序一樣。

IDR
一個序列的第一個圖像叫做 IDR 圖像(立即刷新圖像),IDR 圖像都是 I 幀圖像。
I和IDR幀都使用幀內預測。I幀不用參考任何幀,但是之后的P幀和B幀是有可能參考這個I幀之前的幀的。IDR就不允許這樣。
其核心作用是,是為了解碼的重同步,當解碼器解碼到 IDR 圖像時,立即將參考幀隊列清空,將已解碼的數據全部輸出或拋棄,重新查找參數集,開始一個新的序列。這樣,如果前一個序列出現重大錯誤,在這里可以獲得重新同步的機會。IDR圖像之后的圖像永遠不會使用IDR之前的圖像的數據來解碼。

幀(frame)和場(filed)

參考鏈接: 幀編碼與場編碼的區別分析

視頻的一場和一幀用來產生一個編碼圖像,一幀通常是一個完整的圖像,當采集視頻信號時,如果采用隔行掃描(奇、偶數行),則掃描下來的一幀圖像就被分成了兩個部分,這每一部分都被稱為 [場],根據次序,分為 [頂場] 和 [底場]。
人眼可察覺到的電視視頻圖像刷新中的閃爍為 0.02 秒,即當電視系統的幀率低于 50 幀/秒,人眼可感覺得出畫面的閃爍。常規如 PAL 制式電視系統幀率為 25 幀/秒、NTSC 制式的則為 30 幀/秒,如果采用逐行掃描將不可避免地在視頻刷新時產生閃爍現象。而另一方面如果單純的提高幀率達到避免閃爍刷新效果,則會增加系統的頻帶寬度。
隔行掃描中,每一幀包含兩個場(top field)和(bottom field),其中每個 field 包含一幀中一半數量的水平線,top field 包含所有奇數線,bottom field 則包含所有偶數線。則在電視顯示過程中,電子槍每發射一行隔一行—先發射奇數行13579…(top field)回頭再發射2468…(bottom field)利用兩次掃描來完成一幅圖像,因為視覺的滯留性,我們看到的效果是差不多的。如在 NTSC 視頻中 frame 的頻率為30次/秒-àfield的頻率則為 60 次/秒,大于了人眼可察覺閃爍的頻率。

方式 作用域
幀編碼方式 活動量較小或者靜止的圖像宜采用
場編碼方式 活動量較大的運動圖像
image

H264編解碼編程

參考鏈接: x264源代碼簡單分析:概述;
開源的H264編碼器有很多,JMVC,T264、X264,這里選擇X264,因為網上關于X264源碼分析資源很多。X264編碼器是一個開源的經過優化的高性能H.264編碼器,目前最新的源碼在本人的I5處理器的PC機上,編碼1920x1080分辨率的視頻序列在使用ultrafast配置的情況下,可以實現160fps左右的編碼速度。
H264編碼規范,已經有了不錯的編解碼實現;其中承擔編碼任務的主要實現有:x264,解碼主要實現有libavcodec;下面分別對這兩個進行介紹。

x264說明和API詳解

x264命令行使用和參數解析

參考鏈接: X264 01 命令行用法
使用linux 中使用x264時可以直接使用:

x264 --fullhelp //

查看x264幫助信息;顯示內容如下


x264 core:148 r2643 5c65704
Syntax: x264 [options] -o outfile infile

Infile can be raw (in which case resolution is required),
  or YUV4MPEG (*.y4m),
  or Avisynth if compiled with support (yes).
  or libav* formats if compiled with lavf support (yes) or ffms support (yes).
Outfile type is selected by filename:
 .264 -> Raw bytestream
 .mkv -> Matroska
 .flv -> Flash Video
 .mp4 -> MP4 if compiled with GPAC or L-SMASH support (gpac)
Output bit depth: 8 (configured at compile time)

Options:

  -h, --help                  List basic options
      --longhelp              List more options
      --fullhelp              List all options

Example usage:

      Constant quality mode:
            x264 --crf 24 -o <output> <input>

      Two-pass with a bitrate of 1000kbps:
            x264 --pass 1 --bitrate 1000 -o <output> <input>
            x264 --pass 2 --bitrate 1000 -o <output> <input>

      Lossless:
            x264 --qp 0 -o <output> <input>

      Maximum PSNR at the cost of speed and visual quality:
            x264 --preset placebo --tune psnr -o <output> <input>

      Constant bitrate at 1000kbps with a 2 second-buffer:
            x264 --vbv-bufsize 2000 --bitrate 1000 -o <output> <input>

Presets:

      --profile <string>      Force the limits of an H.264 profile
                                  Overrides all settings.
                                  - baseline:
                                    --no-8x8dct --bframes 0 --no-cabac
                                    --cqm flat --weightp 0
                                    No interlaced.
                                    No lossless.
                                  - main:
                                    --no-8x8dct --cqm flat
                                    No lossless.
                                  - high:
                                    No lossless.
                                  - high10:
                                    No lossless.
                                    Support for bit depth 8-10.
                                  - high422:
                                    No lossless.
                                    Support for bit depth 8-10.
                                    Support for 4:2:0/4:2:2 chroma subsampling.
                                  - high444:
                                    Support for bit depth 8-10.
                                    Support for 4:2:0/4:2:2/4:4:4 chroma subsampling.
      --preset <string>       Use a preset to select encoding settings [medium]
                                  Overridden by user settings.
                                  - ultrafast:
                                    --no-8x8dct --aq-mode 0 --b-adapt 0
                                    --bframes 0 --no-cabac --no-deblock
                                    --no-mbtree --me dia --no-mixed-refs
                                    --partitions none --rc-lookahead 0 --ref 1
                                    --scenecut 0 --subme 0 --trellis 0
                                    --no-weightb --weightp 0
                                  - superfast:
                                    --no-mbtree --me dia --no-mixed-refs
                                    --partitions i8x8,i4x4 --rc-lookahead 0
                                    --ref 1 --subme 1 --trellis 0 --weightp 1
                                  - veryfast:
                                    --no-mixed-refs --rc-lookahead 10
                                    --ref 1 --subme 2 --trellis 0 --weightp 1
                                  - faster:
                                    --no-mixed-refs --rc-lookahead 20
                                    --ref 2 --subme 4 --weightp 1
                                  - fast:
                                    --rc-lookahead 30 --ref 2 --subme 6
                                    --weightp 1
                                  - medium:
                                    Default settings apply.
                                  - slow:
                                    --b-adapt 2 --direct auto --me umh
                                    --rc-lookahead 50 --ref 5 --subme 8
                                  - slower:
                                    --b-adapt 2 --direct auto --me umh
                                    --partitions all --rc-lookahead 60
                                    --ref 8 --subme 9 --trellis 2
                                  - veryslow:
                                    --b-adapt 2 --bframes 8 --direct auto
                                    --me umh --merange 24 --partitions all
                                    --ref 16 --subme 10 --trellis 2
                                    --rc-lookahead 60
                                  - placebo:
                                    --bframes 16 --b-adapt 2 --direct auto
                                    --slow-firstpass --no-fast-pskip
                                    --me tesa --merange 24 --partitions all
                                    --rc-lookahead 60 --ref 16 --subme 11
                                    --trellis 2
      --tune <string>         Tune the settings for a particular type of source
                              or situation
                                  Overridden by user settings.
                                  Multiple tunings are separated by commas.
                                  Only one psy tuning can be used at a time.
                                  - film (psy tuning):
                                    --deblock -1:-1 --psy-rd <unset>:0.15
                                  - animation (psy tuning):
                                    --bframes {+2} --deblock 1:1
                                    --psy-rd 0.4:<unset> --aq-strength 0.6
                                    --ref {Double if >1 else 1}
                                  - grain (psy tuning):
                                    --aq-strength 0.5 --no-dct-decimate
                                    --deadzone-inter 6 --deadzone-intra 6
                                    --deblock -2:-2 --ipratio 1.1 
                                    --pbratio 1.1 --psy-rd <unset>:0.25
                                    --qcomp 0.8
                                  - stillimage (psy tuning):
                                    --aq-strength 1.2 --deblock -3:-3
                                    --psy-rd 2.0:0.7
                                  - psnr (psy tuning):
                                    --aq-mode 0 --no-psy
                                  - ssim (psy tuning):
                                    --aq-mode 2 --no-psy
                                  - fastdecode:
                                    --no-cabac --no-deblock --no-weightb
                                    --weightp 0
                                  - zerolatency:
                                    --bframes 0 --force-cfr --no-mbtree
                                    --sync-lookahead 0 --sliced-threads
                                    --rc-lookahead 0
      --slow-firstpass        Do not force these faster settings with --pass 1:
                                  --no-8x8dct --me dia --partitions none
                                  --ref 1 --subme {2 if >2 else unchanged}
                                  --trellis 0 --fast-pskip

Frame-type options:

  -I, --keyint <integer or "infinite"> Maximum GOP size [250]
  -i, --min-keyint <integer>  Minimum GOP size [auto]
      --no-scenecut           Disable adaptive I-frame decision
      --scenecut <integer>    How aggressively to insert extra I-frames [40]
      --intra-refresh         Use Periodic Intra Refresh instead of IDR frames
  -b, --bframes <integer>     Number of B-frames between I and P [3]
      --b-adapt <integer>     Adaptive B-frame decision method [1]
                                  Higher values may lower threading efficiency.
                                  - 0: Disabled
                                  - 1: Fast
                                  - 2: Optimal (slow with high --bframes)
      --b-bias <integer>      Influences how often B-frames are used [0]
      --b-pyramid <string>    Keep some B-frames as references [normal]
                                  - none: Disabled
                                  - strict: Strictly hierarchical pyramid
                                  - normal: Non-strict (not Blu-ray compatible)
      --open-gop              Use recovery points to close GOPs
                              Only available with b-frames
      --no-cabac              Disable CABAC
  -r, --ref <integer>         Number of reference frames [3]
      --no-deblock            Disable loop filter
  -f, --deblock <alpha:beta>  Loop filter parameters [0:0]
      --slices <integer>      Number of slices per frame; forces rectangular
                              slices and is overridden by other slicing options
      --slices-max <integer>  Absolute maximum slices per frame; overrides
                              slice-max-size/slice-max-mbs when necessary
      --slice-max-size <integer> Limit the size of each slice in bytes
      --slice-max-mbs <integer> Limit the size of each slice in macroblocks (max)
      --slice-min-mbs <integer> Limit the size of each slice in macroblocks (min)
      --tff                   Enable interlaced mode (top field first)
      --bff                   Enable interlaced mode (bottom field first)
      --constrained-intra     Enable constrained intra prediction.
      --pulldown <string>     Use soft pulldown to change frame rate
                                  - none, 22, 32, 64, double, triple, euro (requires cfr input)
      --fake-interlaced       Flag stream as interlaced but encode progressive.
                              Makes it possible to encode 25p and 30p Blu-Ray
                              streams. Ignored in interlaced mode.
      --frame-packing <integer> For stereoscopic videos define frame arrangement
                                  - 0: checkerboard - pixels are alternatively from L and R
                                  - 1: column alternation - L and R are interlaced by column
                                  - 2: row alternation - L and R are interlaced by row
                                  - 3: side by side - L is on the left, R on the right
                                  - 4: top bottom - L is on top, R on bottom
                                  - 5: frame alternation - one view per frame
                                  - 6: mono - 2D frame without any frame packing
                                  - 7: tile format - L is on top-left, R split across

Ratecontrol:

  -q, --qp <integer>          Force constant QP (0-69, 0=lossless)
  -B, --bitrate <integer>     Set bitrate (kbit/s)
      --crf <float>           Quality-based VBR (0-51) [23.0]
      --rc-lookahead <integer> Number of frames for frametype lookahead [40]
      --vbv-maxrate <integer> Max local bitrate (kbit/s) [0]
      --vbv-bufsize <integer> Set size of the VBV buffer (kbit) [0]
      --vbv-init <float>      Initial VBV buffer occupancy [0.9]
      --crf-max <float>       With CRF+VBV, limit RF to this value
                                  May cause VBV underflows!
      --qpmin <integer>       Set min QP [0]
      --qpmax <integer>       Set max QP [69]
      --qpstep <integer>      Set max QP step [4]
      --ratetol <float>       Tolerance of ABR ratecontrol and VBV [1.0]
      --ipratio <float>       QP factor between I and P [1.40]
      --pbratio <float>       QP factor between P and B [1.30]
      --chroma-qp-offset <integer>  QP difference between chroma and luma [0]
      --aq-mode <integer>     AQ method [1]
                                  - 0: Disabled
                                  - 1: Variance AQ (complexity mask)
                                  - 2: Auto-variance AQ
                                  - 3: Auto-variance AQ with bias to dark scenes
      --aq-strength <float>   Reduces blocking and blurring in flat and
                              textured areas. [1.0]

  -p, --pass <integer>        Enable multipass ratecontrol
                                  - 1: First pass, creates stats file
                                  - 2: Last pass, does not overwrite stats file
                                  - 3: Nth pass, overwrites stats file
      --stats <string>        Filename for 2 pass stats ["x264_2pass.log"]
      --no-mbtree             Disable mb-tree ratecontrol.
      --qcomp <float>         QP curve compression [0.60]
      --cplxblur <float>      Reduce fluctuations in QP (before curve compression) [20.0]
      --qblur <float>         Reduce fluctuations in QP (after curve compression) [0.5]
      --zones <zone0>/<zone1>/...  Tweak the bitrate of regions of the video
                              Each zone is of the form
                                  <start frame>,<end frame>,<option>
                                  where <option> is either
                                      q=<integer> (force QP)
                                  or  b=<float> (bitrate multiplier)
      --qpfile <string>       Force frametypes and QPs for some or all frames
                              Format of each line: framenumber frametype QP
                              QP is optional (none lets x264 choose). Frametypes: I,i,K,P,B,b.
                                  K=<I or i> depending on open-gop setting
                              QPs are restricted by qpmin/qpmax.

Analysis:

  -A, --partitions <string>   Partitions to consider ["p8x8,b8x8,i8x8,i4x4"]
                                  - p8x8, p4x4, b8x8, i8x8, i4x4
                                  - none, all
                                  (p4x4 requires p8x8\. i8x8 requires --8x8dct.)
      --direct <string>       Direct MV prediction mode ["spatial"]
                                  - none, spatial, temporal, auto
      --no-weightb            Disable weighted prediction for B-frames
      --weightp <integer>     Weighted prediction for P-frames [2]
                                  - 0: Disabled
                                  - 1: Weighted refs
                                  - 2: Weighted refs + Duplicates
      --me <string>           Integer pixel motion estimation method ["hex"]
                                  - dia: diamond search, radius 1 (fast)
                                  - hex: hexagonal search, radius 2
                                  - umh: uneven multi-hexagon search
                                  - esa: exhaustive search
                                  - tesa: hadamard exhaustive search (slow)
      --merange <integer>     Maximum motion vector search range [16]
      --mvrange <integer>     Maximum motion vector length [-1 (auto)]
      --mvrange-thread <int>  Minimum buffer between threads [-1 (auto)]
  -m, --subme <integer>       Subpixel motion estimation and mode decision [7]
                                  - 0: fullpel only (not recommended)
                                  - 1: SAD mode decision, one qpel iteration
                                  - 2: SATD mode decision
                                  - 3-5: Progressively more qpel
                                  - 6: RD mode decision for I/P-frames
                                  - 7: RD mode decision for all frames
                                  - 8: RD refinement for I/P-frames
                                  - 9: RD refinement for all frames
                                  - 10: QP-RD - requires trellis=2, aq-mode>0
                                  - 11: Full RD: disable all early terminations
      --psy-rd <float:float>  Strength of psychovisual optimization ["1.0:0.0"]
                                  #1: RD (requires subme>=6)
                                  #2: Trellis (requires trellis, experimental)
      --no-psy                Disable all visual optimizations that worsen
                              both PSNR and SSIM.
      --no-mixed-refs         Do not decide references on a per partition basis
      --no-chroma-me          Ignore chroma in motion estimation
      --no-8x8dct             Disable adaptive spatial transform size
  -t, --trellis <integer>     Trellis RD quantization. [1]
                                  - 0: disabled
                                  - 1: enabled only on the final encode of a MB
                                  - 2: enabled on all mode decisions
      --no-fast-pskip         Disables early SKIP detection on P-frames
      --no-dct-decimate       Disables coefficient thresholding on P-frames
      --nr <integer>          Noise reduction [0]

      --deadzone-inter <int>  Set the size of the inter luma quantization deadzone [21]
      --deadzone-intra <int>  Set the size of the intra luma quantization deadzone [11]
                                  Deadzones should be in the range 0 - 32.
      --cqm <string>          Preset quant matrices ["flat"]
                                  - jvt, flat
      --cqmfile <string>      Read custom quant matrices from a JM-compatible file
                                  Overrides any other --cqm* options.
      --cqm4 <list>           Set all 4x4 quant matrices
                                  Takes a comma-separated list of 16 integers.
      --cqm8 <list>           Set all 8x8 quant matrices
                                  Takes a comma-separated list of 64 integers.
      --cqm4i, --cqm4p, --cqm8i, --cqm8p <list>
                              Set both luma and chroma quant matrices
      --cqm4iy, --cqm4ic, --cqm4py, --cqm4pc <list>
                              Set individual quant matrices

Video Usability Info (Annex E):
The VUI settings are not used by the encoder but are merely suggestions to
the playback equipment. See doc/vui.txt for details. Use at your own risk.

      --overscan <string>     Specify crop overscan setting ["undef"]
                                  - undef, show, crop
      --videoformat <string>  Specify video format ["undef"]
                                  - component, pal, ntsc, secam, mac, undef
      --range <string>        Specify color range ["auto"]
                                  - auto, tv, pc
      --colorprim <string>    Specify color primaries ["undef"]
                                  - undef, bt709, bt470m, bt470bg, smpte170m,
                                    smpte240m, film, bt2020
      --transfer <string>     Specify transfer characteristics ["undef"]
                                  - undef, bt709, bt470m, bt470bg, smpte170m,
                                    smpte240m, linear, log100, log316,
                                    iec61966-2-4, bt1361e, iec61966-2-1,
                                    bt2020-10, bt2020-12
      --colormatrix <string>  Specify color matrix setting ["???"]
                                  - undef, bt709, fcc, bt470bg, smpte170m,
                                    smpte240m, GBR, YCgCo, bt2020nc, bt2020c
      --chromaloc <integer>   Specify chroma sample location (0 to 5) [0]
      --nal-hrd <string>      Signal HRD information (requires vbv-bufsize)
                                  - none, vbr, cbr (cbr not allowed in .mp4)
      --filler                Force hard-CBR and generate filler (implied by
                              --nal-hrd cbr)
      --pic-struct            Force pic_struct in Picture Timing SEI
      --crop-rect <string>    Add 'left,top,right,bottom' to the bitstream-level
                              cropping rectangle

Input/Output:

  -o, --output <string>       Specify output file
      --muxer <string>        Specify output container format ["auto"]
                                  - auto, raw, mkv, flv, mp4
      --demuxer <string>      Specify input container format ["auto"]
                                  - auto, raw, y4m, avs, lavf, ffms
      --input-fmt <string>    Specify input file format (requires lavf support)
      --input-csp <string>    Specify input colorspace format for raw input
                              - valid csps for `raw` demuxer:
                                i420, yv12, nv12, nv21, i422, yv16, nv16, i444, yv24, bgr, bgra, rgb
                              - valid csps for `lavf` demuxer:
                                yuv420p, yuyv422, rgb24, bgr24, yuv422p, 
                                yuv444p, yuv410p, yuv411p, gray, monow, monob, 
                                pal8, yuvj420p, yuvj422p, yuvj444p, xvmcmc, 
                                xvmcidct, uyvy422, uyyvyy411, bgr8, bgr4, 
                                bgr4_byte, rgb8, rgb4, rgb4_byte, nv12, nv21, 
                                argb, rgba, abgr, bgra, gray16be, gray16le, 
                                yuv440p, yuvj440p, yuva420p, vdpau_h264, 
                                vdpau_mpeg1, vdpau_mpeg2, vdpau_wmv3, 
                                vdpau_vc1, rgb48be, rgb48le, rgb565be, 
                                rgb565le, rgb555be, rgb555le, bgr565be, 
                                bgr565le, bgr555be, bgr555le, vaapi_moco, 
                                vaapi_idct, vaapi_vld, yuv420p16le, 
                                yuv420p16be, yuv422p16le, yuv422p16be, 
                                yuv444p16le, yuv444p16be, vdpau_mpeg4, 
                                dxva2_vld, rgb444le, rgb444be, bgr444le, 
                                bgr444be, ya8, bgr48be, bgr48le, yuv420p9be, 
                                yuv420p9le, yuv420p10be, yuv420p10le, 
                                yuv422p10be, yuv422p10le, yuv444p9be, 
                                yuv444p9le, yuv444p10be, yuv444p10le, 
                                yuv422p9be, yuv422p9le, vda_vld, gbrp, gbrp9be, 
                                gbrp9le, gbrp10be, gbrp10le, gbrp16be, 
                                gbrp16le, yuva420p9be, yuva420p9le, 
                                yuva422p9be, yuva422p9le, yuva444p9be, 
                                yuva444p9le, yuva420p10be, yuva420p10le, 
                                yuva422p10be, yuva422p10le, yuva444p10be, 
                                yuva444p10le, yuva420p16be, yuva420p16le, 
                                yuva422p16be, yuva422p16le, yuva444p16be, 
                                yuva444p16le, vdpau, xyz12le, xyz12be, nv16, 
                                nv20le, nv20be, yvyu422, vda, ya16be, ya16le, 
                                qsv, mmal, d3d11va_vld, rgba64be, rgba64le, 
                                bgra64be, bgra64le, 0rgb, rgb0, 0bgr, bgr0, 
                                yuva444p, yuva422p, yuv420p12be, yuv420p12le, 
                                yuv420p14be, yuv420p14le, yuv422p12be, 
                                yuv422p12le, yuv422p14be, yuv422p14le, 
                                yuv444p12be, yuv444p12le, yuv444p14be, 
                                yuv444p14le, gbrp12be, gbrp12le, gbrp14be, 
                                gbrp14le, gbrap, gbrap16be, gbrap16le, 
                                yuvj411p, bayer_bggr8, bayer_rggb8, 
                                bayer_gbrg8, bayer_grbg8, bayer_bggr16le, 
                                bayer_bggr16be, bayer_rggb16le, bayer_rggb16be, 
                                bayer_gbrg16le, bayer_gbrg16be, bayer_grbg16le, 
                                bayer_grbg16be, yuv440p10le, yuv440p10be, 
                                yuv440p12le, yuv440p12be, ayuv64le, ayuv64be, 
                                videotoolbox_vld
      --output-csp <string>   Specify output colorspace ["i420"]
                                  - i420, i422, i444, rgb
      --input-depth <integer> Specify input bit depth for raw input
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容