ffvvc / FFmpeg

VVC Decoder for ffmpeg
Other
50 stars 12 forks source link

SPS Range Extension Support #83

Closed frankplow closed 1 year ago

frankplow commented 1 year ago

When using bit depths higher than 10-bit, the sps_range_extension may be include in the SPS. This adds five new flags, primarily to increase the dynamic range. It is possible to use higher bit depths without the range extension, however their benefit will be reduced.

frankplow commented 1 year ago

Here are the range extension features used by the 12-bit VVCv2 bitstreams:

Test extended_precision_flag ts_residual_coding_rice_present_in_sh_flag rrc_rice_extension_flag persistent_rice_adaptation_enabled_flag reverse_last_sig_coeff_enabled_flag
12b400P12_A_Sony_2
12b400P12_B_Sony_2
12b400P12_C_Sony_2
12b400P12_D_Sony_2
12b400P12_E_Sony_2
12b400P16_A_Sony_2
12b400P16_B_Sony_2
12b400P16_C_Sony_2
12b400P16_D_Sony_2
12b400P16_E_Sony_2
12b420P12_A_Sony_2
12b420P12_B_Sony_2
12b420P12_C_Sony_2
12b420P12_D_Sony_2
12b420P12_E_Sony_2
12b420P16_A_Sony_2
12b420P16_B_Sony_2
12b420P16_C_Sony_2
12b420P16_D_Sony_2
12b420P16_E_Sony_2
12b422P12_A_Sony_2
12b422P12_B_Sony_2
12b422P12_C_Sony_2
12b422P12_D_Sony_2
12b422P12_E_Sony_2
12b422P16_A_Sony_2
12b422P16_B_Sony_2
12b422P16_C_Sony_2
12b422P16_D_Sony_2
12b422P16_E_Sony_2
12b444Iepp_A_Sharp_2
12b444Ierrc_A_Qualcomm_2
12b444Ierrc_B_Qualcomm_2
12b444Ietsrc_A_Kwai_2
12b444Iprrc_A_Qualcomm_2
12b444Irlscp_A_OPPO_2
12b444Iwpp_A_OPPO_1
12b444P16_A_Sony_2
12b444P16_B_Sony_2
12b444P16_C_Sony_2
12b444P16_D_Sony_2
12b444P16_E_Sony_2
12b444SPepp_A_Sharp_2
12b444SPerrc_A_Qualcomm_2
12b444SPetsrc_A_Kwai_2
12b444SPetsrc_B_Kwai_2
12b444SPetsrc_C_Kwai_2
12b444SPetsrc_D_Kwai_2
12b444SPetsrc_E_Kwai_2
12b444SPetsrc_F_Kwai_2
12b444SPetsrc_G_Kwai_2
12b444SPetsrc_H_Kwai_2
12b444SPprrc_A_Qualcomm_2
12b444SPrlscp_A_OPPO_2
12b444SPwpp_A_OPPO_1
12b444epp_A_Sharp_2
12b444errc_A_Qualcomm_2
12b444errc_B_Qualcomm_2
12b444errc_C_Qualcomm_2
12b444etsrc_A_Kwai_2
12b444prrc_A_Qualcomm_2
12b444rlscp_A_OPPO_2
12b444wpp_A_OPPO_1

Annoyingly, all of the bitstreams which test only a single feature are 4:4:4. This means the range extension will be easier to implement once #86 is resolved. @nuomi2021 I don't suppose you've done any investigation into this? You said here: https://github.com/ffvvc/FFmpeg/pull/84#issuecomment-1572173468 it may be related to derive_chroma_intra_pred_mod but do you have any more pointers?

nuomi2021 commented 1 year ago

Hi Frank, Good summary.

If you apply this patch. and run "ffmpeg -i tests/conformance/failed/v2/12b444vvc1_A_Sony_2.bit -vsync 0 -y -f rawvideo ffmpeg_patch.yuv" You will find the (64,68) cu on the frame 32 (poc is 32, decoder order is 1) is correct.

The main reason is we derive lumaIntraPredModeC based on "Table 20 – Specification of IntraPredModeC" in spec. It will return INTRA_VDIAG instead INTRA_PLANAR(the correct one)

It's wonderful if you can help double-check the spec and the code. see how to return INTRA_PLANAR

thank you.

git diff
diff --git a/libavcodec/vvc/vvc_ctu.c b/libavcodec/vvc/vvc_ctu.c
index a0a47cc819..c5810f7b0e 100644
--- a/libavcodec/vvc/vvc_ctu.c
+++ b/libavcodec/vvc/vvc_ctu.c
@@ -897,6 +897,11 @@ static void derive_chroma_intra_pred_mode(VVCLocalContext *lc,
                 break;
         }
         cu->intra_pred_mode_c = pred_mode_c[intra_chroma_pred_mode][idx];
+
+        if (fc->decode_order == 1 && cu->x0 == 64 && cu->y0 == 68) {
+            cu->intra_pred_mode_c = INTRA_PLANAR;
+    }
+
     }
     if (sps->chroma_format_idc == CHROMA_FORMAT_422 && cu->intra_pred_mode_c <= INTRA_VDIAG) {
frankplow commented 1 year ago

Implemented in #91.