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 > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 1st December 2018, 15:22   #1  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 637
Tone-mapping HDR PQ to SDR (Studio Master)

Hi,
I've been dealing with this content for far too much.
I've got a few episodes of a TV Series in UHD XAVC Intra Class HDR PQ, which is basically an H.264 progressive file encoded with the Intra profile, level 5.1, 4:2:2 planar 10bit, muxed in .mxf with 6 PCM audio channels.
So far so good.

General
Complete name : I:\Production\UHD05432.mxf
Format : MXF
Format version : 1.3
Format profile : OP-1a
Format settings : Closed / Complete
Overall bit rate : 260 Mb/s
Writing application : Colorfront Transkoder/On-Set Dailies 2017.36665

Video
ID : 2
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High 4:2:2 Intra@L5.1
Format settings, CABAC : No
Format settings, GOP : N=1
Format settings, wrapping mode : Frame
Codec ID : 0D01030102106001-0401020201323001
Bit rate : 253 Mb/s
Maximum bit rate : 250 Mb/s
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate : 25.000 FPS
Standard : Component
Color space : YUV
Chroma subsampling : 4:2:2
Bit depth : 10 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 1.220
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant

Audio #1
ID : 3
Format : PCM
Format settings : Little
Format settings, wrapping mode : Frame (AES)
Codec ID : 0D01030102060300
Bit rate mode : Constant
Bit rate : 1 152 kb/s
Channel(s) : 1 channel
Sampling rate : 48.0 kHz
Frame rate : 25.000 FPS (1920 SPF)
Bit depth : 24 bits
Locked : Yes

Audio #2
ID : 4
Format : PCM
Format settings : Little
Format settings, wrapping mode : Frame (AES)
Codec ID : 0D01030102060300
Bit rate mode : Constant
Bit rate : 1 152 kb/s
Channel(s) : 1 channel
Sampling rate : 48.0 kHz
Frame rate : 25.000 FPS (1920 SPF)
Bit depth : 24 bits
Locked : Yes

Audio #3
ID : 5
Format : PCM
Format settings : Little
Format settings, wrapping mode : Frame (AES)
Codec ID : 0D01030102060300
Bit rate mode : Constant
Bit rate : 1 152 kb/s
Channel(s) : 1 channel
Sampling rate : 48.0 kHz
Frame rate : 25.000 FPS (1920 SPF)
Bit depth : 24 bits
Locked : Yes

Audio #4
ID : 6
Format : PCM
Format settings : Little
Format settings, wrapping mode : Frame (AES)
Codec ID : 0D01030102060300
Bit rate mode : Constant
Bit rate : 1 152 kb/s
Channel(s) : 1 channel
Sampling rate : 48.0 kHz
Frame rate : 25.000 FPS (1920 SPF)
Bit depth : 24 bits
Locked : Yes

Audio #5
ID : 7
Format : PCM
Format settings : Little
Format settings, wrapping mode : Frame (AES)
Codec ID : 0D01030102060300
Bit rate mode : Constant
Bit rate : 1 152 kb/s
Channel(s) : 1 channel
Sampling rate : 48.0 kHz
Frame rate : 25.000 FPS (1920 SPF)
Bit depth : 24 bits
Locked : Yes

Audio #6
ID : 8
Format : PCM
Format settings : Little
Format settings, wrapping mode : Frame (AES)
Codec ID : 0D01030102060300
Bit rate mode : Constant
Bit rate : 1 152 kb/s
Channel(s) : 1 channel
Sampling rate : 48.0 kHz
Frame rate : 25.000 FPS (1920 SPF)
Bit depth : 24 bits
Locked : Yes

Other #1
ID : 1-Material
Type : Time code
Format : MXF TC
Time code of first frame : 00:00:00:00
Time code settings : Material Package
Time code, striped : Yes

Other #2
ID : 1-Source
Type : Time code
Format : MXF TC
Time code of first frame : 00:00:00:00
Time code settings : Source Package
Time code, striped : Yes

Other #3
Type : Time code
Format : SMPTE TC
Muxing mode : SDTI
Time code of first frame : 00:00:00:00


The problem is that they didn't include any info about the content: no master-display, no max/min-cll, nothing. It just says that it's HDR PQ, but I have no idea how many nits it is, which mastering display has been used and so on.
I've been asked to tone-map it to SDR and encode it to FULL HD MPEG-2 4:2:2 planar 8bit interlaced TFF, with a closed GOP, 8 PCM audio files muxed in an mxf.
In other words, an old XDCAM-50 file.
Since the content it's 25fps progressive, I'm simply gonna make a progressive flagged as interlaced, it's not a big deal, but the problem is how to do the tone-mapping.


1) Attempt 1: 65x65x65 LUT

I tried to make a LUT in order to convert the PQ curve to an old SDR one, applying a knee in order to avoid to get non-legal BT709 values.
I tried to adjust the power, the slope, and other parameters.

#Indexing
video=FFVideoSource("UHD05432.mxf")
audio1=FFAudioSource("UHD05432.mxf", track=3)
audio2=FFAudioSource("UHD05432.mxf", track=4)
audio3=FFAudioSource("UHD05432.mxf", track=5)
audio4=FFAudioSource("UHD05432.mxf", track=6)
audio5=FFAudioSource("UHD05432.mxf", track=7)
audio6=FFAudioSource("UHD05432.mxf", track=8)
audio=MergeChannels(audio1, audio2, audio3, audio4, audio5, audio6)
AudioDub(video, audio)

#Bringing everything to 16bit
ConvertBits(16)

#Downscale with 16bit precision
Spline64Resize(1920, 1080)

#Convert from YUV 4:2:2 to Planar RGB with 16bit precision
ConvertToPlanarRGB()

#Applying a 65x65x65 LUT with 16bit precision
Cube("C:\Programmi\AviSynth+\LUTs\PQ_to_BT709_slope_v2.cube")

#Converting from planar RGB to 4:2:2 planar with 16bit precision
Converttoyuv422()

#Dithering down to 8bit with the Floyd-Steinber error diffusion
ConvertBits(bits=8, dither=1)

Unfortunately, my sample got rejected.
The reason is that I didn't manage to make a LUT that produces a result accepted by the studio, no matter how many times I tried.




2) Attempt 2: HDR Tools

As a second attempt, I tried to use the filter written by Jean-Philippe Scotto Di Rinaldi: HDRTools.
I've been using his filter a few times for some amatorial HDR to SDR conversion and I also made a few tests in the past with some blurays and the results I got back then were quite nice, especially with Reinhard (old tests with bluray disks).

After a few other attempts, playing around with Hable, Mobius, Reinhard and even Scale, I managed to get the luma kinda close to the original as well as the chroma, however my sample got rejected again as it's still "not close enough":

Code:
#Indexing
video=FFVideoSource("UHD05432.mxf")
audio1=FFAudioSource("UHD05432.mxf", track=3)
audio2=FFAudioSource("UHD05432.mxf", track=4)
audio3=FFAudioSource("UHD05432.mxf", track=5)
audio4=FFAudioSource("UHD05432.mxf", track=6)
audio5=FFAudioSource("UHD05432.mxf", track=7)
audio6=FFAudioSource("UHD05432.mxf", track=8)
audio=MergeChannels(audio1, audio2, audio3, audio4, audio5, audio6)
AudioDub(video, audio)

#Bringing everything to 16bit
ConvertBits(16)

#Downscale with 16bit precision
Spline64Resize(1920, 1080)

#Converting YUV to XYZ with 16bit precision
ConvertYUVtoXYZ(Color=0, OutputMode=1, HDRMode=0, fullrange=false)

#Tone-mapping HDR PQ to SDR
ConvertXYZ_Reinhard_HDRtoSDR(exposure_X=6.9, contrast_X=0.9)

#Converting XYZ back to YUV with 16bit precision
ConvertXYZtoYUV(pColor=0)

#Converting to 4:2:2 planar with 16bit precision
Converttoyuv422()

#Dithering down to 8bit with the Floyd-Steinber error diffusion
ConvertBits(bits=8, dither=1)
I also tried with Scale by manually setting coefficients getting not so terrible results:

Code:
#Indexing
video=FFVideoSource("UHD05432.mxf")
audio1=FFAudioSource("UHD05432.mxf", track=3)
audio2=FFAudioSource("UHD05432.mxf", track=4)
audio3=FFAudioSource("UHD05432.mxf", track=5)
audio4=FFAudioSource("UHD05432.mxf", track=6)
audio5=FFAudioSource("UHD05432.mxf", track=7)
audio6=FFAudioSource("UHD05432.mxf", track=8)
audio=MergeChannels(audio1, audio2, audio3, audio4, audio5, audio6)
AudioDub(video, audio)

#Bringing everything to 16bit
ConvertBits(16)

#Downscale with 16bit precision
Spline64Resize(1920, 1080)

#Converting YUV to XYZ with 16bit precision
ConvertYUVtoXYZ(Color=0, OutputMode=1, HDRMode=0, fullrange=false)

#Tone-mapping HDR PQ to SDR
ConvertXYZ_Scale_HDRtoSDR(Coeff_X=33.3, Coeff_Y=34.2, Coeff_Z=34.2)

#Converting XYZ back to YUV with 16bit precision
ConvertXYZtoYUV(pColor=0)

#Converting to 4:2:2 planar with 16bit precision
Converttoyuv422()

#Dithering down to 8bit with the Floyd-Steinber error diffusion
ConvertBits(bits=8, dither=1)
I didn't manage to get any closer with Hable and Mobius.
This is as close as I got:



Unfortunately, though, as you can see, luma is pretty close but still not close enough as mid-high whites are too bright and I kinda need to bring them down without affecting the rest of the luma, however I don't know how to do it using HDRTools (if it's possible at all).
As a matter of fact, my sample got rejected once again.

3) Attempt 3: AVID Media Composer

I use AVID on a daily basis, however I think that it still lacks behind when it comes to 4K HDR.
I tried to make a simple XDCAM project and I imported the masterfile provided.
AVID asked me whether to apply an automatic "transform" which is basically a conversion it tries to do.
The result was horrible. Absolutely impossible to use.
I tried to modify it with the manual color correction mode, but it wasn't good at all.
I use AVID on a daily basis, but I've been using it to edit SDR BT709 contents only, I've never actually used it to tone-map HDR PQ to SDR.

4) Attempt 4: Davinci Resolve

When it comes to color correction, Davinci Resolve it's a great piece of software, but I don't generally use it, so I'm not very familiar with it (and I have the free version).
I quickly noticed that it has some default LUTs to do this kind of conversion and I tried to apply one of the default LUTs (PQ 4000 nits to Gamma 2.4) and it was the one that was closest to the result, but it was still too bright, so I tried to do it myself in Davinci.
I managed to get a pretty good result, as I was finally able to bring down the value of the mid-whites to make them resemble the official one, as well as several different blacks and whites, and I modified the saturation as well by grading each component individually, however I still wasn't able to get the blue right.
As result, my sample got rejected (again).


After all these attempts, I decided to ask here, 'cause even though I work in broadcast and I'm an encoder, I've never been a good colorist (shame on me, I know).
I'm pretty sure there are more experienced colorists that will be able to get something that won't get rejected.


Sample files:
- Official HDR PQ: Link
- Official SDR: Link
- My tone-mapping attempt with LUT: Link
- My tone-mapping attempt with HDRTools: Link
- My tone-mapping attempt with DavinciResolve: Link

The target is to get the tone-mapping as close as possible to the "Official SDR" provided by the major, so that the Studio will accept it and it will finally go on air.

Thank you in advance.
__________________
Broadcast Encoder
LinkedIn

Last edited by FranceBB; 1st December 2018 at 15:30.
FranceBB is offline   Reply With Quote
Old 1st December 2018, 17:05   #2  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 6,985
Have you also tried DGTonemap ?
http://rationalqm.us/mine.html
Atak_Snajpera is online now   Reply With Quote
Old 1st December 2018, 20:08   #3  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 637
Quote:
Originally Posted by Atak_Snajpera View Post
Have you also tried DGTonemap ?
http://rationalqm.us/mine.html
Actually, no, but it seems that it's based on "Reinhard", one of the algorithm included in HDRTools.

Quote:
DGTonemap Filter: Basic Reinhard tonemapping for HDR->SDR
I'll give it a shot, but it don't think that the result it's gonna be any different from the one I got with Reinhard inside HDRTools.
__________________
Broadcast Encoder
LinkedIn
FranceBB is offline   Reply With Quote
Old 1st December 2018, 21:32   #4  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 213
So you have an example video of what your conversion should look like? Sounds like you could use AvisynthOptimizer to find the optimal parameters for the HDRTools script. ConvertYUVtoXYZ has quite a few parameters that could be added there as well.

You should probably try to optimize the luma first (to make things easier) and if that succeeds then adjust the chroma parameters as well. The optimizer would only need one frame to compare, if it gets that right then more could be added to make sure the conversion works in every scene.
zorr is offline   Reply With Quote
Old 2nd December 2018, 11:17   #5  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,747
Have you tried also DGHDRtoSDR ?
You can get it here. Don't forget to read the manual...
The author worked a lot on it, and it produces very good results, and from what i've understood, he's done more than simple tonemap algorithm in his filter (mines are simple tonemap).
What i'm affraid of, is that your studio wants excellent/perfect results, which i don't think it's yet possible in actual HDR to SDR convertion.
__________________
My github.

Last edited by jpsdr; 2nd December 2018 at 11:20.
jpsdr is offline   Reply With Quote
Old 4th December 2018, 01:12   #6  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 637
Quote:
Originally Posted by zorr View Post
So you have an example video of what your conversion should look like? Sounds like you could use AvisynthOptimizer to find the optimal parameters for the HDRTools script.
I took a look at Avisynth Optimizer, but I can't manage to get it working.
I made the following script:

Code:
FFVideoSource("Official_SDR.mxf")

ConverttoYUY2()

tdeint(mode=2, order=-1, field=-1, mthreshL=6, mthreshC=6, map=0, type=2, debug=false, mtnmode=1, sharp=true, cthresh=6, blockx=16, blocky=16, chroma=true, MI=64, tryWeave=true, link=1, denoise=true, slow=2, opt=4)

Converttoyv16()

source=trim(0, 4958)

FFVideoSource("Official_HDR_PQ.mxf")

ConvertBits(16)

Spline64ResizeMT(1920, 1080)

ConvertYUVtoXYZ(Color=0, OutputMode=1, HDRMode=0, fullrange=false)

ConvertXYZ_Scale_HDRtoSDR(Coeff_X=33.3, Coeff_Y=34.2, Coeff_Z=33.3)

ConvertXYZtoYUV(pColor=0)

Converttoyuv422()

ConvertBits(bits=8, dither=1)

tonemapped=trim(0, 4958)


global total = 0.0
global ssim_total = 0.0
FrameEvaluate(last, """
	global ssim = SSIM_FRAME(source, tonemapped)
	global ssim = (ssim == 1.0 ? 0.0 : ssim)
	global ssim_total = ssim_total + ssim	
""")	

# measure runtime, plugin writes the value to global avstimer variable
global avstimer = 0.0
AvsTimer(frames=1, type=0, total=false, name="Optimizer")

# per frame logging (ssim, time)
delimiter = "; "
resultFile = "perFrameResults.txt"	# output out1="ssim: MAX(float)" out2="time: MIN(time) ms" file="perFrameResults.txt"
WriteFile(resultFile, "current_frame", "delimiter", "ssim", "delimiter", "avstimer")

# write "stop" at the last frame to tell the optimizer that the script has finished
frame_count = FrameCount()
WriteFileIf(resultFile, "current_frame == frame_count-1", """ "stop " """, "ssim_total", append=true)

return last
I successfully got the following logs for the first 4958 frames: https://pastebin.com/wELMQiTY

Then I tried to set a very large range of values to let the optimiser work:

Code:
FFVideoSource("Official_SDR.mxf")

ConverttoYUY2()

tdeint(mode=2, order=-1, field=-1, mthreshL=6, mthreshC=6, map=0, type=2, debug=false, mtnmode=1, sharp=true, cthresh=6, blockx=16, blocky=16, chroma=true, MI=64, tryWeave=true, link=1, denoise=true, slow=2, opt=4)

Converttoyv16()

source=trim(0, 4958)

FFVideoSource("Official_HDR_PQ.mxf")

ConvertBits(16)

Spline64ResizeMT(1920, 1080)

ConvertYUVtoXYZ(Color=0, OutputMode=1, HDRMode=0, fullrange=false)

Coeff_X = 33.3 # optimize Coeff_X = _n_ | 0.1..1000.1 | Coeff_X
Coeff_Y = 34.2 # optimize Coeff_Y = _n_ | 0.1..1000.1 | Coeff_Y
Coeff_Z = 33.3 # optimize Coeff_Z = _n_ | 0.1..1000.1 | Coeff_Z

ConvertXYZ_Scale_HDRtoSDR(Coeff_X=Coeff_X, Coeff_Y=Coeff_Y, Coeff_Z=Coeff_Z)

ConvertXYZtoYUV(pColor=0)

Converttoyuv422()

ConvertBits(bits=8, dither=1)

tonemapped=trim(0, 4958)


global total = 0.0
global ssim_total = 0.0
FrameEvaluate(last, """
	global ssim = SSIM_FRAME(source, tonemapped)
	global ssim = (ssim == 1.0 ? 0.0 : ssim)
	global ssim_total = ssim_total + ssim	
""")	

# measure runtime, plugin writes the value to global avstimer variable
global avstimer = 0.0
AvsTimer(frames=1, type=0, total=false, name="Optimizer")

# per frame logging (ssim, time)
delimiter = "; "
resultFile = "perFrameResults.txt"	# output out1="ssim: MAX(float)" out2="time: MIN(time) ms" file="perFrameResults.txt"
WriteFile(resultFile, "current_frame", "delimiter", "ssim", "delimiter", "avstimer")

# write "stop" at the last frame to tell the optimizer that the script has finished
frame_count = FrameCount()
WriteFileIf(resultFile, "current_frame == frame_count-1", """ "stop " """, "ssim_total", append=true)

return last
After that, I tried to make the optimiser start by creating a .bat with the following command line:

Code:
optimizer "I:\LUT\test.avs"

pause
However, it starts and crashes soon after.
It also ignores the "pause" command, so I can't see what error it gives.
Last but not least, the work directory is created, but it's empty.
(For the records, I do have Java 6, 7 and 8 installed).

This is what I get before it crashes:



These are the Java redistributables I have installed:



Out of records, I just opened the latest version of JDownloader2 on this machine and it works fine, so it's not Java.

EDIT: Oh, sorry, I got it, it wants integers, my bad, now it works:

Code:
FFVideoSource("Official_SDR.mxf")

ConverttoYUY2()

tdeint(mode=2, order=-1, field=-1, mthreshL=6, mthreshC=6, map=0, type=2, debug=false, mtnmode=1, sharp=true, cthresh=6, blockx=16, blocky=16, chroma=true, MI=64, tryWeave=true, link=1, denoise=true, slow=2, opt=4)

Converttoyv16()

source=trim(0, 4958)

FFVideoSource("Official_HDR_PQ.mxf")

ConvertBits(16)

Spline64ResizeMT(1920, 1080)

ConvertYUVtoXYZ(Color=0, OutputMode=1, HDRMode=0, fullrange=false)

Coeff_X = 33.3 # optimize Coeff_X = _n_ | 1..1000 | Coeff_X
Coeff_Y = 34.2 # optimize Coeff_Y = _n_ | 1..1000 | Coeff_Y
Coeff_Z = 33.3 # optimize Coeff_Z = _n_ | 1..1000 | Coeff_Z

ConvertXYZ_Scale_HDRtoSDR(Coeff_X=Coeff_X, Coeff_Y=Coeff_Y, Coeff_Z=Coeff_Z)

ConvertXYZtoYUV(pColor=0)

Converttoyuv422()

ConvertBits(bits=8, dither=1)

tonemapped=trim(0, 4958)


global total = 0.0
global ssim_total = 0.0
FrameEvaluate(last, """
	global ssim = SSIM_FRAME(source, tonemapped)
	global ssim = (ssim == 1.0 ? 0.0 : ssim)
	global ssim_total = ssim_total + ssim	
""")	

# measure runtime, plugin writes the value to global avstimer variable
global avstimer = 0.0
AvsTimer(frames=1, type=0, total=false, name="Optimizer")

# per frame logging (ssim, time)
delimiter = "; "
resultFile = "perFrameResults.txt"	# output out1="ssim: MAX(float)" out2="time: MIN(time) ms" file="perFrameResults.txt"
WriteFile(resultFile, "current_frame", "delimiter", "ssim", "delimiter", "avstimer")

# write "stop" at the last frame to tell the optimizer that the script has finished
frame_count = FrameCount()
WriteFileIf(resultFile, "current_frame == frame_count-1", """ "stop " """, "ssim_total", append=true)

return last


Quote:
Have you tried also DGHDRtoSDR ?
You can get it here. Don't forget to read the manual...
The author worked a lot on it, and it produces very good results, and from what i've understood, he's done more than simple tonemap algorithm in his filter (mines are simple tonemap).
I'm letting Avisynth Optimizer run with "Scale" as a basic option.
I'm gonna make it run with Reinhard from HDRTools after the first test and then I'll make it run with DGHDRtoSDR.
I downloaded it and I read the documentation; it seems something I can play a lot with. ^_^
__________________
Broadcast Encoder
LinkedIn

Last edited by FranceBB; 4th December 2018 at 01:50.
FranceBB is offline   Reply With Quote
Old 4th December 2018, 08:31   #7  |  Link
tormento
Acid fr0g
 
tormento's Avatar
 
Join Date: May 2002
Location: Italy
Posts: 1,030
Quote:
Originally Posted by FranceBB View Post
Out of records, I just opened the latest version of JDownloader2 on this machine and it works fine, so it's not Java.
Out of records: JD2 uses its own Java in .\jre\
__________________
@turment on Telegram
tormento is offline   Reply With Quote
Old 4th December 2018, 22:36   #8  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 213
Quote:
Originally Posted by FranceBB View Post
I took a look at Avisynth Optimizer, but I can't manage to get it working.
...
I successfully got the following logs for the first 4958 frames: https://pastebin.com/wELMQiTY
The log looks good. But you might want to trim the length a bit, it's going to take an awful long time to optimize thousands of frames...

Quote:
Originally Posted by FranceBB View Post
EDIT: Oh, sorry, I got it, it wants integers, my bad, now it works:

Code:
Coeff_X = 33.3 # optimize Coeff_X = _n_ | 1..1000 | Coeff_X
Coeff_Y = 34.2 # optimize Coeff_Y = _n_ | 1..1000 | Coeff_Y
Coeff_Z = 33.3 # optimize Coeff_Z = _n_ | 1..1000 | Coeff_Z
Yes, floats are not supported but you can emulate them with something like

Code:
Coeff_X = 3330/100.0 # optimize Coeff_X = _n_/100.0 | 1..100000 | Coeff_X
This would give an effective range of 0.01 - 1000.0 with steps of 0.01.

Quote:
Originally Posted by FranceBB View Post
I'm letting Avisynth Optimizer run with "Scale" as a basic option.
I'm gonna make it run with Reinhard from HDRTools after the first test and then I'll make it run with DGHDRtoSDR.
Nice, please report back if you have any difficulties and/or success with it.
zorr is offline   Reply With Quote
Old 5th December 2018, 22:52   #9  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 637
While Avisynth Optimizer is working, I tried to tone-map manually with DGHDRtoSDR.

First of all, it only supports 4:2:0 planar and I would rather not go from 4:2:2 to 4:2:0 and then back to 4:2:2 planar.

Anyway, I managed to get the luma right, almost identical, with just a few highlights off, however Chroma is not right, as the blue is off.

(tone-mapped left, original right).



I flipped the original (right) horizontally.
Pretend that the waveform it's a function and the two screens are 2 phi (pretend that the first half is phi and the second is phi).
If they were identical, the function would be continuous in 2phi; in other words "specular" (and if you look at the waveform, it almost is):



Anyway, colors are still not quite the same and as they are not, it would definitely get rejected.

Code:
FFVideoSource("Official_SDR.mxf")

ConverttoYUY2()

tdeint(mode=2, order=-1, field=-1, mthreshL=6, mthreshC=6, map=0, type=2, debug=false, mtnmode=1, sharp=true, cthresh=6, blockx=16, blocky=16, chroma=true, MI=64, tryWeave=true, link=1, denoise=true, slow=2, opt=4)
Spline64ResizeMT(848, 480)
Converttoyv16()
TurnRight.Histogram.TurnLeft
#FlipHorizontal()

source=trim(14, 4958)

FFVideoSource("Official_HDR_PQ.mxf")

ConvertBits(16)
Converttoyuv420(matrix="Rec2020")

Spline64ResizeMT(848, 480)

DGHDRtoSDR(impl="sw", fulldepth=false, light=178, gamma=0.42, hue=1.0, sat=0.9, tm=1.0, roll=0.5)

Converttoyuv422(matrix="Rec709")
TurnRight.Histogram.TurnLeft

tonemapped=trim(0, 4958)

StackHorizontal(tonemapped, source)
__________________
Broadcast Encoder
LinkedIn

Last edited by FranceBB; 5th December 2018 at 23:19.
FranceBB is offline   Reply With Quote
Old 5th December 2018, 23:26   #10  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 637
UPDATE

I got the results from Avisynth Optimizer and it actually helped me to tune DGHDRtoSDR Reinhard.
With the settings, then, I fine-tuned a bit and I managed to get pretty much the same results as the ones the major sent and the studio wants.
The results are pretty amazing and even though I still didn't manage to get the Chroma right, the luma it's pretty much the same across the whole video, which is amazing, you won't believe your eyes (but you'll believe to the waveform xD)!
Literally, hats off to Donald Graft.

Left DG Reinhard fine-tuned - Right official SDR flipped horizontally:





















__________________
Broadcast Encoder
LinkedIn
FranceBB is offline   Reply With Quote
Old 6th December 2018, 01:30   #11  |  Link
videoh
Registered User
 
Join Date: Jul 2014
Posts: 790
Quote:
Originally Posted by FranceBB View Post
The results are pretty amazing and even though I still didn't manage to get the Chroma right, the luma it's pretty much the same across the whole video, which is amazing, you won't believe your eyes (but you'll believe to the waveform xD)! Literally, hats off to Donald Graft.
Thank you, FranceBB. I spent a lot of time trying to get things right while keeping high performance. If you'd like to give me a stream and your script maybe there's something further I can do for your chroma issue. And BTW, that's a great way to present the results, very effective.

It's cool that the Avisynth Optimizer tool helped you to determine the good parameters. Definitely inspires me to experiment with it. Using your phrasing, hats off to the author.

Last edited by videoh; 6th December 2018 at 01:37.
videoh is offline   Reply With Quote
Old 6th December 2018, 02:32   #12  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,874
your screenshots don't match the waveforms, perhaps the screenshot method was incorrect ?

e.g if you crop them, flip one back to normal and look at a rgb histogram, they don't match. Or if you convert to YUV, the waveform doesn't match either
poisondeathray is offline   Reply With Quote
Old 6th December 2018, 03:53   #13  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 637
Quote:
Originally Posted by poisondeathray View Post
your screenshots don't match the waveforms, perhaps the screenshot method was incorrect ?

e.g if you crop them, flip one back to normal and look at a rgb histogram, they don't match. Or if you convert to YUV, the waveform doesn't match either
Uh... I think that Imgur screwed the images up by converting them to JPEG and doing something wrong during the conversion. I saved them as PNG lossless directly from AVSPmod.
It's late in the night over here, I'll upload them to another host tomorrow if needed.
__________________
Broadcast Encoder
LinkedIn
FranceBB is offline   Reply With Quote
Old 6th December 2018, 04:54   #14  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,874
Quote:
Originally Posted by FranceBB View Post
Uh... I think that Imgur screwed the images up by converting them to JPEG and doing something wrong during the conversion. I saved them as PNG lossless directly from AVSPmod.
It's late in the night over here, I'll upload them to another host tomorrow if needed.


The posted images are pngs, and have no color tag metadata possibly interfering (pngs can have gAMA and cHRM tags that specify gamma and chromacities - different viewing applications can handle them differently; not an issue here)

RGB histogram, animated gif


Y waveform, animated gif




I'm curious about the scene with the bright glow facing the wood railing/fence. Was this current method/settings able to match that roughly or do you still have the "glow" ? Looks like clipping in the official SDR version, perhaps before even mapping, or perhaps a high cutoff level in the algorithm
poisondeathray is offline   Reply With Quote
Old 6th December 2018, 11:09   #15  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 637
I still got the glow in that scene, but that glow is there in the official HDR version as well. I think that they have been graded individually and they specifically wanted to clip the values of the reflected light on the official SDR one, while they left them unclipped in the official HDR. Unfortunately, when the tone mapping algorithm tries to map it, it still has some pretty high white caused by the light. I'm pretty sure the colourist did that scene manually. (Out of curiosity, I managed to get the same grading when I modified that scene only in Davinci Resolve).
__________________
Broadcast Encoder
LinkedIn
FranceBB is offline   Reply With Quote
Old 6th December 2018, 22:45   #16  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 213
Quote:
Originally Posted by FranceBB View Post
UPDATE

I got the results from Avisynth Optimizer and it actually helped me to tune DGHDRtoSDR Reinhard.
With the settings, then, I fine-tuned a bit and I managed to get pretty much the same results as the ones the major sent and the studio wants.
The results are pretty amazing and even though I still didn't manage to get the Chroma right...
Great, makes me happy that the optimizer can help other people too. Perhaps the chroma issue can be solved with the optimizer by letting it optimize DGHDRtoSDR Reinhard.

Since you already have a very good set of parameters, I suggest you set those parameters in the script and use option "-initial script" and set the mutations smaller with something like "-mutamount 0.05 0.01". The optimizer will then start with your good settings and do a focused search around those.

Were you using the default search parameters? It's always possible to do a more thorough search by setting the "-iterations" higher (default is 2000).

Also consider only optimizing a very short clip or a single frame to make the search faster. Perhaps the optimal strategy would be to collect, say, 10 frames from different lighting conditions and optimize a clip that consists of only those. Then you can increase the -iterations and still get the results in a reasonable time frame.

Quote:
Originally Posted by videoh View Post
It's cool that the Avisynth Optimizer tool helped you to determine the good parameters. Definitely inspires me to experiment with it. Using your phrasing, hats off to the author.
Thanks videoh. If you do an experiment don't hesitate to ask for help or give feature suggestions.

Last edited by zorr; 6th December 2018 at 23:03.
zorr is offline   Reply With Quote
Old 2nd January 2019, 01:19   #17  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,146
Videos links all broken
lansing is offline   Reply With Quote
Old 2nd January 2019, 02:51   #18  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 637
They expired after a week, it's the way "WeTransfer" works. It's always been like that: once the problem is solved, they go offline. They are temporary files, there's no need to waste space to keep them online somewhere in the cloud. (I do the same when I reply to users with an encoded sample).
__________________
Broadcast Encoder
LinkedIn
FranceBB is offline   Reply With Quote
Reply

Tags
bt2020, bt2100, hdr to sdr, lut avisynth, tone-mapping

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 15:31.


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