ultravideo / kvazaar

An open-source HEVC encoder
BSD 3-Clause "New" or "Revised" License
815 stars 177 forks source link

16bit encoding broken or am I missing something? #346

Open Selur opened 1 year ago

Selur commented 1 year ago

I'm using: Kvazaar v2.1.0-130-g0a8e8675 2022-09-15 Kvazaar license: 3-clause BSD (Kvazaar was build using https://github.com/m-ab-s/media-autobuild_suite) with

ffmpeg -y -loglevel fatal -noautorotate -nostdin -threads 8 -i "G:\TestClips&Co\files\test.avi" -map 0:0 -an -sn -vf zscale=rangein=tv:range=tv -pix_fmt yuv420p16le -strict -1 -vsync 0 -f rawvideo - | kvazaar --preset medium  -i - --input-res 640x352 --input-fps 25/1 --input-format P420 --input-bitdepth 16 --level 6.2 --high-tier --qp 22 --ref 3 --subme 0 --sar 1:1 --range tv --colorprim undef --transfer undef --colormatrix bt470bg -o "E:\Output\16bit_2022-09-15@12_04_22_3410_01.265"

for the encoding and for the muxing to mp4 I use:

MP4Box -add "E:\Output\16bit_2022-09-15@12_04_22_3410_01.265"#video:fps=25:name="":lang="" -brand hvc1 -itags tool="Hybrid 2022.09.14.1" -tmp "E:\Output" -new "E:\Output\16bit.mp4"

aside that the encoder reports 'PSNR Y 999.9900 U 999.9900 V 999.9900' for each frame encoding seems to work fine.

Compiled: INTEL, flags: MMX SSE SSE2 SSSE3 SSE41 SSE42
Detected: INTEL, flags: MMX SSE SSE2 SSE3 SSSE3 SSE41 SSE42 AVX AVX2
Available: avx2(4)
In use: avx2(4)
--owf=auto value set to 6.
--threads=auto value set to 15.
Input: -, output: E:\Output\16bit_2022-09-15@12_04_22_3410_01.265
  Video size: 640x352 (input=640x352)
....
 Processed 429 frames,     198264 bits AVG PSNR Y 999.9900 U 999.9900 V 999.9900
 Total CPU time: 2.100 s.
 Encoding time: 2.076 s.
 Encoding wall time: 2.075 s.
 Encoding CPU usage: 100.00%
 FPS: 206.75
 Bitrate: 0.011 Mbps
 AVG QP: 27.3

Problem is output is reported by MediaInfo and FFmpeg as 10bit.

Am I missing something, or is something not working as it should? (8bit and 10bit encoding works fine)

Jovasa commented 1 year ago

Kvazaar currently supports only 8 and 10 bit encoding. 12 bit might also work with some combination of tools but is not officially supported.

Selur commented 1 year ago

Okay, thanks for clearing that up. The command line help should be updated to reflect this. Atm. it states '--input-bitdepth : 8-16 [8]'

fador commented 1 year ago

According to https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding#Profiles the only profile where the 16 bits could be used is "Main 4:4:4 16 Intra", so Intra only 🤔 But yes for sure we have not tested anything higher than 10bits.

NeedsMoar commented 1 year ago

According to https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding#Profiles the only profile where the 16 bits could be used is "Main 4:4:4 16 Intra", so Intra only 🤔 But yes for sure we have not tested anything higher than 10bits.

The full HEVC spec is a better reference, since the wiki table you linked specifically says it's a partial list... there are a couple more variants of the 4:4:4 16 Intra. The one more likely to be desirable as a transcoding target (that nothing supports afaik) is Monochrome 16. Notably the conformance chart requires that it be flagged with _general_lower_bit_rate_constraintflag like all of the non-intra-only / display formats, where this is optional for intra-only and the high throughput versions. There's also Main 4:4:4 16 Still Picture, and Main 4:4:4 High Throughput 16 Intra which has a more easily playable base layer that can seemingly be any bit depth below 16. There are 10 / 12 / 14-bit High Throughput and Screen Extended 10 / 14-bit High Throughput as well. They don't quite explain what the meaning or intended use of high throughput or screen extended high throughput are but given their layered structure it's probably something to do with being able to serve a stream from a higher bit depth master at the user-requested bit depth but I can't really say.

I'm pretty sure movie theaters are still using lossless encrypted jpeg2000 and the high end cameras like Sony Venice generally shoot their own raw formats, more consumer grade stuff seems to top out at 4:2:2 10-bit Intra, so I really don't know who the audience for 16-bit or 14-bit would be.

I'm not sure what the command line option "4:0:0" means, there's not a single occurrence in the ~700 page spec. Monochrome is called that, so is it something different?