H.264、HEVC、VP9、AV1、Proresのビットストリームフィルタで色関係のまとめ。各コーデックで出力したときにcolor_range、color_primaries、color_trc、color_spaceの情報を書き込む。

What are bitstream filters in ffmpeg? – Stack Overflowより。

performs bitstream level modifications without performing decoding
デコードせずにビットストリームレベルの変更をする。

The only thing a parser does is change packet boundaries. A bitstream filter, on the other hand, is allowed to actually modify the data.
パーサーがすることは、パケットの境界を変更することだけ。一方、ビットストリームフィルタではデータを実際に変更することができる。

[FFmpeg-devel] Fwd: parser vs. demuxerより。

demuxer is the thing which takes a container (a single 1-D vector of bytes) and splits (demuxes) these into several streams (1 or more audio streams, 1 or more video streams, …)
demuxerは、コンテナ(バイトの単一の1次元ベクトル)を受け取り、これらをいくつかのストリーム(1つ以上のオーディオストリーム、1つ以上のビデオストリームなど)に分割(demux)するもの。

a parser is the thing which takes a single stream as output by a demuxer and splits it into proper frames (some demuxers already produce proper frames so no parser is needed)
parserは、demuxerによる出力として単一のストリームを取得し、それを適切なフレームに分割するもの 。(一部のデマルチプレクサはすでに適切なフレームを生成しているため、パーサーは必要なし)

NALユニットの中身を見てストリームの時点でフラグの状態を確認する。
ffmpeg -v verbose -i input -map 0:v -c copy -bsf:v trace_headers -f null - 2> trace_headers.log

H.264、HEVC

以下のコマンドですべての内容を調べられるが設定値までは載っていない。H.264、HEVCもほとんど同じ。色情報の他にフレームレート、sar、フルレンジフラグ、クロップ、プロファイルレベルの設定などがある。

ffmpeg -h bsf=h264_metadata
ffmpeg -h bsf=hevc_metadata

セクションのE.2.1と、テーブルE-3、E-4、E-5を参照:
H.264 : Advanced video coding for generic audiovisual services
FFmpeg Bitstream Filters Documentation : h264_metadata

セクションのE.3.1と、テーブルE.3、E.4、E.5を参照:
H.265 : High efficiency video coding
FFmpeg Bitstream Filters Documentation : hevc_metadata

H.264のBT.709
ffmpeg -i input -c:v libx264 -bsf:v h264_metadata=colour_primaries=1:transfer_characteristics=1:matrix_coefficients=1 -c:a copy output.mp4

H.265のBT.709
ffmpeg -i input -c:v libx265 -bsf:v hevc_metadata=colour_primaries=1:transfer_characteristics=1:matrix_coefficients=1 -c:a copy output.mp4

H.265のPQ
ffmpeg -i input -c:v libx265 -bsf:v hevc_metadata=colour_primaries=9:transfer_characteristics=16:matrix_coefficients=9 -c:a copy output.mp4

H.265のHLG
ffmpeg -i input -c:v libx265 -bsf:v hevc_metadata=colour_primaries=9:transfer_characteristics=18:matrix_coefficients=9 -c:a copy output.mp4

  • video_full_range_flag[int]
    • 0:limited
    • 1:full
  • colour_primaries[int]
    • 1:BT.709
    • 4:BT.470 System M
    • 5:BT.601 PAL
    • 6:BT.601 NTSC
    • 7:SMPTE 240M
    • 8:Generic film
    • 9:BT.2020
    • 10:XYZ, smpte428, smpte428_1
    • 11:DCI P3, smpte431
    • 12:Display P3, smpte432
  • transfer_characteristics[int]
    • 1:BT.709
    • 4:BT.470 System M
    • 5:BT.470 System B/G
    • 6:BT.601
    • 7:SMPTE 240M
    • 8:Linear
    • 9:Logarithmic (100:1)
    • 10:Logarithmic (316.22777:1)
    • 11:xvYCC
    • 12:BT.1361
    • 13:sRGB/sYCC
    • 14:BT.2020 (10-bit)
    • 15:BT.2020 (12-bit)
    • 16:PQ
    • 17:SMPTE
    • 18:HLG
  • matrix_coefficients[int]
    • 1:BT.709
    • 5:BT.470 System B/G
    • 6:BT.601
    • 7:SMPTE 240M
    • 8:YCgCo
    • 9:BT.2020 non-constant
    • 10:BT.2020 constant
    • 11:Y’D’zD’x
    • 12:Chromaticity-derived non-constant
    • 13:Chromaticity-derived constant
    • 14:ICtCp
  • chroma_sample_loc_type[int]
    -1でVUIから削除する。詳しくはT-REC-H.264のE.2.1 and figure E-1を参照。
    • 0:left。SD、HDの4:2:0用
    • 1:center
    • 2:top left。UHDの4:2:2用
    • 3:top。4:4:4用
    • 4:bottom left
    • 5:bottom

VP9

RGBに設定されているフレームは、暗黙のうちにフルレンジに設定され、プロファイルの0と2とは互換性がない。ビットストリームフィルタではcolorspace以外の指定が出来ないので出力オプションを併用する。
ffmpeg -h bsf=vp9_metadata

FFmpeg Bitstream Filters Documentation : vp9_metadata

ffmpeg -i input -c:v libvpx-vp9 -crf 30 -b:v 0 -qmin 3 -qmax 40 -bsf:v vp9_metadata=color_space=bt709:color_range=tv -color_primaries bt709 -color_trc bt709 -c:a libopus -b:a 96k output.webm

VP9(libvpx-vp9)のエンコード設定について

  • color_space[int]
    • 0, unknown
    • 1, bt601
    • 2, bt709
    • 3, smpte170
    • 4, smpte240
    • 5, bt2020
    • 7, rgb
  • color_range[int]
    • 0, tv:TV(limited)range
    • 1, pc:PC(full)range

AV1

colorのスペルがH.264、HEVCのcolourでないことに注意。
ffmpeg -h bsf=av1_metadata

セクションの6.4.2を参照:
AV1 Bitstream & Decoding Process Specification : Color config semantics
FFmpeg Bitstream Filters Documentation : av1_metadata

Encode/AV1 – FFmpeg

BT.709
ffmpeg -i input -c:v libaom-av1 -crf 30 -cpu-used 6 -bsf:v av1_metadata=color_primaries=1:transfer_characteristics=1:matrix_coefficients=1:color_range=tv -c:a copy output.mp4

PQ
ffmpeg -i input -c:v libaom-av1 -crf 30 -cpu-used 6 -bsf:v av1_metadata=color_primaries=9:transfer_characteristics=16:matrix_coefficients=9:color_range=tv -c:a copy output.mp4

HLG
ffmpeg -i input -c:v libaom-av1 -crf 30 -cpu-used 6 -bsf:v av1_metadata=color_primaries=9:transfer_characteristics=18:matrix_coefficients=9:color_range=tv -c:a copy output.mp4

  • color_primaries[int]
    • 1:BT.709
    • 4:BT.470 System M
    • 5:BT.601 PAL
    • 6:BT.601 NTSC
    • 7:SMPTE 240M
    • 8:Generic film
    • 9:BT.2020
    • 10:XYZ, smpte428, smpte428_1
    • 11:DCI P3, smpte431
    • 12:Display P3, smpte432
  • transfer_characteristics[int]
    • 1:BT.709
    • 4:BT.470 System M
    • 5:BT.470 System B/G
    • 6:BT.601
    • 7:SMPTE 240M
    • 8:Linear
    • 9:Logarithmic (100:1)
    • 10:Logarithmic (316.22777:1)
    • 11:xvYCC
    • 12:BT.1361
    • 13:sRGB/sYCC
    • 14:BT.2020 (10-bit)
    • 15:BT.2020 (12-bit)
    • 16:PQ
    • 17:SMPTE
    • 18:HLG
  • matrix_coefficients[int]
    • 1:BT.709
    • 5:BT.470 System B/G
    • 6:BT.601
    • 7:SMPTE 240M
    • 8:YCgCo
    • 9:BT.2020 non-constant
    • 10:BT.2020 constant
    • 11:Y’D’zD’x
    • 12:Chromaticity-derived non-constant
    • 13:Chromaticity-derived constant
    • 14:ICtCp
  • color_range[int]
    • 0, tv:TV (limited) range
    • 1, pc:PC (full) range

ProRes

ProResの承認関係の話:

Proresコーデックはprores、prores_aw、prores_ksの3種類あり、prores_ksだけ4444、4444xqプロファイルに対応していて設定できる内容が多い。prores_ksprores_kostyaprores_awprores_anatolyiの略。

エンコード設定の例。10ビット422で出力する。
ffmpeg -i input -c:v prores_ks -profile:v hq -vendor Lavc -pix_fmt yuv422p10le -c:a copy prores_ks.mov

ffmpeg -h encoder=prores_ks

  • -mbs_per_slice[int]
    既定値:8
    範囲:1から8まで
  • -profile[int]
    • -1, auto:既定値
    • 0, proxy:apco、sometimes called PR
    • 1, lt:apcs、light
    • 2, standard:acpn、rarely called ST
    • 3, hq:apch、high quality
    • 4, 4444:ap4h
    • 5, 4444xq:ap4x
  • -vendor[string]
    vendor IDの指定。文字は4バイト限定。apl0にするとAppleエンコーダから出力したIDになる
    既定値:Lavc
  • -bits_per_mb[int]
    1つのマクロブロックあたりに求めるビット数
    既定値:0
    範囲:0から8192まで
  • -quant_mat[int]
    定量化マトリクスの指定
    • -1, auto:既定値
    • 0, proxy
    • 2, lt
    • 3, standard
    • 4, hq
    • 6, default
  • -alpha_bits[int]
    アルファチャンネルのビット数
    既定値:16
    範囲:0(無効)、8、16

FourCCsのコーデックID。Apple ProRes – MultimediaWikiより。

  • Apple ProRes 422 High Quality: ‘apch’ (‘hcpa’ in little-endian)
  • Apple ProRes 422 Standard Definition: ‘apcn’ (‘ncpa’ in little-endian)
  • Apple ProRes 422 LT: ‘apcs’ (‘scpa’ in little-endian)
  • Apple ProRes 422 Proxy: ‘apco’ (‘ocpa’ in little-endian)
  • Apple ProRes 4444: ‘ap4h’ (‘h4pa’ in little-endian)
コーデック別ビットレートの目安。Apple ProRes – Wikipediaより。

ドキュメント:

ffmpeg -h bsf=prores_metadata

FFmpeg Bitstream Filters Documentation : prores_metadata
bbc/qtff-parameter-editor: QuickTime file parameter editor for modifying transfer function, colour primary and matrix characteristics

ffmpeg -i input -c:v prores_ks -profile 4444xq -vendor Lavc -pix_fmt yuv422p10 -bsf:v prores_metadata=color_primaries=1:color_trc=1:colorspace=1 -c:a copy prores_ks.mov

  • color_primaries[int]
    • -1, auto:既定値
    • 0, unknown
    • 1, bt709
    • 5, bt470bg:BT601 625
    • 6, smpte170m:BT601 525
    • 9, bt2020
    • 11, smpte431:DCI P3
    • 12, smpte432:P3 D65
  • color_trc[int]
    • -1, auto:既定値
    • 0, unknown
    • 1, bt709:BT 601, BT 709, BT 2020
    • 16, smpte2084:SMPTE ST 2084、PQ (Perceptual Quantization)
    • 18, arib-std-b67:ARIB STD-B67、signal HLG
  • colorspace[int]
    • -1, auto:既定値
    • 0, unknown
    • 1, bt709
    • 6, smpte170m:BT 601
    • 9, bt2020nc

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)