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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 13th April 2020, 05:44   #1  |  Link
wswartzendruber
hlg-tools Maintainer
 
wswartzendruber's Avatar
 
Join Date: Feb 2008
Posts: 413
I Made a PQ to HLG Converter

I wrote a small utility for converting raw video streams from PQ to HLG. It's available on GitHub.

Code:
USAGE: pq2hlg [format] [nits] [width] [height] [input] [output]
  format - The raw pixel format to use. Supported options are:
           rgb48
  nits   - Luminance value of the brightest pixel in the input.
  width  - Width of the video stream in pixels.
  height - Height of the video stream in pixels.
  input  - Raw RGB48 input file; use - for STDIN.
  output - Raw RGB48 output file; use - for STDOUT.
My motivation was that I wanted to rip my 4K UltraHD library, but wanted to do so in a viewing format that is as universal as possible, even if that entails some amount of compromise. I quickly settled on HLG after reading about it, but couldn't find a conversion utility to do this. I learned that ffmpeg supports the use of lookup tables, but couldn't find any such thing for cheaper than a couple hundred dollars. Others were available from the BBC under license.

All in all, I got quite fed up with the situation and started researching PQ, HLG, metadata, gamma curves, etc. until I got nauseated and started work. Then I studied some more and then went back to coding. Wash, rinse, and repeat a few times. I'm at the point where I'm comfortable with releasing my work to the public. Principally, it uses, to the best of my understanding, the algorithm published by BBC Research & Development.

Future improvements may include passing dynamic metadata in for variable PQ->HLG tone mapping. I definitely want to add YUV10 support as soon as I can figure out how the U and V components are encoded.

This is also the first thing I've written in Rust, so it's probably not going to be as idiomatic or as proper as it could be.

EDIT: Attached a screenshot from Alita: Battle Angel using this utility, taken from a nightly build of VLC 3.0.9 on a SDR monitor. The video codec in use is VP9 Profile 2.

EDIT: I also forgot to mention: This isn't really suitable for any brightness value aside from 1,000 nits. If a PQ video has a peak brightness of less than 1,000 nits, pass 1,000 nits in as the second argument anyway. If any pixel ever exceeds 1,000 nits, then external tone mapping really needs to be applied to the PQ source before passing it into this utility. A peak brightness of other than 1,000 nits can be specified, but this will cause reference white to be pushed up or down. This addendum is in accordance with ITU-R BT.2390-8 Section 7.2.
Attached Images
 

Last edited by wswartzendruber; 13th April 2020 at 07:05. Reason: Clarifying brightness setting.
wswartzendruber is offline   Reply With Quote
 

Tags
hdr, hlg, pq2hlg


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 23:57.


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