エンコードメモ

参考文献

https://nyanshiba.com/blog/obs-studio/#hevc_nvenc
https://github.com/nyanshiba/best-ffmpeg-arguments
https://ffmpeg.org/ffmpeg-all.html
https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Ffmpeg.md
https://takuya-1st.hatenablog.jp/entry/2020/05/17/224645
https://github.com/ImageMagick/jpeg-xl/blob/main/doc/man/cjxl.txt
https://trac.ffmpeg.org/wiki/Encode/VP9
https://trac.ffmpeg.org/wiki/Encode/AV1
https://trac.ffmpeg.org/wiki/Encode/HighQualityAudio
https://developer.mozilla.org/ja/docs/Web/Media/Formats/Video_codecs
https://nico-lab.net/setting_in_out_color_with_ffmpeg/
https://trac.ffmpeg.org/wiki/colorspace
https://www.reddit.com/r/ffmpeg/comments/ty9c5k/color_metadata_dcip3/
https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Parameters.md

作業しながら書いたメモなので推奨値ではないです。おそらく上のリンク読んだほうが役に立つ

ffmpegヘルプ

ffmpeg -h encoder=hoge

svtav1

-c:v libsvtav1 -preset 10 -svtav1-params tune=0 -pix_fmt yuv420p10le -crf 45 -c:a libopus -ar 48000 -b:a 128k

低画質ならpreset8もあり。crfは25-35が妥当。45はかなり攻撃的

aomav1

-c:v libaom-av1 -preset 0 -row-mt 1 -tune vmaf_with_preprocessing -crf 40 -pix_fmt yuv420p10le aomenc --help
--tune=
Distortion metric tuned with psnr, ssim, vmaf_with_preprocessing, vmaf_without_preprocessing, vmaf, vmaf_neg, butteraugli, vmaf_saliency_map

vp9

realtimeのcrf40cpu used 5あたりでsvtav1のpreset10 crf35と同じぐらい

-deadline
good, best, realtime
-cpu-used
0-5 or 0-8(realtime)
2pass: (ffmpegで使えず)

ffmpeg -i input.mp4 -c:v libvpx-vp9 -deadline realtime -cpu-used 6 -row-mt 1 -crf 30 -pass 1 -an -f null /dev/null && \
ffmpeg -i input.mp4 -c:v libvpx-vp9 -deadline realtime -cpu-used 6 -row-mt 1 -crf 30 -pass 2 -c:a libopus -ar 48000 -b:a 128k output.webm
-c:v libvpx-vp9 -deadline realtime -cpu-used 5 -row-mt 1 -crf 30 -b:v 0 output.webm

webp

-c:v libwebp
-lossless
1 or 0
-compression_level
0-6
-quality
0-100 def 75
-preset
none
Do not use a preset.
default
Use the encoder default.
picture
digital picture, like portrait, inner shot
photo
outdoor photograph, with natural lighting
drawing
hand or line drawing, with high-contrast details
icon
small-sized colorful images
text
text-like

webp anime

ffmpeg -i input.gif -c:v libwebp_anim -loop 0 -lossless 1 -compression_level 6 -preset icon output.webp

opus

ffmpeg -i hoge.wav -acodec libopus libopus -ab 160k -ar 48000 output.opus

avif

-c:v libsvtav1 -preset 0 -svtav1-params tune=0:film-grain=12 -still-picture 1 -pix_fmt yuv420p10le -crf 30 "$output_file" < /dev/null

svtav1は分割に時間がかかってあまり効果がなさそう

-preset 0 -crf 40 -still-picture 1 -pix_fmt yuv420p10le -color_primaries smpte432 .avif -c:v libaom-av1 -still-picture 1 -aom-params tune=ssim:deltaq-mode=3:cpu-used=4 -pix_fmt yuv420p10le -crf 40 -pix_fmt yuv420p10le -color_primaries smpte432
smpte432
-display p3
smpte431
dci-p3

bt2020

参考: iphoneのdolby-hdr動画のカラー

-color_trc
arib-std-b67 (HLG)
-color_primaries
bt2020
-colorspace
bt2020nc

heif-convert

heif-convert input.HEIF output.png

うんコード

for %%f in (*.mkv) do ( ffmpeg -i "%%~f" -c:v libsvtav1 -preset 5 -crf 35 -g 600 -pix_fmt yuv420p10le -svtav1-params tune=0:film-grain=4 -c:a libopus -ac 2 -ar 48000 -b:a 128k "output\%%~nf.mkv" )

JPEGXL

ffmpeg -i IMG_2144.JPG -effort 7 -distance 2 IMG_21442.jxl

distance 9でavif libaom preset0のcrf35より少しサイズが小さい

distance 0はロスレス distance 1は視覚的ロスレス distance 2はwebにちょうどいい

cjxl -hの結果から

-d DISTANCE, --distance=DISTANCE
Target visual distance in JND units, lower = higher quality. 0.0 = mathematically lossless. Default for already-lossy input (JPEG/GIF). 1.0 = visually lossless. Default for other input. Recommended range: 0.5 .. 3.0. Allowed range: 0.0 ... 25.0. Mutually exclusive with --quality.
-q QUALITY, --quality=QUALITY
Quality setting, higher value = higher quality. This is internally mapped to --distance. 100 = mathematically lossless. 90 = visually lossless. Quality values roughly match libjpeg quality. Recommended range: 68 .. 96. Allowed range: 0 .. 100. Mutually exclusive with --distance.
-e EFFORT, --effort=EFFORT
Encoder effort setting. Range: 1 .. 9. Default: 7. Higher numbers allow more computation at the expense of time. For lossless, generally it will produce smaller files. For lossy, higher effort should more accurately reach the target quality.

- 1 or ``lightning''
- 2 or ``thunder''
- 3 or ``falcon''
- 4 or ``cheetah''
- 5 or ``hare''
- 6 or ``wombat''
- 7 or ``squirrel'' (default)
- 8 or ``kitten''
- 9 or ``tortoise''

hevc

const

-c:v hevc_nvenc -preset:v p7 -profile:v main10 -rc:v constqp -rc-lookahead 1 -spatial-aq 0 -temporal-aq 1 -weighted_pred 0 -init_qpI 24 -init_qpP 24 -init_qpB 28 -qp_cb_offset 10 -qp_cr_offset 11 -b_ref_mode 1 -dpb_size 4 -multipass 1 -g 60 -bf 3 -pix_fmt yuv420p10le -c:a aac -ar 48000 -b:a 128k

constqpでは、init_qpI=n init_qpP=n init_qpB=n+4 が良い結果を出す傾向にあった。

20 20 24
24 24 28

36 36 40
38 38 42

vbr cq

-c:v hevc_nvenc -preset:v p7 -profile:v main10 -rc:v vbr -rc-lookahead 1 -spatial-aq 0 -temporal-aq 1 -weighted_pred 0 -cq 42 -b_ref_mode 1 -dpb_size 4 -multipass 1 -g 60 -bf 3 -pix_fmt yuv420p10le -c:a aac -ar 48000 -b:a 128k