Fix High Profile scaling matrix defaults per H.264 Table 7-2 - #26
Fix High Profile scaling matrix defaults per H.264 Table 7-2#26intrepidsilence wants to merge 1 commit into
Conversation
When seq_scaling_matrix_present_flag is 0, all weightScale matrices retain their flat-16 values from the struct initializer. H.264 Table 7-2 Fall-Back Rule Set A requires specific default matrices: 4x4 lists 0-2: Default_4x4_Intra 4x4 lists 3-5: Default_4x4_Inter 8x8 lists 0-3: Default_8x8_Intra (DC=6) 8x8 lists 4-7: Default_8x8_Inter (DC=9) The existing code only sets defaults for lists 0 and 3 (4x4) inside the seq_scaling_matrix_present_flag==1 block, leaving lists 1,2,4,5 at flat-16 even when the flag is set, and all lists at flat-16 when the flag is 0. Move and expand the default initialization to before the flag check, so the correct defaults apply in both cases. When the flag is 1, parse_scaling_lists will override with stream-provided values. The incorrect flat-16 quantization causes subtle errors in intra frames that accumulate through inter-prediction, producing progressively increasing pixel drift across each GOP (measured as mean absolute difference growing from 0.26 to 17.11 over 24 frames, resetting at each IDR). With this fix, decoded output matches FFmpeg pixel-for-pixel.
|
Hi! |
|
@traffaillac The file I was converting was an MKV dump of the movie "Gravity (2013)" from 3D BD. Since this is copyright protected I cannot send. I used makemkv to dump it. The MKV file played cleanly in Bino, which is the only other app I know on macOS that can read the 3D format. I was also able to programmatically confirm that the left and right images in the source were devoid of issues. I think this and the other 3 patches I submitted may bring edge 264 much closer to ready for production. |
|
Hi Thibault, |
The "What's fixed vs upstream master" table only listed the MVC-correctness patches. Group it and add every fix that had since landed - the sample-audit decode-robustness sweep and the MinGW / wasm build fixes. Describe each robustness fix by its generic failure mode; keep private sample filenames, frame counts and volatile source line numbers out of this public doc. Move the single-threaded decode hang (PR #25) out of the MVC table - it is a general single-thread fix, not MVC-specific - into the single-thread lead note. Remove the now-redundant Status section, keeping only its non-redundant facts (single-thread requirement, +4 POC API fields, upstream-match result, and a "Deliberately not included" note for PR #26 and unsupported NAL types).
Summary
When
seq_scaling_matrix_present_flagis 0 in a High Profile stream, allweightScalematrices retain their flat-16 values from the struct initializer. H.264 Table 7-2 Fall-Back Rule Set A requires specific default matrices that differ from flat-16.The Bug
The struct initializer at line ~1826 sets all scaling matrices to flat-16:
The existing code at line ~1869 only sets defaults for 4x4 lists 0 and 3 (Intra/Inter), and only inside the
seq_scaling_matrix_present_flag == 1block. This means:flag == 0: all lists stay at flat-16 (wrong)flag == 1: lists 1, 2, 4, 5 use flat-16 as fall-back instead of spec defaults (wrong)Fix
Set all spec-mandated defaults before checking
seq_scaling_matrix_present_flag:Symptom
Inter-prediction drift that grows progressively across each GOP:
The incorrect flat-16 dequantization causes subtle errors in intra-coded macroblocks that propagate and accumulate through inter-prediction.
Verification
seq_scaling_matrix_present_flag=0)