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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 6th March 2017, 15:42   #1  |  Link
zub35
Registered User
 
Join Date: Oct 2016
Posts: 56
Convert HDR to SDR

Hello!
How to make HDR conversion in SDR (fullrange 8bit bt709)?

Here are two examples, HDR and SDR.
HDR 2160p (UBDRip): https://yadi.sk/i/wP4oZQjo3F6BnZ
SDR 1080p (BDRip): https://yadi.sk/i/aXC0fsF73F6Bnh

If use a conversion madVR
http://s012.radikal.ru/i319/1703/4a/30402f28b209.png
That result looks like this
http://screenshotcomparison.com/comp...2580/picture:0

upd: more samples https://cloud.mail.ru/public/2iEk/CiyUARGZy

Last edited by zub35; 23rd March 2017 at 14:34.
zub35 is offline   Reply With Quote
Old 6th March 2017, 16:55   #2  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,905
FFMpegSource2 or LibawVideoSource can dither it down to 8bit 2160p for you, then all you need is a resizer and colormatrix.

Something like:

FFMpegSource2("video.h265", fpsnum=24000, fpsden=1001)

Spline64Resize(1920, 1080)

Converttoyv12(interlaced=false, matrix="PC709")

It's really simple as that.
Feel free to use Spline64ResizeMT for better performance, or any other resizer. If you want even more quality, use NNEDI, even though, for downscaling, Spline64Resize is generally enough.
FranceBB is offline   Reply With Quote
Old 6th March 2017, 18:17   #3  |  Link
zub35
Registered User
 
Join Date: Oct 2016
Posts: 56
Quote:
Originally Posted by FranceBB View Post
FFMpegSource2 or LibawVideoSource can dither it down to 8bit 2160p for you, then all you need is a resizer and colormatrix.
Therein lies the difficulty, I could not figure out how to make this conversion, so that it is consistent with the result madVR and SDR-source
zub35 is offline   Reply With Quote
Old 6th March 2017, 20:54   #4  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Quote:
Originally Posted by FranceBB View Post
It's really simple as that.
No, it's not. Much more complicated.
sneaker_ger is offline   Reply With Quote
Old 7th March 2017, 01:21   #5  |  Link
MisterXDTV
Registered User
 
Join Date: Oct 2016
Posts: 17
I have the same problem: I don't know how to encode/convert an HDR sample to SDR. Is it possible with avisynth?
MisterXDTV is offline   Reply With Quote
Old 7th March 2017, 20:32   #6  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,905
Quote:
Originally Posted by zub35 View Post
Therein lies the difficulty, I could not figure out how to make this conversion, so that it is consistent with the result madVR and SDR-source
Ok, so if both ffms2 and libaw screw levels while dithering, then maybe how about using the 10bit hack to import the HDR source directly into avisynth and then use the Dither Tool to dither down to 8bit instead?
FranceBB is offline   Reply With Quote
Old 8th March 2017, 13:16   #7  |  Link
zub35
Registered User
 
Join Date: Oct 2016
Posts: 56
FranceBB, I think that the Y-component needs to be cut somehow before converting from 10 to 8 bits.

Simple conversion gives a faded result. Without contrast аs SDR.
MadVR does this via pixel shading, additionally applying filtering compress highlights.

From 10 bits to 8 bits, this is one case with the application of dithering.
But the conversion of HDR to SDR here is already a more complicated case, and is not limited to just dithering.

Example of a file with HDR and example necessary result - I gave. If necessary, I will provide more examples of HDR&SDR sources.

Maybe for proper conversion, is needed new plugin or new instructions in Avisynth+

Last edited by zub35; 8th March 2017 at 14:30.
zub35 is offline   Reply With Quote
Old 11th March 2017, 00:23   #8  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
Quote:
Originally Posted by FranceBB View Post
FFMpegSource2 or LibawVideoSource can dither it down to 8bit 2160p for you, then all you need is a resizer and colormatrix.

Something like:

FFMpegSource2("video.h265", fpsnum=24000, fpsden=1001)

Spline64Resize(1920, 1080)

Converttoyv12(interlaced=false, matrix="PC709")

It's really simple as that.
Feel free to use Spline64ResizeMT for better performance, or any other resizer. If you want even more quality, use NNEDI, even though, for downscaling, Spline64Resize is generally enough.
It's way more complex and to get decent results you need very clever adaptive algorithms. It needs something as revolutionary as e.g. NNEDI3 etc. Big companies (e.g. Dolby, Technicolor) are working on it.
kolak is offline   Reply With Quote
Old 12th March 2017, 02:15   #9  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,905
Unfortunately, yes, I noticed.
When I did it and I saw washed out colours and blacks I was disappointed as I didn't think it was a complex thing, but I was wrong.
FranceBB is offline   Reply With Quote
Old 12th March 2017, 08:45   #10  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 2,316
Quote:
Originally Posted by sneaker_ger View Post
No, it's not. Much more complicated.
Do you have a link, by any chance, which explain where the complexity lies ?
Because i didn't realy understand where it could be.
The only thing i may see whould be just if there is a non-linear function somewhere, and instead of just a linear matrix :
YUV (REC2020) -> RGB -> YUV (REC709)
you would have :
YUV (REC2020) -> (linear matrix) R'G'B' -> RGB (with non linear function) -> YUV (REC709) (linear matrix).
So, if you have any link which may explain the detail/specificiation of it, and why it's more complex, i'm curious.
jpsdr is offline   Reply With Quote
Old 12th March 2017, 13:29   #11  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
It is non-linear. I don't have a good link, though. Try searching for HDR10, Perceptual Quantizer (PQ) or SMPTE ST 2084PQ.
sneaker_ger is offline   Reply With Quote
Old 12th March 2017, 13:39   #12  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
Quote:
Originally Posted by FranceBB View Post
Unfortunately, yes, I noticed.
When I did it and I saw washed out colours and blacks I was disappointed as I didn't think it was a complex thing, but I was wrong.
Try using Resolve for this:

http://www.mysterybox.us/blog/2016/1...delivering-hdr
kolak is offline   Reply With Quote
Old 13th March 2017, 14:40   #13  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 2,316
I have the feeling i'm missing or don't understand something.
The video (in H265 for exemple), has to be decoded to "standard" RGB values to be displayed, otherwise the display will be wrong. I can understand that in the process of the creation of the UHD Blu-Ray (for exemple), there is some non-linear parts, but, after, this has to be displayed, so the decoder during one step of the process has to "reverse" this, to create a "standard" RGB. Meaning, there is a "simple" equation/formula to do this, otherwise, it would not be possible to display such streams.
... There something i've the feeling i'm missing...
jpsdr is offline   Reply With Quote
Old 13th March 2017, 15:32   #14  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,079
Have you seen this post in the VapourSynth thread? Looks interesting...
https://forum.doom9.org/showthread.p...67#post1800667
manolito is offline   Reply With Quote
Old 14th March 2017, 04:16   #15  |  Link
Andrew25
Registered User
 
Join Date: Mar 2017
Posts: 3
Quote:
Originally Posted by kolak View Post
That's a pretty useful link! Thanks for that.
Andrew25 is offline   Reply With Quote
Old 23rd March 2017, 10:07   #16  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 2,316
I've got informations here :
BT.2020
BT.709

From what i've understood (some, anyone else is free to read and correct me if necessary) :
The gama correction formula is the same between BT.709 and BT.2020.
But, in BT.2020, there is two YCbCr possibilities, when there is only one in BT.709.
If you are in what they call "Non-constant luminance", the standard linear matrix formula will work, and the usual method used for doing BT.601 <-> BT.709 conversion will also work with BT.2020.
But, if you are in what they call "Constant luminance", things are differents !
But with these documents, we have all necessary formula to make HDR/SDR conversion (i think...).
jpsdr is offline   Reply With Quote
Old 23rd March 2017, 11:11   #17  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
"Non-constant luminance" is used way more for Rec.2020.
For HDR you actually need to look at HDR10 (SMPTE ST-2084, HLG, etc), which I assume should give you some hint how to go from HDR to SDR. Also, looks like things going to be shifting into Rec.2100 with new ICtCp color space, which meant to improve compression by 10%.

Last edited by kolak; 23rd March 2017 at 11:20.
kolak is offline   Reply With Quote
Old 23rd March 2017, 11:17   #18  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 2,316
The problem, is if you are in "Non-constant luminance", i don't see what could prevent HDR/SDR conversion like described in post #2 working...
Except in post 2 it's missing BT.2020 somewhere...
I would see more
ConvertToRGB(matrix="REC2020") (don't remember exactly the name of matrix).
ConvertToYV12(matrix="PC709")
But according document, doing this should work on "Non-constant luminance".

Last edited by jpsdr; 23rd March 2017 at 11:23.
jpsdr is offline   Reply With Quote
Old 23rd March 2017, 11:25   #19  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
I don't know, but HDR to SDR is not trivial. It's more about how to shrink all these HDR info into much "tighter" SDR signal avoiding any tint, hue shifts etc. I know that eg. Technicolor is trying to make some tools for semi automated conversion. This tool analyses each scene an uses some adaptive conversion.

It ca be doe with fixed math- Resolve has node (and LUT) for it and this is rather simple fixed math.
kolak is offline   Reply With Quote
Old 23rd March 2017, 12:25   #20  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 2,316
I see nothing of the sort in the R-REC-BT.2020-2-201510-I!!PDF-E document, maybe this document is not enough to convert BT.2020 and don't cover the whole part, but i thought it would be...
Or... i've missed it in the document...?
Didn't see the edit part, i'll look for this.

Edit
Found things here on ITU... But access only to ITU users... Seems to be difficult to get proper informations.
It seems maybe there is things here. Bigger than others, it will take a little more time to understand properly i think.
There is also the R-REP-BT.2390-2016-PDF-E document.

Edit 2
WTF !!! I've begin to try to read the R-REC-BT.2100-0-201607-I!!PDF-E document, it's horrible, and yes... not so easy at all.

Last edited by jpsdr; 23rd March 2017 at 12:48.
jpsdr is offline   Reply With Quote
Reply


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 09:12.


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