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 Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 30th May 2018, 11:11   #1  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
Plugin HDRTools for Avisynth

This is a plugin with functions made to work on HDR videos, but can also eventualy work to do some color conversions.

Current version: 0.4.2

Sources are here.
Binaries are here.

Change list:
14/08/2018 v0.4.2 : Update ReadMe, minor changes.
10/08/2018 v0.4.1 : Minor changes.
09/08/2018 v0.4.0 : Some fix on HLG, rename and change of HDRtoSDR/SDRtoHDR functions, add Hable, Mobius and Reinhard tonemap (formula from Vapoursynth). Reinhard uses the "exposure" parameter.
03/08/2018 v0.3.1 : Fix some crash issues.
31/07/2018 v0.3.0 : Add HLG support, update PDF document.
08/06/2018 v0.2.0 : Add support of float planar RGB input/ouput on ConvertXYZtoRGB and ConvertRGBtoXYZ. Add document.
30/05/2018 v0.1.0 : Initial release.

Note about HDR HLG:
For speed-up:
8 bits input use 3D lookup (startup is slow).
10 and 12 bits use 2D lookup (startup is slow), but there is a resolution loss noticeable effect on low values.

Note about YV12/YV16/YV24 input/ouput:
For ConvertYUVtoxxx functions, convertion to YV24 if input is not YV24 is "quick".
If you want a true correct precise/perfect convertion, i would avise you to use a resampler and feed directly to YV24.
For ConvertxxxtoYUV functions, if you choose an ouput different from YV24, same remark, convertion is "quick".
If you want a true correct precise/perfect convertion, i would avise you to ouput to YV24, and use a resampler to achieve the real output format you want.

The functions avaible in this plugin are:

ConvertYUVtoLinearRGB(int Color,int OutputMode,int HDRMode,float HLGLb,float HLGLw,int HLGColor,bool OOTF,bool EOTF,bool fullrange,bool mpeg2c,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)
ConvertLinearRGBtoYUV(int Color,int OutputMode,int HDRMode,float HLGLb,float HLGLw,int HLGColor,bool OOTF,bool EOTF,bool fullrange,bool mpeg2c,bool fastmode,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)

ConvertYUVtoXYZ(int Color,int OutputMode,int HDRMode,float HLGLb,float HLGLw,int HLGColor,bool OOTF,bool EOTF,bool fullrange,bool mpeg2c,float Rx,float Ry,float Gx,float Gy,float Bx,float By,float Wx,float Wy,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)
ConvertXYZtoYUV(int Color,int OutputMode,int HDRMode,float HLGLb, float HLGLw,int HLGColor,bool OOTF,bool EOTF,bool fullrange,bool mpeg2c,bool fastmode,float Rx,float Ry,float Gx,float Gy,float Bx,float By,float Wx,float Wy,int pColor,float pRx,float pRy,float pGx,float pGy,float pBx,float pBy,float pWx,float pWy,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)

ConvertRGBtoXYZ(int Color,int OutputMode,int HDRMode,float HLGLb,float HLGLw,int HLGColor,bool OOTF,bool EOTF,bool fastmode,float Rx,float Ry,float Gx,float Gy,float Bx,float By,float Wx,float Wy,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)
ConvertXYZtoRGB(int Color,int OutputMode,int HDRMode,float HLGLb,float HLGLw,int HLGColor,bool OOTF,bool EOTF,bool fastmode,float Rx,float Ry,float Gx,float Gy,float Bx,float By,float Wx,float Wy,int pColor,float pRx,float pRy,float pGx,float pGy,float pBx,float pBy,float pWx,float pWy,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)

ConvertXYZ_Scale_HDRtoSDR(float Coeff_X,float Coeff_Y,float Coeff_Z,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)
ConvertXYZ_Scale_SDRtoHDR(float Coeff_X,float Coeff_Y,float Coeff_Z,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)

ConvertXYZ_Hable_HDRtoSDR(float exposure_X,float whitescale_X,float a_X,float b_X,float c_X,float d_X,float e_X,float f_X,float exposure_Y,float whitescale_Y,float a_Y,float b_Y,float c_Y,float d_Y,float e_Y,float f_Y,float exposure_Z,float whitescale_Z,float a_Z,float b_Z,float c_Z,float d_Z,float e_Z,float f_Z,int pColor,float pRx,float pRy,float pGx,float pGy,float pBx,float pBy,float pWx,float pWy,bool fastmode,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)
ConvertRGB_Hable_HDRtoSDR(float exposure_R,float whitescale_R,float a_R,float b_R,float c_R,float d_R,float e_R,float f_R,float exposure_G,float whitescale_G,float a_G,float b_G,float c_G,float d_G,float e_G,float f_G,float exposure_B,float whitescale_B,float a_B,float b_B,float c_B,float d_B,float e_B,float f_B,bool fastmode,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)

ConvertXYZ_Mobius_HDRtoSDR(float exposure_X,float transition_X,float peak_X,float exposure_Y,float transition_Y,float peak_Y,float exposure_Z,float transition_Z,float peak_Z,int pColor,float pRx,float pRy,float pGx,float pGy,float pBx,float pBy,float pWx,float pWy,bool fastmode,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)
ConvertRGB_Mobius_HDRtoSDR(float exposure_R,float transition_R,float peak_R,float exposure_G,float transition_G,float peak_G,float exposure_B,float transition_B,float peak_B,bool fastmode,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)

ConvertXYZ_Reinhard_HDRtoSDR(float exposure_X,float contrast_X,float peak_X,float exposure_Y,float contrast_Y,float peak_Y,float exposure_Z,float contrast_Z,float peak_Z,int pColor,float pRx,float pRy,float pGx,float pGy,float pBx,float pBy,float pWx,float pWy,bool fastmode,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)
ConvertRGB_Reinhard_HDRtoSDR(float exposure_R,float contrast_R,float peak_R,float exposure_G,float contrast_G,float peak_G,float exposure_B,float contrast_B,float peak_B,bool fastmode,int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch)

Brief description of most important parameters:
Color: Set the colorspace mode of the data.
OutputMode: Set the output data mode.
HDRMode: Set the HDR mode (PQ or HLG).
OOTF: Allow the output of linear displayed data instead of linear scene data.

See the ReadMe file for more informations and descriptions of the functions and their parameters.

Note about linear values:
For ConvertYUVtoxxx functions, the output is :
For HDR data (Color=0), HDRMode=(0 or 1), the output (R,G,B stage) is normalized for 1.0=10000 cd/mē (or 255 or 65535).
For SDR data (Color<>0),the output (R,G,B stage) is normalized for 1.0=100 cd/mē (or 255 or 65535).
For ConvertxxxtoYUV functions, the input is :
For HDR data (Color=0), HDRMode=(0 or 1),the input (R,G,B stage) is normalized for 1.0=10000 cd/mē (or 255 or 65535).
For SDR data (Color<>0),the input (R,G,B stage) is normalized for 1.0=100 cd/mē (or 255 or 65535).

Note: ConvertXYZ_Scale_HDRtoSDR is a simple scalar function, i've made just to see what result it produces. Don't have expectations on this plugin, but if by luck it works for you...

In the Document directory i've put a pdf file describing how things work, with detailled explainations and formula.

Some exemples:
BT.2020 to BT.709 convertion, do the following:
Code:
ConvertYUVtoXYZ(Color=1)
ConvertXYZtoYUV(pColor=1)
BT.709 to BT.2020 convertion, do the following:
Code:
ConvertYUVtoXYZ()
ConvertXYZtoYUV(Color=1,pColor=2)
HDR HLG (with mastering Lw at 1500 and HLG mastering display colorspace BT.2020) to HDR PQ convertion:
Code:
ConvertYUVtoLinearRGB(Color=0,HDRMode=1,HLGLw=1500,OOTF=false)
ConvertLinearRGBtoYUV(Color=0,OOTF=false)
HDR PQ to HDR HLG (with mastering Lw at 1200 and HLG mastering display colorspace BT.709) convertion:
Code:
ConvertYUVtoLinearRGB(Color=0,OOTF=false)
ConvertLinearRGBtoYUV(Color=0,HDRMode=1,HLGLw=1200,HLGColor=2,OOTF=false)
__________________
My github.

Last edited by jpsdr; 14th August 2018 at 17:49.
jpsdr is offline   Reply With Quote
Old 30th May 2018, 11:17   #2  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
Some pre-release, for people to try and make feedback.
Don't get hope yet, these are tools for me for working on a real HDR to SDR. I have something i want to try. It will take a long time, and i don't even know if it will work, but i'm curious to try.
For now, the HDRtoSDR is not working, it's a simple linear scalling i just made for simple testing. But all the others functions are supposed to work (unless bug found).

I'll probably add a little later the simple standard tonemap commonly used.

Feel free to comment, feedback, and correct me if i have misunderstood how things work.
__________________
My github.
jpsdr is offline   Reply With Quote
Old 4th June 2018, 10:07   #3  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
Note on use : If your chromaticity parameters are the same of the BT.xxxxx defined by the Color parameter, there is no need to specify them.
I'm working on a pdf document, which will explain and detail all of the formulas used, and the process and how i'm doing things, i hope i'll be able to put it with next release, but will not be before a week or two.
You'll be welcome at the time to read it, and most of it, correct me if there was things i've misunderstood.
Stay tuned...

Otherwise, about perfomance, as i'm purely soft, even multi-threaded and vectorized ASM, DGHDRtoSDR will always beats this plugin, a lot !!!
Also, i didn't thought the simple linear scaling would realy produce interesting result, as i just made quick it in the meantime, focussing for now on my real needs, the YUV/XYZ/YUV converters.
__________________
My github.

Last edited by jpsdr; 4th June 2018 at 10:14.
jpsdr is offline   Reply With Quote
Old 4th June 2018, 17:57   #4  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
Some quick benchmark on my system :
Code:
Coeff=50.0
Colorbars(width=1920,height=804,pixel_type="yv12").killaudio().assumefps(25,1).trim(0,999)
ConvertYUVtoXYZ(Color=0,OutputMode=1,Rx=0.680,Ry=0.320,Gx=0.265,Gy=0.690,Bx=0.150,By=0.060)
ConvertXYZ_HDRtoSDR(Coeff_X=Coeff,Coeff_Y=Coeff,Coeff_Z=Coeff)
ConvertXYZtoYUV()
288.9fps

Code:
Coeff=50.0
Colorbars(width=3840,height=1608,pixel_type="yv12").killaudio().assumefps(25,1).trim(0,999)
ConvertYUVtoXYZ(Color=0,OutputMode=1,Rx=0.680,Ry=0.320,Gx=0.265,Gy=0.690,Bx=0.150,By=0.060)
ConvertXYZ_HDRtoSDR(Coeff_X=Coeff,Coeff_Y=Coeff,Coeff_Z=Coeff)
ConvertXYZtoYUV()
47.66 fps

And real life 4k file bench :
Code:
Coeff=50.0
DGSource("DCrystal.dgi",i420=false,deinterlace=0,fieldop=0,fulldepth=true).crop(0,276,0,-276).trim(12632,12731)
ConvertYUVtoXYZ(Color=0,OutputMode=1,Rx=0.680,Ry=0.320,Gx=0.265,Gy=0.690,Bx=0.150,By=0.060)
ConvertXYZ_HDRtoSDR(Coeff_X=Coeff,Coeff_Y=Coeff,Coeff_Z=Coeff)
ConvertXYZtoYUV()
29.0fps
__________________
My github.

Last edited by jpsdr; 4th June 2018 at 19:36.
jpsdr is offline   Reply With Quote
Old 4th June 2018, 18:56   #5  |  Link
videoh
Registered User
 
Join Date: Jul 2014
Posts: 546
And what is your system please?
videoh is offline   Reply With Quote
Old 4th June 2018, 19:36   #6  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
A Broadwell 10 cores (i7-6950X) overclocked @4.1GHz.
__________________
My github.
jpsdr is offline   Reply With Quote
Old 4th June 2018, 21:19   #7  |  Link
videoh
Registered User
 
Join Date: Jul 2014
Posts: 546
Thanks.
videoh is offline   Reply With Quote
Old 4th June 2018, 22:12   #8  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 376
You have no idea how long I've been waiting for this.
Very appreciated! Thank you very much indeed!
__________________
Broadcast Encoder
FranceBB is online now   Reply With Quote
Old 5th June 2018, 09:06   #9  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
Happy to see it's usefull to some people. But i warn again, unless bug found, everything is expected to work properly, except the HDR to SDR wich is just a multiply scaling, i've just made it out of curiosity to see what result a very simple thing would produce, without expectation of course, because if it would have been so simple, it would have been done a long time ago.
I'll had for 0.2 input RGBPS on ConvertRGBtoXYZ and ConvertLinearRGBtoYUV.
With also a document explaining things more precisely.
After, for 0.3, i'll try to add the standard tonemap. They are "simple" functions (multiply, div, add, sub), so, they can be vectorized.
And then, i'll "slowly" or "quietly" work on the real HDR to SDR process i want to try, but don't know if it will produce results...
__________________
My github.
jpsdr is offline   Reply With Quote
Old 8th June 2018, 15:03   #10  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
New version, and i've added a document with the release.
So, feel free to read it, and provide feedback in case i was doing things wrong, and/or misunderstood things.
__________________
My github.
jpsdr is offline   Reply With Quote
Old 10th June 2018, 09:06   #11  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
I've updated the 0.2 file (no changes in the binaries) with a new version of the document, a few very minor corrections on it.
__________________
My github.
jpsdr is offline   Reply With Quote
Old 14th June 2018, 13:57   #12  |  Link
Yanak
Registered User
 
Join Date: Oct 2011
Posts: 250
Hello jpsdr,

It's the first time i have a HDR file and try to do something with it so please forgive me if I'm asking silly things but after spending a couple of hours on this i didn't manage to get things working correctly.

This if the file mediaInfo from the mkv container :
Quote:
Video
ID : 1
Format : HEVC
Format/Info : High Efficiency Video Coding
Commercial name : HDR10
Format profile : Main 10@L5.1@High
Codec ID : V_MPEGH/ISO/HEVC
Duration : 2 h 1 min
Bit rate : 45.2 Mb/s
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0 (Type 2)
Bit depth : 10 bits
Bits/(Pixel*Frame) : 0.227
Stream size : 40.6 GiB (85%)
Default : Yes
Forced : No
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant
Mastering display color primaries : Display P3
Mastering display luminance : min: 0.0000 cd/m2, max: 1100 cd/m2
I first open the file with DSS2 or FFVideoSource ( of course the colors are off here), i don't have and not yet tried with DGSource like in your real life 4k file bench script, I'm not sure if i need this or if DSS2 or FFms2/ffvideosource are enough.

I then tried to add like in your first post
Code:
ConvertYUVtoXYZ(Color=1)
ConvertXYZtoYUV(pColor=1)
plus tried a few other variations, i get the colors shifting but not getting the right colors out in avisynth, It's my first time messing with HDR stuff and i'm not sure if i am doing something wrong with your plugin or if the HEVC video is the problem, so if you have any hints to share please.

Thanks a lot ( and thanks for your very useful Avisynth plugins pack while i'm at it )

Last edited by Yanak; 14th June 2018 at 14:13.
Yanak is offline   Reply With Quote
Old 14th June 2018, 16:36   #13  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
First, again, as i've explained several times, the plugin do only XYZ/RGBLinear conversion, but the HDR to SDR part is not realy properly implemented, there is only a simple quick linear scaling which may produce results on some case, but that's all.
If you want try something like this :
Code:
Coeff=20.0
ConvertYUVtoXYZ(Color=0,OutputMode=1)
ConvertXYZ_HDRtoSDR(Coeff_X=Coeff,Coeff_Y=Coeff,Coeff_Z=Coeff)
ConvertXYZtoYUV()
Your mediainfo information doesn't provide the chromaticity parameters metadata, so the script assume default for BT.2100.
Try different values of Coeff.
But again, for now, the HDR to SDR part is not realy implemented.
__________________
My github.
jpsdr is offline   Reply With Quote
Old 14th June 2018, 16:57   #14  |  Link
Yanak
Registered User
 
Join Date: Oct 2011
Posts: 250
Thanks a lot for the reply,

Will give more tries later at night and dig a bit more into this, never had to deal with HDR content before and i am still discovering all this.

Thank you very much for the hint.

Edit :
Got it working and displaying the right colors now, might need a little tweak with levels or hue/sat but it's good already, thanks again for the help.
I looked to see if i could get more infos about the chromacity on it but the only thing mediainfo is giving me that i forgot to post is "Writing library: ATEME Titan KFE 3.7.3 (4.7.3.1001)" and i don't think this will help anyways.

It's the first time i have to deal with such material and probably won't have to do this a lot in the near future so thank your very much for the help and patience with a nooby in this domain.

Last edited by Yanak; 15th June 2018 at 08:26.
Yanak is offline   Reply With Quote
Old 19th June 2018, 08:56   #15  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
Message to Narkyy (from another realm). Can you tell me what is your issue between 0.1 and 0.2 version ?

Edit :
Ok, reproduce and found. Will be fixed in next release.
__________________
My github.

Last edited by jpsdr; 19th June 2018 at 14:36.
jpsdr is offline   Reply With Quote
Old 19th June 2018, 15:13   #16  |  Link
videoh
Registered User
 
Join Date: Jul 2014
Posts: 546
With the AVX2 build disabled, this test is being hit with b2[i] equal to zero.

if (fabs(b2[i])<=_zero) return(-2);

I guess you already found it.
videoh is offline   Reply With Quote
Old 19th June 2018, 16:44   #17  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,636
I'll push soon (time for me to get back home) the fix on github, you'll be able to make a build if you want.
__________________
My github.
jpsdr is offline   Reply With Quote
Old 19th June 2018, 17:34   #18  |  Link
videoh
Registered User
 
Join Date: Jul 2014
Posts: 546
Great, thank you.
videoh is offline   Reply With Quote
Old 20th June 2018, 22:27   #19  |  Link
videoh
Registered User
 
Join Date: Jul 2014
Posts: 546
I wonder if you should consider renaming your package to avoid confusion with this:

https://gitlab.com/standards/HDRTools/
videoh is offline   Reply With Quote
Old 20th June 2018, 23:34   #20  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,904
Quote:
I wonder if you should consider renaming your package to avoid confusion with this:
Good idea, there have been such confilcts before on D9 [even if linked one aint on D9], HdrToolKit, or something, perhaps.
I once was attending a computer show where one of my lumps of s/w was only in demo form (could not manage to complete in time),
and a game with identical name was released at same show, I had to make a quick name change [which turned out to be better I think],
and avoided what could have been a few legal wrangles, and lots of user confusion.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS 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 21:41.


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