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 > Programming and Hacking > Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 17th August 2020, 22:08   #41  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 1,165
Quote:
Originally Posted by wswartzendruber View Post
I've noticed that VLC tone maps HLG differently depending on OS, which is strange.

Anyway, I also remember the release notes for 3.0.0 saying that they corrected HLG tone mapping.
Since you have the latest version of VLC, can you try to compare its HLG tonemapping to the one done by MPV? It would be interesting to see how they look like and whether the VLC guys actually really improved it compared to years ago.
FranceBB is offline   Reply With Quote
Old 17th August 2020, 23:59   #42  |  Link
butterw2
Registered User
 
Join Date: Jun 2020
Posts: 111
VLC uses different video output APIs vs OS.
Default on Win10 is Dx11. If you check the changelog you will see there have been a number of HDR updates for this mode in the last year.

there is also an OpenGL for windows mode.

Dx9 doesn't do tonemapping without using a shader.
butterw2 is offline   Reply With Quote
Old 18th August 2020, 02:35   #43  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
Quote:
Originally Posted by FranceBB View Post
Since you have the latest version of VLC, can you try to compare its HLG tonemapping to the one done by MPV? It would be interesting to see how they look like and whether the VLC guys actually really improved it compared to years ago.
Here you go; VLC is on the top in each one while MPV is on the bottom: https://imgur.com/a/2JeNJvT

I was blown away by this at first. MPV seems to handle 2020->709 conversion with dramatic superiority along with having much more pleasing gamma. In fact with MPV, I can't even tell it wasn't graded natively in 709.

Last edited by wswartzendruber; 18th August 2020 at 02:37.
wswartzendruber is offline   Reply With Quote
Old 18th August 2020, 09:57   #44  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 1,165
Quote:
Originally Posted by wswartzendruber View Post
Here you go; VLC is on the top in each one while MPV is on the bottom: https://imgur.com/a/2JeNJvT
Thanks.

Quote:
Originally Posted by wswartzendruber View Post
I was blown away by this at first. MPV seems to handle 2020->709 conversion with dramatic superiority along with having much more pleasing gamma. In fact with MPV, I can't even tell it wasn't graded natively in 709.
Yeah, that's exactly what I was talking about when I said that I switched to MPV years ago. Looks like VLC did improve, but it still lacks behind MPV when it comes to tone-mapping HDR contents.
FranceBB is offline   Reply With Quote
Old 28th August 2020, 05:59   #45  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
Two things:

1. MPV on Linux is using luminance mapping. Bright specular areas will dim over a couple of seconds, and it's not part of the movie.

2. VLC on Windows doesn't exhibit this and looks much better than VLC on Linux.
wswartzendruber is offline   Reply With Quote
Old 11th September 2020, 07:18   #46  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
I finally got to watch my encodes on a HLG display, a Samsung from either this year or last. It was absolutely abysmal. The TV correctly detected the gamma curve as HLG, and I disabled the TV's enhancements for everything, but it just looked bland and washed out.

Luminance

I could see the TV continually adjusting the brightness level depending on the average luminance of the frame being shown. I'm not understanding why it wouldn't just apply tone mapping similar to VLC and MPV, although much less aggressively. The tone mapping used would depend on what the TV's brightness is set to. The higher the brightness setting, the more quickly specular detail gets compressed. This...shouldn't be hard.

Color

I don't know how to describe this other than "underwhelming."

HEVC Decode

On my PC, the HEVC decoding is exceptional. For movies where I instructed x265 to preserve grain, that comes through nicely. Whereas with this television, each frame seemed more like a matte painting. I wasn't quite sure what I was even looking at or how messed up the decode filtering would have to be to produce this result.

This isn't the result I was looking for. My converter only does linear brightness adjustment followed by gamma conversion. That's it.

Last edited by wswartzendruber; 11th September 2020 at 07:21.
wswartzendruber is offline   Reply With Quote
Old 13th October 2020, 00:31   #47  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
I did The Matrix.

https://imgur.com/gallery/SL3NYCe

What surprises me is how overly bright and washed out the 2018 Blu-ray release is.
wswartzendruber is offline   Reply With Quote
Old 13th October 2020, 11:25   #48  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 1,165
For me, the worst thing about Matrix is the green-ish tint they spread everywhere on the SDR BD.
I mean, I know it's an artistic choice, but still...
Thankfully, the HDR BD isn't affected, as your MPV preview shows.
Your version looks good too, by the way.
FranceBB is offline   Reply With Quote
Old 24th October 2020, 23:02   #49  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
Is there a defacto standard tonemapping algorithm for compressing +1,000 nit brightness levels down to within 1,000 nits?

HDR TVs are doing something to apply metadata...

Right now, pq2hlg is just hard-clipping.
wswartzendruber is offline   Reply With Quote
Old 24th October 2020, 23:56   #50  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 1,165
Oh no, you don't want to hard-clip it!
As you're working with curves, just knee it down to the desired level.
I think that applying a knee is a far better approach than brutally clipping values above 1000 nits
FranceBB is offline   Reply With Quote
Old 25th October 2020, 19:08   #51  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
Quote:
Originally Posted by FranceBB View Post
Oh no, you don't want to hard-clip it!
As you're working with curves, just knee it down to the desired level.
I think that applying a knee is a far better approach than brutally clipping values above 1000 nits
It looks like I need to apply the Rec.2020 coefficients to the RGB tuple to get that pixel's luminosity, map that to a lower luminosity, get the adjustment ratio, and then adjust each of the RGB channels by that ratio...
wswartzendruber is offline   Reply With Quote
Old 31st October 2020, 04:38   #52  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
Tomorrow's agenda:

1. Sober up.
2. Implement the BT.2390 tone mapping algorithm.
3. Derive unit tests for said algorithm.
4. Rule the world.
wswartzendruber is offline   Reply With Quote
Old 4th November 2020, 19:38   #53  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
Here's the latest command line usage for pq2hlg:

Quote:
PQ2HLG 0.1.0
Converts from HDR-PQ (HDR10) to HDR-HLG

USAGE:
pq2hlg [OPTIONS] <INPUT-FILE> <OUTPUT-FILE> --height <PIXELS> --width <PIXELS>

FLAGS:
--help Prints help information
-V, --version Prints version information

OPTIONS:
-h, --height <PIXELS> Height of the input video stream
-m, --max-cll <NITS> Brightness of the input video stream's brightest pixel [default: 10000]
-r, --ref-white <NITS> Brightness of the input video stream's reference white level [default: 203]
-w, --width <PIXELS> Width of the input video stream

ARGS:
<INPUT-FILE> Raw input video stream (PQ, BT.2020, RGB48); use - for STDIN
<OUTPUT-FILE> Raw output video stream (HLG, BT.2020, RGB48); use - for STDOUT

This utility follows the BT.2390 method for converting PQ to HLG. If a reference white value is supplied, then the input
will first be linearly scaled to bring that level to 203 nits. If a MaxCLL value has been provided, then it will be
internally adjusted by this factor. If the internal MaxCLL value exceeds 1,000 nits, then BT.2390 tone mapping will be
applied.
As you can all see, tone mapping support has now been added. It maps each color channel independently and not overall luminance.

Next up is to get DV/HDR10+ dynamic tone mapping in place.

Last edited by wswartzendruber; 4th November 2020 at 20:00.
wswartzendruber is offline   Reply With Quote
Old 5th November 2020, 09:52   #54  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 1,165
Good!
Well done.
Since your project continues to grow and you're basically accepting an input file and giving an output file to the user, have you ever thought of accepting also a stream as an input and outputting a stream as an output?
You probably figured out yourself what I mean by that, but I'm gonna say it anyway: introducing Avisynth+ support.
There are still alternatives, but, you know, the more tools we have, the better.
FranceBB is offline   Reply With Quote
Old 5th November 2020, 21:04   #55  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
Quote:
Originally Posted by FranceBB View Post
Good!
Well done.
Since your project continues to grow and you're basically accepting an input file and giving an output file to the user, have you ever thought of accepting also a stream as an input and outputting a stream as an output?
You probably figured out yourself what I mean by that, but I'm gonna say it anyway: introducing Avisynth+ support.
There are still alternatives, but, you know, the more tools we have, the better.
Your encouragement and feedback are appreciated.

I have very little experience with Avisynth+. As it stands now, you can pass "-" as the input and output files, causing pq2hlg to use STDIN and STDOUT instead of files.

Also, this thing is nowhere near ready for prime time. While you have access to professional grade equipment, I do not. This means that I am relying solely on mathematical correctness. In other words, I need more unit tests and lots of them.

So while I am very interested in Avisynth+ support, that is not the part of the roadmap that I am focusing on right now.

pq2hlg is also really slow (at the moment).

Last edited by wswartzendruber; 5th November 2020 at 21:06.
wswartzendruber is offline   Reply With Quote
Old 5th November 2020, 23:03   #56  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,247
OK, then, I have to ask. Given the existence of several good Avisynth filters that convert PQ to HLG, and given that processing by an EXE reading and writing raw files is unlikely to be easily usable in typical workflows, what is the reason for this project?
videoh is offline   Reply With Quote
Old 5th November 2020, 23:22   #57  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
Quote:
Originally Posted by videoh View Post
OK, then, I have to ask. Given the existence of several good Avisynth filters that convert PQ to HLG, and given that processing by an EXE reading and writing raw files is unlikely to be easily usable in typical workflows, what is the reason for this project?
I do all of my transcoding in Linux. Piping RGB48 between processes is trivial.

ffmpeg -> pq2hlg -> ffmpeg

How good are the other solutions at dealing with arbitrary MaxCLL values?

This project is principally for my own consumption, but others are free to use and share it.
wswartzendruber is offline   Reply With Quote
Old 6th November 2020, 03:28   #58  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
@FranceBB

The BBC says that the HLG OOTF needs to operate on luminance and scale R, G, and B by a fixed ratio. BT.2390 doesn't seem to care one way or the other.

Can I get away with having the HLG OOTF transform each channel independently? I could make this thing overwhelmingly faster if I can.

EDIT: Rats. I don't think I can.

Last edited by wswartzendruber; 6th November 2020 at 06:03.
wswartzendruber is offline   Reply With Quote
Old 21st November 2020, 20:37   #59  |  Link
wswartzendruber
Registered User
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 84
I'm now at the part of this journey where it's time to use dynamic metadata to tone map on a scene-by-scene basis.

Is there already tooling for parsing Dolby Vision out into a JSON file (or something), or do I have to create that as well? I'm assuming it's stored in HEVC extension fields throughout the stream.
wswartzendruber is offline   Reply With Quote
Old 21st November 2020, 23:54   #60  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Germany
Posts: 1,165
Did something happen? I was pretty sure to have answered the question before and I also spent a fair amount of time on it (which I'm not gonna spend now 'cause it's midnight)... Uhm... maybe there was a connection error, anyway I'm sorry you didn't get my answer.

Quote:
Originally Posted by wswartzendruber View Post
@FranceBB

The BBC says that the HLG OOTF needs to operate on luminance and scale R, G, and B by a fixed ratio. BT.2390 doesn't seem to care one way or the other.

Can I get away with having the HLG OOTF transform each channel independently? I could make this thing overwhelmingly faster if I can.
You really shouldn't. Technically you can try and see the result, but you would miss the correlation between them and I would encourage you not to do it.

Quote:
Originally Posted by wswartzendruber View Post
I'm now at the part of this journey where it's time to use dynamic metadata to tone map on a scene-by-scene basis.

Is there already tooling for parsing Dolby Vision out into a JSON file (or something), or do I have to create that as well? I'm assuming it's stored in HEVC extension fields throughout the stream.
Ah... I've seen people talking about it in the H.265 section of the forum; unfortunately I haven't been dealing with Dolby Vision contents that much so I don't know but there must be, 'cause other people have done it.
I mean, they have extracted the metadata from the Dolby Vision, parsed it into a json and used it in x265 to re-encode, so yes, that can be done, with which tool, though, I don't know/don't remember.
I hope someone from the H.265 section will pop here to give you a hand.
FranceBB is offline   Reply With Quote
Reply

Tags
hdr, hlg, pq2hlg

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 06:17.


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