aletaziar
9th December 2023, 06:43
Looking for some help optimizing an encode with ffmpeg/x265. It's a 4k animation that has grain and HDR. I'm trying to find the right flags for a transparent encode at a reasonable size but it's proving difficult.
The test encodes I've made have *mostly* worked, but at 00:10.427 (frame 249, 23.976) in the sample scene provided, the left figure has pink blotches in the waist sash in the encodes. The right figure has blockier skin in the encodes, especially in the chest/shoulder and around the nose.
These issues don't seem noticeable when played in MPC-BE via MadVR, but they do show up when I compare the encode with the original using video-compare (https://github.com/pixop/video-compare), which uses ffplay without HDR. Is MadVR hiding these issues with the HDR tone-mapping? Maybe ffplay is kind of "inventing" issues because of the lack of HDR tone-mapping? I would think the blockiness I see is an issue regardless of whether the colors are accurate in ffplay.
I'm trying to reduce both those issues but I don't want to drop my crf anymore since I'm already at 12. Any suggestions would be helpful, this is my first foray into HEVC encoding. I've been doing a lot of reading but figuring this out is proving difficult. The three encode variations I tried all look pretty much the same to me.
samples:
one 15s original quality sample
three 15s encode variations
https://app.box.com/s/6atm9dfchj1nzjzhqaxjusaxchqcqz34
video-compare command, with padding for encode:
video-compare -w x980 -r pad=iw:ih+80:0:80/2 test.mkv test.x265_crf12-nosao-aqmode4.mkv
video-compare command, with cropping for original:
video-compare -w x980 -l crop=iw:ih-80 test.mkv test.x265_crf12-nosao-aqmode4.mkv
encode base:
ff -v level+panic -i test.mkv -max_muxing_queue_size 8192 \
-map 0:v -vf "crop=iw:ih-80" -pix_fmt yuv420p10le -f yuv4mpegpipe \
-strict -1 - | x265 - --y4m --profile main10 --preset slower --crf 12 \
--vbv-bufsize=160000 --vbv-maxrate=160000 --colorprim "bt2020" \
--transfer "smpte2084" --colormatrix "bt2020nc" --range "limited" \
--chromaloc=2 --master-display \
"G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,50)" \
--max-cll "1000,140" --hdr10 --hdr10-opt --repeat-headers --aud \
--hrd --no-strong-intra-smoothing --limit-refs 3 --rd 4 --dynamic-rd 3
crf12:
--selective-sao 2 test.x265_crf12.hevc
crf12, aqmode=4:
--selective-sao 2 --aq-mode 4 test.x265_crf12-aqmode4.hevc
crf12, aqmode=4, no-sao:
--no-sao --aq-mode 4 test.x265_crf12-aqmode4-nosao.hevc
test.mkv mediainfo:
General
Unique ID : 333647730702598027554471434130870826641 (0xFB02372DDF2EA7B8816759A9A0D4F691)
Complete name : R:\test.mkv
Format : Matroska
Format version : Version 4
File size : 110 MiB
Duration : 15 s 683 ms
Overall bit rate : 58.6 Mb/s
Frame rate : 23.720 FPS
Encoded date : 2023-12-09 05:01:16 UTC
Writing application : mkvmerge v81.0 ('Milliontown') 64-bit
Writing library : libebml v1.4.4 + libmatroska v1.7.1
Video
ID : 1
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main 10@L5.1@High
HDR format : SMPTE ST 2086, HDR10 compatible
Codec ID : V_MPEGH/ISO/HEVC
Duration : 15 s 683 ms
Bit rate : 58.6 Mb/s
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate mode : Variable
Frame rate : 23.720 FPS
Original frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0 (Type 2)
Bit depth : 10 bits
Bits/(Pixel*Frame) : 0.298
Time code of first frame : 01:13:14:22
Stream size : 110 MiB (100%)
Title : MPEG-H HEVC Video / 63607 kbps / 2160p / 23.976 fps / 16:9 / Main 10 @ Level 5.1 @ High / 10 bits / HDR10 / BT.2020
Writing library : ATEME Titan File 3.9.6 (4.9.6.2)
Language : zxx
Default : Yes
Forced : No
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant
Mastering display color primaries : Display P3
Mastering display luminance : min: 0.0050 cd/m2, max: 1000 cd/m2
Maximum Content Light Level : 1000 cd/m2
Maximum Frame-Average Light Level : 140 cd/m2
The test encodes I've made have *mostly* worked, but at 00:10.427 (frame 249, 23.976) in the sample scene provided, the left figure has pink blotches in the waist sash in the encodes. The right figure has blockier skin in the encodes, especially in the chest/shoulder and around the nose.
These issues don't seem noticeable when played in MPC-BE via MadVR, but they do show up when I compare the encode with the original using video-compare (https://github.com/pixop/video-compare), which uses ffplay without HDR. Is MadVR hiding these issues with the HDR tone-mapping? Maybe ffplay is kind of "inventing" issues because of the lack of HDR tone-mapping? I would think the blockiness I see is an issue regardless of whether the colors are accurate in ffplay.
I'm trying to reduce both those issues but I don't want to drop my crf anymore since I'm already at 12. Any suggestions would be helpful, this is my first foray into HEVC encoding. I've been doing a lot of reading but figuring this out is proving difficult. The three encode variations I tried all look pretty much the same to me.
samples:
one 15s original quality sample
three 15s encode variations
https://app.box.com/s/6atm9dfchj1nzjzhqaxjusaxchqcqz34
video-compare command, with padding for encode:
video-compare -w x980 -r pad=iw:ih+80:0:80/2 test.mkv test.x265_crf12-nosao-aqmode4.mkv
video-compare command, with cropping for original:
video-compare -w x980 -l crop=iw:ih-80 test.mkv test.x265_crf12-nosao-aqmode4.mkv
encode base:
ff -v level+panic -i test.mkv -max_muxing_queue_size 8192 \
-map 0:v -vf "crop=iw:ih-80" -pix_fmt yuv420p10le -f yuv4mpegpipe \
-strict -1 - | x265 - --y4m --profile main10 --preset slower --crf 12 \
--vbv-bufsize=160000 --vbv-maxrate=160000 --colorprim "bt2020" \
--transfer "smpte2084" --colormatrix "bt2020nc" --range "limited" \
--chromaloc=2 --master-display \
"G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,50)" \
--max-cll "1000,140" --hdr10 --hdr10-opt --repeat-headers --aud \
--hrd --no-strong-intra-smoothing --limit-refs 3 --rd 4 --dynamic-rd 3
crf12:
--selective-sao 2 test.x265_crf12.hevc
crf12, aqmode=4:
--selective-sao 2 --aq-mode 4 test.x265_crf12-aqmode4.hevc
crf12, aqmode=4, no-sao:
--no-sao --aq-mode 4 test.x265_crf12-aqmode4-nosao.hevc
test.mkv mediainfo:
General
Unique ID : 333647730702598027554471434130870826641 (0xFB02372DDF2EA7B8816759A9A0D4F691)
Complete name : R:\test.mkv
Format : Matroska
Format version : Version 4
File size : 110 MiB
Duration : 15 s 683 ms
Overall bit rate : 58.6 Mb/s
Frame rate : 23.720 FPS
Encoded date : 2023-12-09 05:01:16 UTC
Writing application : mkvmerge v81.0 ('Milliontown') 64-bit
Writing library : libebml v1.4.4 + libmatroska v1.7.1
Video
ID : 1
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main 10@L5.1@High
HDR format : SMPTE ST 2086, HDR10 compatible
Codec ID : V_MPEGH/ISO/HEVC
Duration : 15 s 683 ms
Bit rate : 58.6 Mb/s
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate mode : Variable
Frame rate : 23.720 FPS
Original frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0 (Type 2)
Bit depth : 10 bits
Bits/(Pixel*Frame) : 0.298
Time code of first frame : 01:13:14:22
Stream size : 110 MiB (100%)
Title : MPEG-H HEVC Video / 63607 kbps / 2160p / 23.976 fps / 16:9 / Main 10 @ Level 5.1 @ High / 10 bits / HDR10 / BT.2020
Writing library : ATEME Titan File 3.9.6 (4.9.6.2)
Language : zxx
Default : Yes
Forced : No
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant
Mastering display color primaries : Display P3
Mastering display luminance : min: 0.0050 cd/m2, max: 1000 cd/m2
Maximum Content Light Level : 1000 cd/m2
Maximum Frame-Average Light Level : 140 cd/m2