Description
Describe the bug
For some reason if you enforce bit depth and it does not align with source (aka 8bit --> 10bit and 10bit-->8bit respectively), resulting video will have distorted colors due to setting wrong color primaries (and doing conversion based on them).
For HEVC 8bit encodes BT.709+BT.709 is enforced, while for 10bit BT.2020+PQ. Mastering data is lost on encode (unless specified).
For AV1 encodes color primary data is stripped, but mastering for HDR is transferred without specification.
Weirdly TranscodeHW and VCEEncC (after update which dropped most it's defaults to AMF defaults) break colors in different ways.
TranscodeHW makes 8->10bit outputs look as low contrast,10->8bit look similar way.
While VCEEncC 8->10bit looks oversaturated, while 10->8bit looks bleak.
UPD: Oh no it's even worse than i thought... I had HEVC10 source with BT.709 color primaries lying around. Well, if i enforce 8-bit encode via TranscodeHW, it gets completely ruined.
At least VCEEncC could do HEVC 10bit BT.709 -> HEVC 8bit without completely ruining picture.
For VCEEncC:
BT.709 -> BT.709 conversion is always correct.
BT.709 -> BT.2020 causes oversaturated result.
BT.2020->BT.709 causes bleak result. Can be fixed by transferring HDR parameters.
For TranscodeHW:
BT.709->BT.709 conversion completely breaks with 8bit->10bit encode.
BT.709->BT.2020 causes image with less contrast, but colors are preserved.
BT.2020->BT.709 causes image with less contrast, but colors are preserved.
I assume that stems from source detection and what color primaries encoder is made to think source in? VCEEncC always presumes that source is BT.709
TranscodeHW always presumes that 8-bit source is BT.709, while 10-bit source is BT.2020. But why does it darken outputs?
To Reproduce
Used software:
TranscodeHW - from latest AMF repo. Just cloned and built it before testing.
VCEEncC 8.27 (also latest on moment of writing)
Used commands:
@echo off
TranscodeHW command list.
:: HEVC 10 bit
%~dp0\TranscodeHW.exe -input %1 -output "%~n1_TranscodeHW_HEVC10%~x1" -codec hevc -HevcRateControlMethod CQP -HevcQP_I 26 -HevcQP_P 26 -HevcColorBitDepth 10
pause
:: HEVC 8 bit
%~dp0\TranscodeHW.exe -input %1 -output "%~n1_TranscodeHW_HEVC8%~x1" -codec hevc -HevcRateControlMethod CQP -HevcQP_I 26 -HevcQP_P 26 -HevcColorBitDepth 8
pause
:: AV1 10bit (i only had 1080p source of 10 bit video in BT.709, hence alignment)
%~dp0\TranscodeHW.exe -input %1 -output "%~n1_TranscodeHW_AV110%~x1" -codec av1 -Av1RateControlMethod CQP -Av1QIndex_Inter 26 -Av1QIndex_Intra 26 -Av1ColorBitDepth 10 -Av1AlignmentMode 2
pause
:: AV1 8bit (i only had 1080p source of 10 bit video in BT.709, hence alignment)
%~dp0\TranscodeHW.exe -input %1 -output "%~n1_TranscodeHW_AV18%~x1" -codec av1 -Av1RateControlMethod CQP -Av1QIndex_Inter 26 -Av1QIndex_Intra 26 -Av1ColorBitDepth 8 -Av1AlignmentMode 2
pause
VCEEncC command list.
:: HEVC 8 bit
%~dp0\VCEEncC64.exe -i %1 -o "%~n1_processed_hevc10%~x1" --avsw --codec hevc --cqp 26 --preset slow --profile main --output-depth 10 --audio-copy
pause
:: HEVC 10 bit
%~dp0\VCEEncC64.exe -i %1 -o "%~n1_processed_hevc8%~x1" --avsw --codec hevc --cqp 26 --preset slow --profile main --output-depth 8 --audio-copy
pause
:: AV1 10bit
%~dp0\VCEEncC64.exe -i %1 -o "%~n1_processed_av110%~x1" --avsw --codec av1 --cqp 26 --preset slow --profile main --output-depth 10 --audio-copy
pause
:: AV1 8bit
%~dp0\VCEEncC64.exe -i %1 -o "%~n1_processed_av18%~x1" --avsw --codec av1 --cqp 26 --preset slow --profile main --output-depth 8 --audio-copy
pause
Setup (please complete the following information):
- OS: Windows 11, 23H2, build 22631.4602
- Driver Version: 24.12.1
- GPU: 7800XT
- Which component has the issue [e.g. Encoder, Decoder]: Encoder.
Screenshots
No debug logs, encode proceeds properly. But outputs are messed up. Here are screenshots. Names of files are visible and show respective encode parameters.
-
TranscodeHW. 8bit BT.709. Two right samples (-> 10bit enforced) look as low contrast.
-
TranscodeHW. 10bit BT.2020. Two left samples (-> 8bit enforced) look as low contrast.
-
TranscodeHW. 10bit BT.709. Two left samples (-> 8bit enforced) are broken. And two right samples (-> 10bit enforced) are oversaturated.
-
VCEEncC 8.27. 8bit BT.709. Two right samples (-> 10bit enforced) are oversaturated.
-
VCEEncC 8.27. 10bit BT.2020. Two left samples (-> 8bit enforced) are bleak
(well, this one actually is more or less expected outcome. Source is HDR and i didn't transfer it's parameters)
-
VCEEncC 8.27. 10bit BT.709. Two right samples (-> 10bit enforced) are oversaturated.
Expected behavior
Output color primaries should not solely depend on forced bit depth.
Breaking 10-bit BT.709 sample to this extent when reencoding it to 8-bit BT.709 definitely should not be a thing.
Additional context
Additional issue:
When i use TranscodeHW on 10-bit BT.2020 HDR source fragment (cropped via ffmpeg) beginning of outputs is ALWAYS corrupted.
First frames (like 3 or 4, perhaps? At least movement is visible) is fine, then there is corrupted several frame gap up to a exactly 1 second mark.
->AV1 8-bit enforced = several frames are either stuck or skipped. Looks like pause and snap afterwards.
->AV1 10-bit enforced = several frames are either stuck or skipped AND green tinted.
->HEVC 8-bit enforced = several frames are corrupted with distorted image.
-> HEVC 10-bit enforced = several frames are corrupted with distorted image and white-grey tint.
-> AVC (8-bit only) = several frames are either stuck/skipped or rapidly switching between two static frames until threshold is passed.
Here is how it looks. Sadly it is impossible to show stuck frames there.
Frankly speaking this also should not be a thing. (VCEEncC does not have this issue), so this one may be either decoder or reader issue. FFMPEG, perhaps?
Activity