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 > Video Encoding > High Efficiency Video Coding (HEVC)
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 16th June 2018, 21:32   #1  |  Link
henryperu77
Registered User
 
Join Date: Jun 2009
Posts: 49
Convert HEVC 2160p 10 bits HLG to 2160p 8bits with HLG/HDR using ffmpeg

I have this World Cup sample in 4k HEVC 4:2:0 HLG 10bits and i want to convert it to 4k HEVC 8bits HLG/HDR using ffmpeg but maintaining the correct colors

https://transfer.pcloud.com/download...3TCb5VnyMDbagV

I tried this that i found on another site, but the color results are horrible

ffmpeg -i "d:\Descargas\NPO1 UHD.ts"
-c:a copy
-c:v libx265
-tag:v hvc1 -crf 22
-pix_fmt yuv420p10le
-x265-params "colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc" "d:\Descargas\NPO1_UHD_mkv.mkv"

Any help is appreciated...
henryperu77 is offline   Reply With Quote
Old 16th June 2018, 22:04   #2  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Why do you think it is HDR HLG? It doesn't look like it to me. Looks like plain old UHD.
videoh is offline   Reply With Quote
Old 16th June 2018, 22:13   #3  |  Link
henryperu77
Registered User
 
Join Date: Jun 2009
Posts: 49
Quote:
Originally Posted by videoh View Post
Why do you think it is HDR HLG? It doesn't look like it to me. Looks like plain old UHD.
Video
ID : 511 (0x1FF)
Menu ID : 20901 (0x51A5)
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main 10@L5.1@Main
Codec ID : 36
Duration : 53 s 280 ms
Bit rate : 24.4 Mb/s
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate : 50.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 10 bits
Bits/(Pixel*Frame) : 0.059
Stream size : 155 MiB (93%)
Encryption : TPS-Crypt or Viaccess
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : HLG / BT.2020 (10-bit)
Matrix coefficients : BT.2020 non-constant
henryperu77 is offline   Reply With Quote
Old 16th June 2018, 22:57   #4  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Assuming that is MediaInfo output, I'll have to look into how it detects HLG (there is no metadata for HLG). It may just be 2020 UHD, as the "HLG / BT.2020" could be ambiguous with the "/" meaning "or" rather than "and". If I decode this as simple UHD, then it looks fine. Investigating...
videoh is offline   Reply With Quote
Old 16th June 2018, 23:11   #5  |  Link
nevcairiel
Registered Developer
 
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,346
Quote:
Originally Posted by videoh View Post
If I decode this as simple UHD, then it looks fine. Investigating...
Thats one of the "features" of HLG, if you ignore it, it still looks mostly fine.

HLG-encoded streams usually have one extra SEI message that tells the player that the stream is HLG, but if you ignore that SEI message then it would just look like ordinary BT.2020 SDR.

For the OP, you should definitely not set the transfer to 2084 since thats not HLG but HDR10/PQ. I don't know if x265 can properly set the double transfer characteristics that HLG uses (ie. BT.2020 in main header, HLG in SEI header).
__________________
LAV Filters - open source ffmpeg based media splitter and decoders
nevcairiel is offline   Reply With Quote
Old 16th June 2018, 23:27   #6  |  Link
henryperu77
Registered User
 
Join Date: Jun 2009
Posts: 49
Quote:
Originally Posted by nevcairiel View Post
Thats one of the "features" of HLG, if you ignore it, it still looks mostly fine.

HLG-encoded streams usually have one extra SEI message that tells the player that the stream is HLG, but if you ignore that SEI message then it would just look like ordinary BT.2020 SDR.

For the OP, you should definitely not set the transfer to 2084 since thats not HLG but HDR10/PQ. I don't know if x265 can properly set the double transfer characteristics that HLG uses (ie. BT.2020 in main header, HLG in SEI header).
So what do you suggest i can use?
henryperu77 is offline   Reply With Quote
Old 17th June 2018, 01:24   #7  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Quote:
Originally Posted by nevcairiel View Post
HLG-encoded streams usually have one extra SEI message that tells the player that the stream is HLG
Interesting! Can you tell me the details on the SEI message, or point to a spec? Thank you.
videoh is offline   Reply With Quote
Old 19th June 2018, 20:58   #8  |  Link
Revan654
Registered User
 
Revan654's Avatar
 
Join Date: May 2004
Posts: 324
Quote:
Originally Posted by henryperu77 View Post
Video
ID : 511 (0x1FF)
Menu ID : 20901 (0x51A5)
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main 10@L5.1@Main
Codec ID : 36
Duration : 53 s 280 ms
Bit rate : 24.4 Mb/s
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate : 50.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 10 bits
Bits/(Pixel*Frame) : 0.059
Stream size : 155 MiB (93%)
Encryption : TPS-Crypt or Viaccess
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : HLG / BT.2020 (10-bit)
Matrix coefficients : BT.2020 non-constant
The sample you Uploaded is not HLG from what my editing software is reading out. Mediainfo been hit or miss when it comes to HDR content.

I'm a little fuzzy when it comes to HLG, shouldn't the transfer be something other then BT.2020? HDR10 uses ST.2084, I would think HLG uses ARIB STD-B67.

Revan654 is offline   Reply With Quote
Old 17th June 2018, 17:29   #9  |  Link
excellentswordfight
Lost my old account :(
 
Join Date: Jul 2017
Posts: 325
Quote:
Originally Posted by henryperu77 View Post
I have this World Cup sample in 4k HEVC 4:2:0 HLG 10bits and i want to convert it to 4k HEVC 8bits HLG/HDR using ffmpeg but maintaining the correct colors

https://transfer.pcloud.com/download...3TCb5VnyMDbagV

I tried this that i found on another site, but the color results are horrible

ffmpeg -i "d:\Descargas\NPO1 UHD.ts"
-c:a copy
-c:v libx265
-tag:v hvc1 -crf 22
-pix_fmt yuv420p10le
-x265-params "colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc" "d:\Descargas\NPO1_UHD_mkv.mkv"

Any help is appreciated...
Ideally you wanna use the "alternative_transfer_characteristics" but its not supported by x265, but this mostly to keep fallback compatibility with SDR devices. But the transfer function you are after is arib-std-b67 (its the same transfer as used by HLG so it also uses 18 as value).

With that said, I cant see any reason for the 8bit transcode, that is out of the HLG specc. What should be done is to convert it to SDR, then transcode it.

Last edited by excellentswordfight; 17th June 2018 at 17:38.
excellentswordfight is offline   Reply With Quote
Old 17th June 2018, 18:19   #10  |  Link
henryperu77
Registered User
 
Join Date: Jun 2009
Posts: 49
Quote:
Originally Posted by excellentswordfight View Post
Ideally you wanna use the "alternative_transfer_characteristics" but its not supported by x265, but this mostly to keep fallback compatibility with SDR devices. But the transfer function you are after is arib-std-b67 (its the same transfer as used by HLG so it also uses 18 as value).

With that said, I cant see any reason for the 8bit transcode, that is out of the HLG specc. What should be done is to convert it to SDR, then transcode it.
Ok what i need to convert it to SDR adding the color changes
henryperu77 is offline   Reply With Quote
Old 17th June 2018, 20:09   #11  |  Link
excellentswordfight
Lost my old account :(
 
Join Date: Jul 2017
Posts: 325
Quote:
Originally Posted by henryperu77 View Post
Ok what i need to convert it to SDR adding the color changes
What is the target for the encode? Cause first you asked to keep the HDR intact, but I cant I imagine a decoder that can handle HDR but not 10bit.

When I looked at this the last time the options were limited and I ended up doing it with ffmpeg and a LUT with acceptable results (but definitely not great). Cant share the LUT though so cant help you with that unfortunately. Maybe someone else here know of another solution.

I've seen some people doing the convert with just ffmpeg (without a lut), I guess that it would look something like this:

Code:
"ffmpeg.exe" -i "input.ts" -vf zscale=tin=arib-std-b67:min=bt2020nc:pin=bt2020:rin=tv:t=arib-std-b67:m=bt2020nc:p=bt2020:r=tv,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -an -c:v libx265 -preset slow -x265-params level=51:crf=22:keyint=500:min-keyint=50:rc-lookahead=50:bframes=8:no-sao=1:colorprim="bt709":transfer="bt709":colormatrix="bt709":range="limited" "out"
Dont have any HLG samples atm to test with, but I guess that you can start with that, but be prepaird to tweak it.

Last edited by excellentswordfight; 17th June 2018 at 20:37.
excellentswordfight is offline   Reply With Quote
Old 19th June 2018, 22:36   #12  |  Link
nevcairiel
Registered Developer
 
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,346
HLG uses a separate SEI element to indicate a secondary transfer function, which allows fallback to SDR with non-HLG aware players. So the main transfer function entry would be an SDR one, and the extra SEI element would indicate the HLG transfer. If your analyzer does not understand that separate SEI, then it would show as SDR.
__________________
LAV Filters - open source ffmpeg based media splitter and decoders
nevcairiel is offline   Reply With Quote
Old 19th June 2018, 22:40   #13  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
That stream does contain the SEI message discussed. Next slipstream of DGDecNV will show it in the DGI file.
videoh is offline   Reply With Quote
Old 21st June 2018, 11:29   #14  |  Link
excellentswordfight
Lost my old account :(
 
Join Date: Jul 2017
Posts: 325
Quote:
Originally Posted by videoh View Post
That stream does contain the SEI message discussed. Next slipstream of DGDecNV will show it in the DGI file.
Are you sure, I think it does. If I make an encode with x265 with --atc-sei 18 --transfer bt2020 (it should be --transfer bt2020-10 though), I get the same readout in ffmpeg and mediainfo as OP:s ts file.
excellentswordfight is offline   Reply With Quote
Old 26th June 2018, 04:44   #15  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,770
Quote:
Originally Posted by nevcairiel View Post
HLG uses a separate SEI element to indicate a secondary transfer function, which allows fallback to SDR with non-HLG aware players. So the main transfer function entry would be an SDR one, and the extra SEI element would indicate the HLG transfer. If your analyzer does not understand that separate SEI, then it would show as SDR.
Real-world, it's more that the HLG code values look okay when treated as SDR.

HLG is something that works in practice (decent HDR on supported devices, with decent SDR on legacy devices) but not in theory (same set of code values without metadata can deliver two different creative intents).

The challenge with HLG is that it gets optimized for SDR, HDR, or sort of in the middle. It's never going to be as accurate or "HDR" as well-graded HDR-10(+) or Dolby Vision.

But if you are a broadcaster limited by RF instead of IP, having one channel that can do SDR and HDR is very appealing.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 20th June 2018, 16:05   #16  |  Link
hydra3333
Registered User
 
Join Date: Oct 2009
Location: crow-land
Posts: 540
thank you, videoh.
hydra3333 is offline   Reply With Quote
Old 20th June 2018, 16:23   #17  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
You're welcome, hydra3333. I am also adding HLG support to DGHDRtoSDR. Current version (no HLG yet) is here:

http://rationalqm.us/misc/DGHDRtoSDR_1.4.rar
videoh is offline   Reply With Quote
Old 20th June 2018, 21:55   #18  |  Link
SeeMoreDigital
Life's clearer in 4K UHD
 
SeeMoreDigital's Avatar
 
Join Date: Jun 2003
Location: Notts, UK
Posts: 12,227
Quote:
Originally Posted by Revan654 View Post
The sample you Uploaded is not HLG from what my editing software is reading out. Mediainfo been hit or miss when it comes to HDR content.
I can confirm the sample triggers the HLG HDR flag on my LG television

Quote:
Originally Posted by henryperu77 View Post
...I tried this that i found on another site, but the color results are horrible...
Out of interest... Are you viewing HLG content on a screen that supports HLG decoding?
__________________
| I've been testing hardware media playback devices and software A/V encoders and decoders since 2001 | My Network Layout & A/V Gear |

Last edited by SeeMoreDigital; 20th June 2018 at 22:01.
SeeMoreDigital is online now   Reply With Quote
Old 22nd June 2018, 07:10   #19  |  Link
hydra3333
Registered User
 
Join Date: Oct 2009
Location: crow-land
Posts: 540
don't know if this is relevant, someone said
https://mrmc.tv/forum/viewtopic.php?t=3973#p16210
Quote:
The transfer characteristics for true HDR10 content cannot be BT.2020 ( # 14). It has to be PQ/ST.2084 ( #16). BT.2020 transfer characteristic is the same as for BT.709 (BT.1886/SDR)
.
hydra3333 is offline   Reply With Quote
Old 3rd July 2018, 18:06   #20  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,770
Oh, another thing I just recalled - HLG is supposed to always be 10-bit. Weird things might happen using it in 8-bit instead due to lack of precision and/or hardware support.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Reply

Tags
10bits, 2160p, hevc


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


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