Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > High Efficiency Video Coding (HEVC)

Reply
 
Thread Tools Search this Thread Display Modes
Old 20th June 2018, 21:24   #1  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,902
From HDR10 to HDR HLG

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:


Code:
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.
FranceBB is offline   Reply With Quote
Old 20th June 2018, 21:34   #2  |  Link
nevcairiel
Registered Developer
 
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,346
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.
__________________
LAV Filters - open source ffmpeg based media splitter and decoders
nevcairiel is offline   Reply With Quote
Old 20th June 2018, 22:05   #3  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
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.

Last edited by videoh; 20th June 2018 at 22:11.
videoh is offline   Reply With Quote
Old 20th June 2018, 22:11   #4  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,902
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.
FranceBB is offline   Reply With Quote
Old 20th June 2018, 22:14   #5  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Well, it's all so new; these things take time. It's a complicated thing:

http://downloads.bbc.co.uk/rd/pubs/p...anscode_v2.pdf
videoh is offline   Reply With Quote
Old 20th June 2018, 23:57   #6  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,902
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. ^_^
FranceBB is offline   Reply With Quote
Old 21st June 2018, 00:06   #7  |  Link
d3rd3vil
Registered User
 
Join Date: Jun 2016
Posts: 92
How about you use your resources for Dolby Vision first?
d3rd3vil is offline   Reply With Quote
Old 21st June 2018, 02:04   #8  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Quote:
Originally Posted by FranceBB View Post
Davinci Resolve
Did you use the free version for that?
videoh is offline   Reply With Quote
Old 21st June 2018, 02:05   #9  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Quote:
Originally Posted by d3rd3vil View Post
How about you use your resources for Dolby Vision first?
You buy the spec for us, I'll do the coding.
videoh is offline   Reply With Quote
Old 21st June 2018, 03:04   #10  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,902
Quote:
Originally Posted by videoh View Post
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).

Last edited by FranceBB; 21st June 2018 at 03:17.
FranceBB is offline   Reply With Quote
Old 21st June 2018, 03:18   #11  |  Link
Cary Knoop
Cary Knoop
 
Cary Knoop's Avatar
 
Join Date: Feb 2017
Location: Newark CA, USA
Posts: 397
Quote:
Originally Posted by FranceBB View Post
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.
Cary Knoop is offline   Reply With Quote
Old 21st June 2018, 09:50   #12  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
Quote:
Originally Posted by nevcairiel View Post
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)?

Last edited by kolak; 21st June 2018 at 09:58.
kolak is offline   Reply With Quote
Old 26th June 2018, 05:04   #13  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,770
Quote:
Originally Posted by kolak View Post
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.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 29th June 2018, 11:32   #14  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
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.
kolak is offline   Reply With Quote
Old 2nd July 2018, 16:39   #15  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
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.

Last edited by videoh; 2nd July 2018 at 16:43.
videoh is offline   Reply With Quote
Old 3rd July 2018, 01:40   #16  |  Link
hydra3333
Registered User
 
Join Date: Oct 2009
Location: crow-land
Posts: 540
Yet more great free software !
Thank you.
hydra3333 is offline   Reply With Quote
Old 3rd July 2018, 04:44   #17  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
You're welcome. Happy to be useful.
videoh is offline   Reply With Quote
Old 3rd July 2018, 18:02   #18  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,770
Quote:
Originally Posted by kolak View Post
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.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 18th November 2018, 17:39   #19  |  Link
frank
Banned
 
Join Date: Oct 2001
Location: https://t.me/pump_upp
Posts: 811
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.
frank is offline   Reply With Quote
Old 18th November 2018, 19:10   #20  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Quote:
Originally Posted by frank View Post
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.
videoh is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 18:46.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.