ffmpegでvideotoolbox(macOS)を使う
macOSのhardware encoder
品質指定方法
-crf や -cq は使えない
-q:v (0〜100) と -b:v (ビットレート指定) がサポートされている
-q:v について
ffmpeg 4.4+ かつ Apple Sillicon 限定
0〜100 の整数のみ (小数点以下切り捨て)
h264 における crf と比べて、1加えたときの差がかなり大きい
速度と画質
h264 の-preset veryfast -b:v 6000k -g 300 (2.2x)
h264_toolbox の -c:v h264_videotoolbox -b:v 7000k -g 300 (6.0x)
-q:v 換算だと、54と55の間くらい
hevc の -c:v hevc -preset veryfast -b:v 4300k -g 300 (0.48x)
hevc_toolbox の -c:v h264_videotoolbox -b:v 6100k -g 300 (5.4x)
詳細
0〜100指定の場合
code:txt
-c:v h264_videotoolbox -q:v 50 -g 300
これでlibx264 -crf 20と同じくらいのファイルサイズ
ビットレート指定の場合
code:txt
-c:v h264_videotoolbox -b:v 9000k -g 300
品質指定 (-crfや-cqの代わり) は -q:v
0〜100指定
-b:vと併用はできない。エラーとかは出ないけど -q:v が優先される
-q:v 指定の際は、実際のビットレートがどうなっているか mediainfo とかで確認したほうがよい -b:v (ビットレート) は、-q:vを指定してない場合はちゃんと指定したほうが画質よさげ
-gはキーフレーム間隔の設定 (これ自体は videotoolbox に関係ない) 減らすとキーフレーム分ビットレートが上がるので、ビットレート指定の場合は増やすと画質が向上する
-q:v 指定の場合、増やすとほぼ画質は変わらずビットレートが下がる
出力後のキーフレーム間隔を短くする必要がなければ、ある程度上げとくと良さげ
level, profile について
軽く試した限り、上記に加えて -level 52 -profile:v high を指定したときと指定しないときの違いは無さそうだった
エンコーダの固有オプションリスト
ffmpeg 7.1 (homebrew) の ffmpeg -h full より
code:avoptions.txt
h264_videotoolbox AVOptions:
-profile <int> E..V....... Profile (from -99 to INT_MAX) (default -99)
baseline 66 E..V....... Baseline Profile
constrained_baseline 578 E..V....... Constrained Baseline Profile
main 77 E..V....... Main Profile
high 100 E..V....... High Profile
constrained_high 612 E..V....... Constrained High Profile
extended 88 E..V....... Extend Profile
-level <int> E..V....... Level (from 0 to 52) (default 0)
1.3 13 E..V....... Level 1.3, only available with Baseline Profile
3.0 30 E..V....... Level 3.0
3.1 31 E..V....... Level 3.1
3.2 32 E..V....... Level 3.2
4.0 40 E..V....... Level 4.0
4.1 41 E..V....... Level 4.1
4.2 42 E..V....... Level 4.2
5.0 50 E..V....... Level 5.0
5.1 51 E..V....... Level 5.1
5.2 52 E..V....... Level 5.2
-coder <int> E..V....... Entropy coding (from 0 to 2) (default 0)
cavlc 1 E..V....... CAVLC entropy coding
vlc 1 E..V....... CAVLC entropy coding
cabac 2 E..V....... CABAC entropy coding
ac 2 E..V....... CABAC entropy coding
-a53cc <boolean> E..V....... Use A53 Closed Captions (if available) (default true)
-constant_bit_rate <boolean> E..V....... Require constant bit rate (macOS 13 or newer) (default
false)
-max_slice_bytes <int> E..V....... Set the maximum number of bytes in an H.264 slice. (fr
om -1 to INT_MAX) (default -1)
-allow_sw <boolean> E..V....... Allow software encoding (default false)
-require_sw <boolean> E..V....... Require software encoding (default false)
-realtime <boolean> E..V....... Hint that encoding should happen in real-time if not f
aster (e.g. capturing from camera). (default false)
-frames_before <boolean> E..V....... Other frames will come before the frames in this sessi
on. This helps smooth concatenation issues. (default false)
-frames_after <boolean> E..V....... Other frames will come after the frames in this sessio
n. This helps smooth concatenation issues. (default false)
-prio_speed <boolean> E..V....... prioritize encoding speed (default auto)
-power_efficient <int> E..V....... Set to 1 to enable more power-efficient encoding if su
pported. (from -1 to 1) (default -1)
-max_ref_frames <int> E..V....... Sets the maximum number of reference frames. This only
has an effect when the value is less than the maximum allowed by the profile/level. (from 0 to INT_
MAX) (default 0)
hevc_videotoolbox AVOptions:
-profile <int> E..V....... Profile (from -99 to INT_MAX) (default -99)
main 1 E..V....... Main Profile
main10 2 E..V....... Main10 Profile
-alpha_quality <double> E..V....... Compression quality for the alpha channel (from 0 to 1
) (default 0)
-constant_bit_rate <boolean> E..V....... Require constant bit rate (macOS 13 or newer) (default
false)
-allow_sw <boolean> E..V....... Allow software encoding (default false)
-require_sw <boolean> E..V....... Require software encoding (default false)
-realtime <boolean> E..V....... Hint that encoding should happen in real-time if not f
aster (e.g. capturing from camera). (default false)
-frames_before <boolean> E..V....... Other frames will come before the frames in this sessi
on. This helps smooth concatenation issues. (default false)
-frames_after <boolean> E..V....... Other frames will come after the frames in this sessio
n. This helps smooth concatenation issues. (default false)
-prio_speed <boolean> E..V....... prioritize encoding speed (default auto)
-power_efficient <int> E..V....... Set to 1 to enable more power-efficient encoding if su
pported. (from -1 to 1) (default -1)
-max_ref_frames <int> E..V....... Sets the maximum number of reference frames. This only
has an effect when the value is less than the maximum allowed by the profile/level. (from 0 to INT_
MAX) (default 0)
prores_videotoolbox AVOptions:
-profile <int> E..V....... Profile (from -99 to 5) (default auto)
auto -99 E..V....... Automatically determine based on input format
proxy 0 E..V....... ProRes 422 Proxy
lt 1 E..V....... ProRes 422 LT
standard 2 E..V....... ProRes 422
hq 3 E..V....... ProRes 422 HQ
4444 4 E..V....... ProRes 4444
xq 5 E..V....... ProRes 4444 XQ
-allow_sw <boolean> E..V....... Allow software encoding (default false)
-require_sw <boolean> E..V....... Require software encoding (default false)
-realtime <boolean> E..V....... Hint that encoding should happen in real-time if not f
aster (e.g. capturing from camera). (default false)
-frames_before <boolean> E..V....... Other frames will come before the frames in this sessi
on. This helps smooth concatenation issues. (default false)
-frames_after <boolean> E..V....... Other frames will come after the frames in this sessio
n. This helps smooth concatenation issues. (default false)
-prio_speed <boolean> E..V....... prioritize encoding speed (default auto)
-power_efficient <int> E..V....... Set to 1 to enable more power-efficient encoding if su
pported. (from -1 to 1) (default -1)
-max_ref_frames <int> E..V....... Sets the maximum number of reference frames. This only
has an effect when the value is less than the maximum allowed by the profile/level. (from 0 to INT_
MAX) (default 0)
関連