Skip to content

Fix HEVC decoding artifacts in VA-API to NVDEC translation - #445

Merged
elFarto merged 1 commit into
elFarto:masterfrom
jaheaga:fix-hevc-artifacts
Jun 27, 2026
Merged

elFarto merged 1 commit into
elFarto:masterfrom
jaheaga:fix-hevc-artifacts

Conversation

@jaheaga

@jaheaga jaheaga commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Three bugs in copyHEVCPicParam caused persistent visual artifacts (blocks, shadows) during HEVC playback via VA-API, while the same streams played clean via VDPAU (direct NVDEC):

  1. NumPocTotalCurr counted all DPB entries instead of only pictures flagged as used by the current frame (RPS_ST_CURR_BEFORE, RPS_ST_CURR_AFTER, RPS_LT_CURR). Now computed as the sum of NumPocStCurrBefore + NumPocStCurrAfter + NumPocLtCurr, matching FFmpeg's nvdec_hevc.c reference implementation.

  2. Tile uniform_spacing_flag detection looped over hardcoded bounds (19 columns, 21 rows), reading out-of-bounds memory. Now uses num_tile_columns_minus1 / num_tile_rows_minus1 as loop bounds.

  3. NumDeltaPocsOfRefRpsIdx was hardcoded to 0 (TODO comment). Now computed as the count of short-term (non-long-term) reference pictures with valid RefPicIdx in the DPB.

Tested on RTX 4060 Max-Q (Optimus/PRIME), driver 570.211.01, Firefox 151, HEVC Main 1080p HLS streams.

Fixes #444

Three bugs in copyHEVCPicParam caused persistent visual artifacts
(blocks, shadows) during HEVC playback via VA-API, while the same
streams played clean via VDPAU (direct NVDEC):

1. NumPocTotalCurr counted all DPB entries instead of only pictures
   flagged as used by the current frame (RPS_ST_CURR_BEFORE,
   RPS_ST_CURR_AFTER, RPS_LT_CURR). Now computed as the sum of
   NumPocStCurrBefore + NumPocStCurrAfter + NumPocLtCurr, matching
   FFmpeg's nvdec_hevc.c reference implementation.

2. Tile uniform_spacing_flag detection looped over hardcoded bounds
   (19 columns, 21 rows), reading out-of-bounds memory. Now uses
   num_tile_columns_minus1 / num_tile_rows_minus1 as loop bounds.

3. NumDeltaPocsOfRefRpsIdx was hardcoded to 0 (TODO comment). Now
   computed as the count of short-term (non-long-term) reference
   pictures with valid RefPicIdx in the DPB.

Tested on RTX 4060 Max-Q (Optimus/PRIME), driver 570.211.01,
Firefox 151, HEVC Main 1080p HLS streams.
@elFarto
elFarto merged commit 5072f29 into elFarto:master Jun 27, 2026
2 checks passed
@elFarto

elFarto commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Thanks for the patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HEVC decoding artifacts caused by incorrect NumPocTotalCurr, tile bounds, and NumDeltaPocsOfRefRpsIdx

2 participants