MediaSDK icon indicating copy to clipboard operation
MediaSDK copied to clipboard

Fill HDR Side Data for HEVC Decoding

Open softworkz opened this issue 4 years ago • 56 comments

Structures for HDR side data have recently been added for HEVC encoding: https://github.com/Intel-Media-SDK/MediaSDK/commit/a9685bf658d1ec97ff44b614dcf75818ecc62819 :

  • mfxExtContentLightLevelInfo
  • mfxExtMasteringDisplayColourVolume

What missing is to fill those structures when decoding HEVC video.

Could this be added?

softworkz avatar Feb 11 '21 22:02 softworkz

@softworkz , just to be on the same page: would you like to have this reporting from DecodeHeader and together with each output frame (if there're per frame SEI), right?

dmitryermilov avatar Feb 11 '21 22:02 dmitryermilov

@softworkz , just to be on the same page: would you like to have this reporting from DecodeHeader and together with each output frame (if there're per frame SEI), right?

Correct. From all videos that I've seen so far, even with static HDR (like HDR10), the data is in every frame (SEI type 137 and 144 IIRC).

Purposes:

  • Re-Encoding while keeping HDR data e.g. just scaling down while retaining color format and HDR (you've already done the encoding side)
  • The data is required for tone mapping
    • It's a prerequisite for this: https://github.com/Intel-Media-SDK/MediaSDK/issues/1949
    • But even right now it's a problem when doing tone mapping for example with OpenCL, because QuickSync decoders (unlike VAAPI) do bitstream and codec parsing, so it's not possible to get at this data (e.g. using ffmpeg)

softworkz avatar Feb 11 '21 23:02 softworkz

Thanks for details. Yes, we can do it but please expect some delay, ~2 weeks.

dmitryermilov avatar Feb 12 '21 20:02 dmitryermilov

2 weeks? That's not a delay - that would be awesome 😆

softworkz avatar Feb 12 '21 21:02 softworkz

@pengxin99 Could you please take a look? Thanks.

wangyan-intel avatar Jun 16 '21 02:06 wangyan-intel

Thanks for details. Yes, we can do it but please expect some delay, ~2 weeks.

@dmitryermilov @pengxin99 - Is there any progress in sight on this issue?

softworkz avatar Nov 17 '21 20:11 softworkz

@softworkz Sorry for slow response. As you know, we are transferring from MSDK legacy to oneVPL (https://github.com/oneapi-src/oneVPL-intel-gpu). For legacy branch, it has been implemented by @pengxin99 with extension buffer. But this flow cannot be used in VPL architecture. We are evaluating the path and will update it ASAP.

wangyan-intel avatar Nov 19 '21 02:11 wangyan-intel

Only the "legacy" path is of interest at this time. Will the implementation from @pengxin99 be merged?

softworkz avatar Nov 19 '21 14:11 softworkz

For Linux we could easily merge this patch ourselves, but not for Windows - that's the big problem. Or is there a way how we could build our own libmfxhw64.dll for Windows?

softworkz avatar Nov 19 '21 14:11 softworkz

@softworkz In general, we will not add new feature into legacy path and just bug fix. Of course, you could use @pengxin99's legacy PR. Windows code isn't included in current repo (https://github.com/Intel-Media-SDK). @dmitryermilov @onabiull Could we provide binary build beyond the normal release build?

wangyan-intel avatar Nov 22 '21 02:11 wangyan-intel

Or even better - could we get the Windows code (maybe under NDA) to build our own binaries? Thanks, sw

softworkz avatar Nov 22 '21 18:11 softworkz

Binary for NDA user - I assume it's possible. Code for NDA user - there should be a very strong request, unlikely to be approved but I can double check. Please send me a formal email including company name.

dmitryermilov avatar Nov 24 '21 22:11 dmitryermilov

Hi Dmitry, thanks I'll follow up offline!

softworkz avatar Nov 24 '21 22:11 softworkz

Fixed by https://github.com/Intel-Media-SDK/MediaSDK/pull/2726. Manual update: https://github.com/Intel-Media-SDK/MediaSDK/pull/2876.

Windows changes will be merged today. Please expect a few (2-8) weeks delay to get updated msdk/vpl run-time library in public graphics driver packages.

dmitryermilov avatar Jan 31 '22 14:01 dmitryermilov

@softworkz , the fix landed into 101.1404 Windows Graphics driver

dmitryermilov avatar Mar 14 '22 19:03 dmitryermilov

Hey Dmitry,

thanks that's great news!

Now we will just need to let it land in ffmpeg ;-)

I'll check with @xhaihao whether he wants to do it. Otherwise I'll try to find some time.

Thanks again, softworkz

softworkz avatar Mar 14 '22 19:03 softworkz

@softworkz Yes, we will check the latest driver. @dmitryermilov it is available in the latest oneVPL GPU runtime on both Linux & Windows, right ? Does MediaSDK support it ?

xhaihao avatar Mar 15 '22 00:03 xhaihao

@xhaihao Yes, It is common code for both Windows and Linux. MediaSDK also supports it.

wangyan-intel avatar Mar 15 '22 01:03 wangyan-intel

Right

dmitryermilov avatar Mar 15 '22 07:03 dmitryermilov

@dmitryermilov @wangyan-intel If user provides MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME & MFX_EXTBUFF_CONTENT_LIGHT_LEVEL_INFO extended buffers, is there a flag indicating valid HDR data is returned from the SDK?

xhaihao avatar Mar 15 '22 16:03 xhaihao

Good question, @xhaihao . I have to admit it looks as a gap. I can propose only to rely on checking non zero MaxDisplayMasteringLuminance/MaxContentLightLevel ..

dmitryermilov avatar Mar 15 '22 21:03 dmitryermilov

however 0 is a valid value for max_content_light_level and max_pic_average_light_level

xhaihao avatar Mar 15 '22 23:03 xhaihao

BTW is this added for av1 decoding ?

xhaihao avatar Mar 16 '22 01:03 xhaihao

Not yet

wangyan-intel avatar Mar 16 '22 01:03 wangyan-intel

@dmitryermilov @wangyan-intel If user provides MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME & MFX_EXTBUFF_CONTENT_LIGHT_LEVEL_INFO extended buffers, is there a flag indicating valid HDR data is returned from the SDK?

@pengxin99 Could you please clarify it? Thanks

wangyan-intel avatar Mar 16 '22 01:03 wangyan-intel

Are RGB x coordinates stored in DisplayPrimariesX[3] in R=>G=>B order, or G=>B=>R order ?

xhaihao avatar Mar 16 '22 01:03 xhaihao

hi, @xhaihao , At first, we wanted to use InsertPayloadToggle in the struct mfxExtMasteringDisplayColourVolume to indicate whether the decoded clips have HDR SEI, but the InsertPayloadToggle was designed for encoding originally, so we did not use this plan. The current way is that if the value of all members ​​in the struct mfxExtMasteringDisplayColourVolume are 0, it means that there is no HDR sei in the decoded clips, and vice versa.

pengxin99 avatar Mar 16 '22 02:03 pengxin99

is it possible to use a reserved byte in mfxExtMasteringDisplayColourVolume and mfxExtContentLightLevelInfo to indicate whether the SDK writes valid data back ?

xhaihao avatar Mar 16 '22 02:03 xhaihao

Are RGB x coordinates stored in DisplayPrimariesX[3] in R=>G=>B order, or G=>B=>R order ?

For the DisplayPrimariesX[3], We just parse the SEI of clips storage information in order, and according to the spec, it should be G=>B=>R order.

pengxin99 avatar Mar 16 '22 02:03 pengxin99

is it possible to use a reserved byte in mfxExtMasteringDisplayColourVolume and mfxExtContentLightLevelInfo to indicate whether the SDK writes valid data back ?

I think this way can be considered, I will discuss it with @wangyan-intel @dmitryermilov for this. If it is fine, I will continue to add this flag.

pengxin99 avatar Mar 16 '22 02:03 pengxin99