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)

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,344
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 17th June 2018, 02:15   #8  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Found this:

HEVC HDR UHDTV Bitstreams using HLG10 shall also contain the alternative_transfer_characteristics SEI message. The alternative_transfer_characteristics SEI message shall be inserted on the HEVC DVB_RAP, and preferred_transfer_characteristics shall be set equal to “18”, indicating Recommendation ITU-R BT. 2100 [45] HLG system.
videoh is offline   Reply With Quote
Old 17th June 2018, 02:30   #9  |  Link
MGarret
Registered User
 
Join Date: Feb 2007
Posts: 18
Quote:
Originally Posted by henryperu77 View Post
So what do you suggest i can use?
I don't have a clue about HDR but in x265 docs there is this:

Quote:
--atc-sei <integer>

Emit the alternative transfer characteristics SEI message where the integer is the preferred transfer characteristics. Required for HLG (Hybrid Log Gamma) signalling. Not signalled by default.
I encoded your sample to elementary stream with the command you posted but added atc-sei=18 and mediainfo reports HLG / BT.2020 for transfer. However I don't know if this is correct output or if it's possible to encode it like this to 8bit.
MGarret is offline   Reply With Quote
Old 17th June 2018, 02:54   #10  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
I will add HLG support to DGDecNV and DGHDRtoSDR.

Last edited by videoh; 17th June 2018 at 12:18.
videoh is offline   Reply With Quote
Old 17th June 2018, 03:25   #11  |  Link
henryperu77
Registered User
 
Join Date: Jun 2009
Posts: 49
Quote:
Originally Posted by MGarret View Post
I don't have a clue about HDR but in x265 docs there is this:



I encoded your sample to elementary stream with the command you posted but added atc-sei=18 and mediainfo reports HLG / BT.2020 for transfer. However I don't know if this is correct output or if it's possible to encode it like this to 8bit.
Please upload it, to check it out!
thanks
henryperu77 is offline   Reply With Quote
Old 17th June 2018, 03:27   #12  |  Link
henryperu77
Registered User
 
Join Date: Jun 2009
Posts: 49
Quote:
Originally Posted by videoh View Post
I will add HLG support to DGHDRtoSDR.
What is that??
henryperu77 is offline   Reply With Quote
Old 17th June 2018, 11:22   #13  |  Link
MGarret
Registered User
 
Join Date: Feb 2007
Posts: 18
Quote:
Originally Posted by henryperu77 View Post
Please upload it, to check it out!
thanks
Why don't you try it yourself?

Here
Code:
https://www.mediafire.com/file/z7y5lqczufsqbxn/NPO_TEST_x265.hevc
It's only few seconds
MGarret is offline   Reply With Quote
Old 17th June 2018, 15:15   #14  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Quote:
Originally Posted by henryperu77 View Post
What is that??
It's an Avisynth filter for converting HDR10 to SDR. It runs at 100fps+ for 2160p on a recent nVidia card. It also can run in software mode but is very slow that way. Don't look to download it right now as I have it in the shop for changes. Will be available again in a few days. I will also add the HLG SEI detection to DGDecNV.
videoh is offline   Reply With Quote
Old 17th June 2018, 17:29   #15  |  Link
excellentswordfight
Lost my old account :(
 
Join Date: Jul 2017
Posts: 322
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   #16  |  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   #17  |  Link
excellentswordfight
Lost my old account :(
 
Join Date: Jul 2017
Posts: 322
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, 20:58   #18  |  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 19th June 2018, 22:36   #19  |  Link
nevcairiel
Registered Developer
 
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,344
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   #20  |  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
Reply

Tags
10bits, 2160p, hevc

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 20:39.


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