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 > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 25th January 2018, 17:25   #41  |  Link
age
Registered User
 
Join Date: Oct 2015
Posts: 54
I've taken the formula for decomposing rgb to luma and come back(it gives different result from a classic rgb->yuv->rgb and it is faster) from here:https://www.google.it/amp/s/imdoingi...-blacks-3/amp/

The jhon hable tonemapping from here:http://filmicworlds.com/blog/filmic-...ing-operators/
age is offline   Reply With Quote
Old 25th January 2018, 19:36   #42  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 2,308
... I'm still unable to see the whole mathematical formula path .
I also don't see any formula with exposed_bias in your links...

I have no idea what is the mathematical results of such things
Code:
tm = core.std.Expr(c, expr="x  {exposure_bias} * 0.15 x  {exposure_bias} * * 0.05 + * 0.004 + x  {exposure_bias} * 0.15 x  {exposure_bias} * * 0.50 + * 0.06 + / 0.02 0.30 / -  ".format(exposure_bias=exposure_bias),format=vs.RGBS)#12=1200 nits / 100 nits

w = core.std.Expr(c, expr="{exposure_bias} 0.15 {exposure_bias} * 0.05 + * 0.004 + {exposure_bias} 0.15 {exposure_bias} * 0.50 + * 0.06 + / 0.02 0.30 / -  ".format(exposure_bias=exposure_bias),format=vs.RGBS)#  


c = core.std.Expr(clips=[tm,w], expr=" x  1 y  / *  ",format=vs.RGBS)
This is why, a "unrolled" explicit mathematical formula would be wonderfull...
I mean... Your script result in several mathematic formulas apllied step by step.
Is it possible to have the formula of each step ?

Last edited by jpsdr; 25th January 2018 at 19:42.
jpsdr is offline   Reply With Quote
Old 25th January 2018, 21:56   #43  |  Link
ifb
Registered User
 
Join Date: Dec 2009
Posts: 72
Quote:
Originally Posted by jpsdr View Post
... I'm still unable to see the whole mathematical formula path .
I also don't see any formula with exposed_bias in your links...

I have no idea what is the mathematical results of such things
Code:
tm = core.std.Expr(c, expr="x  {exposure_bias} * 0.15 x  {exposure_bias} * * 0.05 + * 0.004 + x  {exposure_bias} * 0.15 x  {exposure_bias} * * 0.50 + * 0.06 + / 0.02 0.30 / -  ".format(exposure_bias=exposure_bias),format=vs.RGBS)#12=1200 nits / 100 nits

w = core.std.Expr(c, expr="{exposure_bias} 0.15 {exposure_bias} * 0.05 + * 0.004 + {exposure_bias} 0.15 {exposure_bias} * 0.50 + * 0.06 + / 0.02 0.30 / -  ".format(exposure_bias=exposure_bias),format=vs.RGBS)#  


c = core.std.Expr(clips=[tm,w], expr=" x  1 y  / *  ",format=vs.RGBS)
This is why, a "unrolled" explicit mathematical formula would be wonderfull...
I mean... Your script result in several mathematic formulas apllied step by step.
Is it possible to have the formula of each step ?
I haven't looked at his script, but what you've quoted is the Hable operator from earlier in the thread. You can look at the VS plugin or ffmpeg if you want to see a C version.

https://github.com/ifb/vapoursynth-t.../tonemap.c#L44
ifb is offline   Reply With Quote
Old 26th January 2018, 09:55   #44  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 2,308
Ok, i'll try to figure out things with all i have for now.
jpsdr is offline   Reply With Quote
Old 27th January 2018, 10:40   #45  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 2,308
I've tried to read again the BT.2100 and BT.2390.
I'm still confused.
I'm unable to relate the formulas of OETF, EOTF, OOTF functions with the formulas of the tonemap functions you've all provided in your links. Where from the BT.2100 and BT.2390 did you get the formulas of the tonemap functions (what page, chapter ) ?
I'm still unable to figure out where the "white max" information is involved in the OETF, EOTF, OOTF functions...
jpsdr is offline   Reply With Quote
Old 27th January 2018, 19:40   #46  |  Link
age
Registered User
 
Join Date: Oct 2015
Posts: 54
EOTF and tonemapping are two different things, you could read about the st2084 formula in the official documentation or in the zimg code or elsewhere.
I've founded an interesting pdf about hdr and tonemapping
http://www.eusipco2016.org/documents...R_tutorial.pdf
at page 119 the EOTF formula.
At pages 100-107 some methods for the correction of the saturation.
From the first one I've done a vapoursynth function with only two parameters,(clip and source_peak)it's simple but at my eyes is better then my previous attempt

https://filebin.net/7c6kocrmxxnat1cp


Code:
import vapoursynth as vs
import tmsimple

core = vs.get_core()

c = core.ffms2.Source(source  = 'C:/.../testhdr.mkv')

c=core.resize.Bicubic(clip=c, format=vs.RGBS,filter_param_a=0.0,filter_param_b=0.75, range_in_s="limited", matrix_in_s="2020ncl", primaries_in_s="2020", primaries_s="2020", transfer_in_s="st2084", transfer_s="linear",dither_type="none", nominal_luminance=1000)


c=tmsimple.tm(clip=c,source_peak=1000)

c=core.resize.Bicubic(clip=c, format=vs.YUV420P8, filter_param_a=0.0, filter_param_b=0.75, matrix_s="709", primaries_in_s="2020", primaries_s="709", transfer_in_s="linear", transfer_s="709",dither_type="ordered")


c.set_output()
age is offline   Reply With Quote
Old 28th January 2018, 14:18   #47  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 2,308
Ok thanks, i'll read it.
jpsdr is offline   Reply With Quote
Old 14th April 2018, 22:59   #48  |  Link
jkilez
Registered User
 
Join Date: May 2014
Posts: 33
Quote:
Originally Posted by Magik Mark View Post
Is there a way to convert this to avisynth+?
There is now a tone-mapping plug-in for avisynth+: http://rationalqm.us/DGTonemap.rar

It supports both Hable and Reinhard methods.

Last edited by jkilez; 14th April 2018 at 23:01.
jkilez is offline   Reply With Quote
Old 16th April 2018, 20:32   #49  |  Link
MonoS
Registered User
 
Join Date: Aug 2012
Posts: 203
Some times ago i wrote a c++ implementation of the hable implementation in tmap, i don't remeber how much faster it is, but IIRC about 2x .

It only works for float input with mod8 resolution video and AVX CPU, i didn't bother writing an SSE implementation due to the high amount of FMAD instruction used.
The static buffer optimization only work on windows right now.

If i see any interest in this i'll try to add some functionality like the debug views, non mod8 support, etc

Here the repo https://github.com/MonoS/tmap-vapoursynth/tree/V1
MonoS is offline   Reply With Quote
Old 2nd January 2019, 06:31   #50  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Japanese television recently launched their 4k/8k broadcasting last month, here's a same frame comparison between a 1080p HD version and the 4k HDR version:

1080p:


4K HDR:


note: delete the last letter ("h") on the image name to get the original size.


None of the three methods in the tonemap plugin I've tested can map the 4k one to look like 1080 one. They all failed on the color mapping.
lansing is offline   Reply With Quote
Old 2nd January 2019, 07:27   #51  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,345
@lansing - does the original stream have metadata and parameters listed ? That can help guide what settings to use (or at least as a starting point)
poisondeathray is offline   Reply With Quote
Old 2nd January 2019, 08:58   #52  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Here's the sample clip, there's no metadata with the stream.

script I've tested:

Code:
rgb_clip = core.resize.Bicubic(clip, height=1080, width=1920, matrix_in_s="709", format=vs.RGBS)

# hable
tonemap_clip = core.tonemap.Hable(rgb_clip, exposure=7.0, a=0.10, b=0.50, c=0.10, d=0.20, e=0.01, f=0.08, w=5.2)

# mobius
tonemap_clip = core.tonemap.Mobius(rgb_clip, exposure=1.5, transition=0.9, peak=1.0)

#reinhard
tonemap_clip = core.tonemap.Reinhard(rgb_clip, exposure=1.5, contrast=0.5, peak=1.0)
The hable method is the only one that came close, but color are still off. The other two failed completely, as they have nothing to tweak.
lansing is offline   Reply With Quote
Old 7th January 2019, 20:19   #53  |  Link
ifb
Registered User
 
Join Date: Dec 2009
Posts: 72
Quote:
Originally Posted by lansing View Post
The hable method is the only one that came close, but color are still off. The other two failed completely, as they have nothing to tweak.
tonemap requires linear input and you still need to convert from 2020 to 709.

<edit>
I'm pretty sure it's HLG but with Rec.709 color, which is weird but I suppose they are worried about backward compatibility.

This is with zero tweaking, just copied from the tonemap examples:
Code:
c = core.ffms2.Source(source  = "4kbs_trim.mp4")
c = core.resize.Lanczos(clip=c, format=vs.RGBS, 
                        width=1920, height=1080,
                        matrix_in_s="709",
                        transfer_in_s="std-b67", transfer_s="linear",
                        nominal_luminance=1000)
c = core.tonemap.Mobius(clip=c, exposure=4)
c = core.resize.Lanczos(clip=c, format=vs.YUV420P10, matrix_s="709",
                        primaries_in_s="709",  primaries_s="709",
                        transfer_in_s="linear", transfer_s="709")

Last edited by ifb; 7th January 2019 at 20:51.
ifb is offline   Reply With Quote
Old 8th January 2019, 03:44   #54  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,345
Quote:
Originally Posted by HolyWu View Post
It seems that the stream is actually SDR rather than HDR even though the resolution is 4K. By definition, HDR video should have at least 10-bit color depth. And the stream is encoded in AVC, not HEVC. AVC-encoded HDR video is very uncommon.

^ this

If the goal was to "match" the other version, I'd probably just use normal color manipulation filters .
poisondeathray is offline   Reply With Quote
Old 8th January 2019, 17:59   #55  |  Link
age
Registered User
 
Join Date: Oct 2015
Posts: 54
Hi :-)
I would like to use normal color manipulation filters too for this video.
I've made a.cube file for the sdr match.
https://filebin.net/uu8l2zh4xso2gqd2



Code:
import vapoursynth as vs


core = vs.get_core()

c = core.lsmas.LibavSMASHSource(source= "C:/Users/..../4kbs_trim.mp4")




c=core.resize.Bicubic(clip=c, format=vs.RGB48, chromaloc_in_s="left", chromaloc_s="center", filter_param_a=0.0, filter_param_b=0.75, matrix_in_s="2020ncl",  range_in_s="limited",dither_type="none") 
c=core.timecube.Cube(c, cube="C:/..../Videos/4kbshdr.cube")
c=core.resize.Bicubic(clip=c, format=vs.YUV420P8, chromaloc_in_s="center", chromaloc_s="left",matrix_s="709", filter_param_a=0.0, filter_param_b=0.75, range_in_s="full", range_s="limited",dither_type="none")


c.set_output()

Last edited by age; 8th January 2019 at 19:02.
age is offline   Reply With Quote
Old 8th January 2019, 21:05   #56  |  Link
ifb
Registered User
 
Join Date: Dec 2009
Posts: 72
HLG has a different look ("natural" to use BBC/BT.2408 terminology) versus the "traditional" look of SDR. To convert, you need to do a scene-referred conversion, which is not exposed in z.lib/vapoursynth. You can patch z.lib and build your own custom vapoursynth.dll, but really you're just better off using a LUT like shown.

The BBC has some official .cube files they provide for doing this sort of thing.
ifb is offline   Reply With Quote
Old 8th January 2019, 22:11   #57  |  Link
age
Registered User
 
Join Date: Oct 2015
Posts: 54
That video doesn't look hdr, but more like an hdr video converted to rec709 without tonemapping
for example with hable tonemapping for 1000 nits
Code:
import vapoursynth as vs


core = vs.get_core()
c = core.lsmas.LibavSMASHSource(source= "C:/Users//Desktop/4kbs_trim.mp4")




c=core.resize.Bicubic(clip=c, format=vs.RGBS,filter_param_a=0.0,filter_param_b=0.75, range_in_s="limited", matrix_in_s="2020ncl",  chromaloc_in_s="left", chromaloc_s="center", transfer_in_s="709", transfer_s="linear",dither_type="none")

#insert here tonemapping 1000nits
#exposure_bias=10
#tm = core.std.Expr(c, expr="x  {exposure_bias} * 0.15 x  {exposure_bias} * * 0.05 + * 0.004 + x  {exposure_bias} * 0.15 x  {exposure_bias} * * 0.50 + * 0.06 + / 0.02 0.30 / -  ".format(exposure_bias=exposure_bias))
#w=((exposure_bias*(0.15*exposure_bias+0.10*0.50)+0.20*0.02)/(exposure_bias*(0.15*exposure_bias+0.50)+0.20*0.30))-0.02/0.30
#tm = core.std.Expr(clips=[tm,c], expr="x  1 {w}  / * ".format(exposure_bias=exposure_bias,w=w))



c=core.resize.Bicubic(clip=c, format=vs.RGBS, transfer_in_s="linear", transfer_s="709",dither_type="none")
c=core.resize.Bicubic(clip=c, format=vs.YUV420P8, chromaloc_in_s="center", chromaloc_s="left", filter_param_a=0.0, filter_param_b=0.75, range_in_s="full", range_s="limited", matrix_s="709",dither_type="none")





c.set_output()
it gives me this
age is offline   Reply With Quote
Old 9th January 2019, 09:05   #58  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Quote:
Originally Posted by age View Post
That video doesn't look hdr, but more like an hdr video converted to rec709 without tonemapping
I think you're right, it turns out that the recorder has an older model 4K TV that doesn't support HDR, and the tv just converted it into something else.
lansing is offline   Reply With Quote
Old 10th January 2019, 19:08   #59  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Ok after reading the hable reference article from ifb's tonemap page, I just realized that hable is not for 4k hdr tv to sdr conversion. It was created for images and SDR games to make them looks HDR. So this whole approach to use it for "4K HDR TV content -> SDR" is just wrong. The right tool for this in vapoursynth is DGHDRtoSDR.
lansing is offline   Reply With Quote
Old 10th January 2019, 19:20   #60  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Quote:
Originally Posted by lansing View Post
So this whole approach to use it for "4K HDR TV content -> SDR" is just wrong. The right tool for this in vapoursynth is DGHDRtoSDR.
So, maybe you know a solution to my problem too. See: DGHDRtoSDR lacking in contrast

Which also makes me wonder, would there be a way for DGHDRtoSDR to extract values like 'Max luminance: 1000' from the metadata itself?
__________________
Gorgeous, delicious, deculture!
asarian is offline   Reply With Quote
Reply

Tags
hdr, sdr

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 11:18.


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