View Full Version : From HDR10 to HDR HLG
FranceBB
20th June 2018, 21:24
Alright,
so here's the thing: I've got an HDR 10bit BT2020nc masterfile which has been mastered with a mastering display color volume of 1000 cd/m2 but contains slightly brighter contents 'cause the colorist looked at the waveform and at the histogram and decided to leave un-clipped content above 1000. As a matter of fact, the maximum content light level is 1127 cd/m2. I've been asked to encode it to HDR HLG 'cause is compatible with SDR displays since it includes both information. I already set the parameters, but I don't know which value I should assign to --pic-struct which sets the picture structure and emits it in the picture timing SEI message and is required for HLG signalling. It takes an integer from 0 to 12, but I don't know which value I should choose.
This is my command line:
ffmpeg.exe -hwaccel dxva2 -i "master.mov" -vf scale=out_color_matrix=bt2020nc:out_h_chr_pos=0:out_v_chr_pos=0 -pix_fmt yuv420p10 -strict -1 -an -f yuv4mpegpipe - | x265.exe --y4m - --input-depth 10 --input-res 3840x2160 --fps 24000/1001 --dither --preset medium --level 5.0 --tune fastdecode --ref 2 --rc-lookahead 3 -b 2 --profile main10 --bitrate 25000 --deblock -4:-4 --hrd --min-luma 64 --max-luma 940 --chromaloc 2 --range limited --videoformat component --colorprim bt2020 --transfer arib-std-b67 --colormatrix bt2020nc --master-display "G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)" --atc-sei 18 --max-cll 1000,400 --overscan show --no-open-gop --min-keyint 1 --keyint 24 --repeat-headers --rd 3 --vbv-maxrate 25000 --vbv-bufsize 25000 --wpp -o "raw_video.hevc"
Which value should I choose for --pic-struct? Can I just decode my HDR10 masterfile via ffmpeg and encode it using x265 with the options above plus --pic-struct and x265 will *automatically* include the information required by the player to be played back by both HDR and SDR TV or do I need to do something else?
Thank you in advance.
nevcairiel
20th June 2018, 21:34
Just re-encoding won't actually give you a valid video, you would have to properly map the HDR10/PQ transfer to the HLG transfer. I don't think FFmpeg can currently do that.
videoh
20th June 2018, 22:05
Also, the picture timing SEI is not the one used to signal HLG. The correct one is the alternative transfer characteristics information SEI, and which carries a preferred transfer characteristics value of 18.
pic_struct isn't something you can just arbitrarily set. It signals the coded structure of the picture, progressive, field, pulled down, etc.
PQ to HLG is a quite involved process. We barely have good PQ support out there yet for desktop video tools, let alone HLG and PQ<-->HLG. But don't despair, I'm working on it. ;)
FranceBB
20th June 2018, 22:11
I knew about --atc-sei 18 but I didn't know how to map HDR10 PQ to HLG and it's a shame that ffmpeg can't actually do that. Maybe (just maybe) I'll find something to do it via AVID Media Composer that I use on a daily basis to edit videos.
videoh
20th June 2018, 22:14
Well, it's all so new; these things take time. It's a complicated thing:
http://downloads.bbc.co.uk/rd/pubs/papers/HDR/BBC_HDRTV_PQ_HLG_Transcode_v2.pdf
FranceBB
20th June 2018, 23:57
I read the pdf. It seems that it's far from being as straightforward as I thought.
Luckily, developers working for Davinci Resolve already did the math for me.
This is what I did: I was able to import the file in AVID Media Composer, but it seems that AVID supports only PQ SMPTE 2084, so I fired up Davinci Resolve and I managed to import the file and export it in HLG.
For everyone who is interested in PQ to HLG conversion using Davinci Resolve:
Go to Project Settings and choose the "Color Management" pane.
Choose Davinci Resolve YRGB Color Managed as the Color Science.
Import your media.
Choose Rec.2100 HLG as the Output Color Space.
Export.
I encoded a few seconds to compare the original master file and the encoded output with a waveform videoscope just to make sure that Davinci didn't screw up and they looked the same.
So I'm launching the encode right now, so I can leave the office and I can let it encode overnight (the CPU it's an Intel Xeon E5-2630 V3, so it's gonna take quite some time).
Anyway, I would say that Davinci Resolve is a lot further down the development line for delivering in HDR than AVID Media Composer is, but - on the other hand - I have Avid Media Composer 8.8.3 which is not the latest version.
Still, Davinci Resolve seems to be handling the conversion.
Thank you all, anyway. ^_^
d3rd3vil
21st June 2018, 00:06
How about you use your resources for Dolby Vision first?
videoh
21st June 2018, 02:04
Davinci Resolve Did you use the free version for that?
videoh
21st June 2018, 02:05
How about you use your resources for Dolby Vision first? You buy the spec for us, I'll do the coding. ;)
FranceBB
21st June 2018, 03:04
Did you use the free version for that?
The company I work for has the licences for both AVID Media Composer and Davinci Resolve, but I don't, that's why I generally prefer to use free open source softwares whenever I can so I can do the same things at home if I have to encode something that is not work-related.
(As a side note: we had a licence for Telestream Vantage as well but it didn't properly decode and encode many formats, so - believe it or not - it got replaced by a workflow made with AutoIt which is based on Avisynth, FFmpeg, x264 and x265 which has a few watch folders, many conditionals and is able deinterlace/interlaced, crop, upscale/downscale, do the speed-up with pitch adjustment, blend frames or just drop them, bring luma and chroma in Tv range, apply loudness correction as well as make slow motion with or without mvtools based on the framerate and append clips recorded by a P2 CAM and is also faster than Vantage. Since then, my boss doesn't mind if I use avisynth to manually encode files which is just amazing).
Cary Knoop
21st June 2018, 03:18
For everyone who is interested in PQ to HLG conversion using Davinci Resolve:
Go to Project Settings and choose the "Color Management" pane.
Choose Davinci Resolve YRGB Color Managed as the Color Science.
Import your media.
Choose Rec.2100 HLG as the Output Color Space.
Export.
You would have to set the input color space as well to Rec.2084 with either a P3 or Rec.2020 gamut.
Also I would tone-map the PQ signal to 1000 nits before you convert to HLG.
kolak
21st June 2018, 09:50
Just re-encoding won't actually give you a valid video, you would have to properly map the HDR10/PQ transfer to the HLG transfer. I don't think FFmpeg can currently do that.
This should be based on "pure" math (no tone mapping should be even needed for 1000nits), like BBC paper suggests. ffmepg should be able to do it, no (maybe after small code tweaks)?
benwaggoner
26th June 2018, 05:04
This should be based on "pure" math (no tone mapping should be even needed for 1000nits), like BBC paper suggests. ffmepg should be able to do it, no (maybe after small code tweaks)?
I don't think "pure math" would work well. There's a lot of color science about human video perception that would need to be applied, no more than a "pure math" SMPTE 2084-709 conversion would provide a perceptually pleasing or creatively accurate result.
I think ColorFront's Transkoder product supports this conversion now, and their color science is always top notch.
kolak
29th June 2018, 11:32
I was just based on BBC paper.
It's definitely way easier than any HDR to SDR, which forces use of pseudo-creative or creative decisions.
videoh
2nd July 2018, 16:39
DGPQtoHLG:
http://rationalqm.us/misc/DGPQtoHLG_1.0.rar
Includes CUDA (fast) and C (slow) modes.
It's "pure math" with a minor hack to avoid divide by zero that is possible with the BBC process.
hydra3333
3rd July 2018, 01:40
Yet more great free software !
Thank you.
videoh
3rd July 2018, 04:44
You're welcome. Happy to be useful.
benwaggoner
3rd July 2018, 18:02
I was just based on BBC paper.
It's definitely way easier than any HDR to SDR, which forces use of pseudo-creative or creative decisions.
Yes, definitely easier than that.
Worst case is SDR-> HDR, since so much creative intent needs to be extrapolated. Although there are some promising techniques based on machine learning.
frank
18th November 2018, 17:39
There is a good movie for testing DGPQtoHLG to convert to HLG: LIFE (2017).
The first chapter has from the beginning high contrast and HDR lights (outer space, ISS).
I tested with FFmpeg and Avisynth+ but the HDR SEI parameters of that movie are strange:
Mastering display L 4000 cd/mē / 0.005 cd/mē
and
MaxCLL=6414, MaxFALL=952
So MaxCLL is higher than the max of mastering display!
The readme of DGPQtoHLG says use light=MaxCLL. In this case the result is too dark and pale.
I got better results with light=4000 (max level of mastering display).
Is that the right way?
I use a calibrated monitor LG 10bit with bt709, bt2020 HDR - but no HLG function.
Played via tv box with KODI 18 and LibreELEC.
videoh
18th November 2018, 19:10
I got better results with light=4000 (max level of mastering display).
Is that the right way? Right is what works best for you with the given stream. ;)
Blue_MiSfit
27th November 2018, 01:13
The MaxCLL / MaxFALL in the SEI is sometimes changed for creative intent due to different rendering behavior on different devices so I'd take it with a grain of salt.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.