My encoding notebook - writing things down for reference.
- ffmpeg
- MediaInfo
- Video Codec: H264 (CPU)
- FPS: Same as source
- Constant Quality: RF 16 (18 seems to be the golden quality standard, but darker scenes might still suffer with it)
- Preset: VerySlow
- Profile: High
- Level: 4.1
- Tune: film
- Advanced Parameters:
deblock=-2,-2
8-bit format is not being used at all, as it introduces a noticeable color banding on SDR sources.
On a Ryzen 3700X (8c/16t) the most viable preset is medium
. It encodes with a speed of 1.0x
.
Slower presets / higher CRF are not worth pursuing, as the encoding time inflates too much, and the quality improvement is debatable.
aq-mode=2
seems to yield the best result (both visually and according to SSIM).
aq-mode=1:aq-strength:1
is decent too, and it consumes less bitrate than aq-mode=2
.
qcomp=0.8
influences CRF - this value seems to be the community standard for when trying to replicate AVC quality on HEVC and CRF is <= 23.
no-sao=1:no-strong-intra-smoothing=1
are a MUST to preserve quality and avoid blurriness.
Check the script in the repo.
- Encodes the video track to HEVC 10-bit (SDR).
- Auto-crops the video.
- Copies the chapters metadata.
- Creates three audio tracks from the primary one (assuming it's high quality - 7.1 - 24bit - 48kHz)
- Stereo track @ 192kbps
- 5.1 track @ 384kbps
- 7.1 track @ 512kbps
- If audio is 5.1, it skips the 7.1 track.
- Copies the first subtitle track over.
Same as above, but we apply a lanczos scale video filter.
-vf=scale=1920:800 -sws_flags lanczos
See also HDR flags in the section below. HDR -> SDR tonemapping is totally not worth it.
- Video Codec: H265-10Bit (CPU)
- FPS: Same as source
- Constant Quality: EXPERIMENTING
- Preset: EXPERIMENTING
- Profile: Main10
- Level: 5.1
- Tune: none
- Advanced Parameters:
aq-mode=1:aq-strength=1.0:deblock=-2,-2:qcomp=0.8:no-sao:transfer=smpte2084:colorprim=bt2020:colormatrix=bt2020nc:chromaloc=2:hdr:hdr-opt:max-cll=724,647:master-display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)
transfer=smpte2084:colorprim=bt2020:colormatrix=bt2020nc:hdr:hdr-opt
HDRchromaloc=2
check this on the source file with MediaInfo, make sure it's the samemax-cll=724,647
check this on the source file with MediaInfo, make sure it's the samemaster-display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)
P3 display specification
SSIM:
ffmpeg -i main.mkv -i reference.mkv -lavfi ssim -f null -
Luminance difference (Y) seems to be the most noticeable.
https://forum.doom9.org/showthread.php?p=1334145#post1334145
ssim: ((1-oldssim)/(1-newssim) - 1)*100 = % improvement
psnr: (new - old) / 0.05 = % improvement
https://trac.ffmpeg.org/ticket/6375
Solution:
-max_muxing_queue_size 1024
Some users report that using 9999
also worked.
https://trac.ffmpeg.org/ticket/5718
FFmpeg is not remapping channels for 5.1(side)
streams.
A simple audio filter can fix that: -af "channelmap=channel_layout=5.1"