Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --chromaloc 2 to x265 parameters automatically if source is 4.2:0 (Type 2) #190

Closed
E-t-z opened this issue Jan 26, 2021 · 22 comments
Closed
Labels
bug Something isn't working

Comments

@E-t-z
Copy link

E-t-z commented Jan 26, 2021

A bit unsure on this, if it is even required, some sources say it is definitely required if you want to retain HDR, others say it is optional.

Maybe @cdgriffith can comment on this (you wrote terrific article on HDR encoding after all) and if needed, could implement it?

@E-t-z E-t-z changed the title add --chromaloc 2 ot x265 parameters if source is 4.2:0 (Type 2) add --chromaloc 2 to x265 parameters automatically if source is 4.2:0 (Type 2) Jan 26, 2021
@cdgriffith
Copy link
Owner

Never heard of that before actually. Know of any example sources that have type 2 chroma? Would need to find out how that is displayed via ffprobe.

If you happen to have one, would appreciate output of:

ffprobe -v quiet -loglevel panic -print_format json -show_format -show_streams <file>

@E-t-z
Copy link
Author

E-t-z commented Jan 27, 2021

Most UHD BR's (if not all) with HDR should have it, but I have some sample clips myself as well.

Type 2 does not have anything chromaloc related present in JSON.

But, when you don't specify it as x265-param and use Defaults, this row appears on HEVC stream.
"chroma_location": "topleft",
Immediately after "color_primaries": "bt2020"

In mediainfo, it shows like this:

Type 2:
image

Default (Without chromaloc specified):
image

@E-t-z
Copy link
Author

E-t-z commented Jan 27, 2021

Some documentation https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-H.Sup19-201910-I!!PDF-E&type=items

image

To follow BT.2020 specifications, it seems to be, kind of required, if Color Space is YUV (YCbCr) a.k.a TV color. 😄

@E-t-z
Copy link
Author

E-t-z commented Jan 27, 2021

My current assumption is, that it should be always used, when dealing with WCG/HDR content and YUV.

At least all of my 10-bit HDR sample files (except one) have Type 2 specified.
Checked couple of UHD BR's as well, they also have 4:2:0 (Type 2) on all of them.

@cdgriffith
Copy link
Owner

Thanks for the details!

Luckily it does display in ffprobe: "chroma_location": "left" looks to be 0 and "chroma_location": "topleft" looks to be 2.

And you are correct that it seems a movies encoded with FastFlix without that does switch it from topleft to left. (There seems to be debate if anything actually uses that flag right now, is possibly why no one has yet noticed https://forum.doom9.org/archive/index.php/t-174491.html)

https://x265.readthedocs.io/en/3.1/cli.html says to refer to the HEVC specification to find what the 5 possible options mean, did a quick search through https://www.itu.int/rec/T-REC-H.265-201911-I/en without much luck, would like to get them all defined for future proofing.

@E-t-z
Copy link
Author

E-t-z commented Jan 27, 2021

For me Type 2, does not seem to reflect anything in ffprobe output, at least BR's which I checked have nothing in that output.
That element is simply not present...but they are Detected as 4:2:0 (Type 2).

You are probably right, that nothing uses it at the moment, as my AndroidTV does not seem to care.
Still, it would be nice to follow the standards, in case something does and messes up the colors 😆

I think best way to understand, how it is actually reflected in ffprobe, would be to encode 6 sample files, with chromaloc flag 0...5 and one without that flag and then compare outputs.

@E-t-z
Copy link
Author

E-t-z commented Jan 27, 2021

@cdgriffith BTW all HEVC possible chroma locations are described here:
https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-H.265-201612-S!!PDF-E&type=items

On page 384, Figure E.1

TL;DR: They are basically: left, center, top_left, top, bottom_left, bottom

@cdgriffith
Copy link
Owner

I think best way to understand, how it is actually reflected in ffprobe, would be to encode 6 sample files, with chromaloc flag 0...5 and one without that flag and then compare outputs.

You know, I felt so smart going and brute forcing it just like that, and was coming back to report the results and you already posted the idea 😭

chromaloc ffmpeg chroma_location
0 left
1 center
2 topleft
3 top
4 bottomleft
5 bottom

@E-t-z
Copy link
Author

E-t-z commented Jan 27, 2021

And now, checkbox would be nice "Preserve Chroma location", checked by default for HDR and inserting chromaloc=X as last element into x265-params 😄

Too bad, I suck on python...maybe I could rewrite it in C# (kidding) 😋

@cdgriffith cdgriffith added the bug Something isn't working label Jan 27, 2021
@cdgriffith
Copy link
Owner

I think it's safe to just always insert it if the incoming source provides a chroma_location.

My only wonder now is if doing the remove_hdr process changes the chroma_location..hmm..

@E-t-z
Copy link
Author

E-t-z commented Jan 27, 2021

That is an interesting question indeed.
But if you look this table (I pasted here previosly) BT.709 has Chroma_location=0 always, when YUV is used.

AFAIK, you cannot remove HDR and keep BT.2020 😉

EDIT: Mkay, you actually (technically) can...wondering, what is the point of having BT.2020 on SDR.

@cdgriffith
Copy link
Owner

Currently it does take it down to bt709, so hopefully just always setting / leaving it at 0 is proper for that.

Filter used:

zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap={tone_map}:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p"

@E-t-z
Copy link
Author

E-t-z commented Jan 27, 2021

As 0 seems to be default as well, I don't think it would cause an issue.

@cdgriffith
Copy link
Owner

I hope not, and just did some test encodes with Handbrake to see how they handled it, they seem to ignore it entirely as well (everything comes out 0).

I'm still planning on adding the passthrough, just glad I'm not the only one who missed the memo 😉

@E-t-z
Copy link
Author

E-t-z commented Jan 27, 2021

As I stated at the beginning, I'm quite unsure how much it actually matters in real life, but it seemed to violate the spec,
so I simply started digging.

Even checked couple of encodes (of UHD BR's I own) on torrent sites, to see how famous scene groups handle it.
And they all seemed to preserve "chromaloc" for some reason...and you already know the rest I guess... 😄

AFAIK, Handbrake cannot handle HDR properly, their internal pipeline is 8-bit only, so I would not pick them as reference.

@E-t-z
Copy link
Author

E-t-z commented Jan 27, 2021

Anyway, I think we can close this now.

@E-t-z E-t-z closed this as completed Jan 27, 2021
@cdgriffith
Copy link
Owner

I just like to keep these open until actually released to keep track of progress, thanks again for all the info!

@cdgriffith cdgriffith reopened this Jan 27, 2021
cdgriffith added a commit that referenced this issue Feb 14, 2021
* Adding #109 NVENC HEVC support based on FFmpeg
* Adding NVEenC encoder for HEVC and AVC
* Adding #166 More robust queue that is recoverable
* Adding ability to extract HDR10+ metadata if hdr10plus_parser is detected on path
* Adding #178 selector for number of autocrop positions throughout video (thanks to bmcassagne)
* Adding Windows 10 notification for queue complete success
* Adding #194 fast two pass encoding (thanks to Ugurtan)
* Fixing German translations (thanks to SMESH)
* Fixing #171 Be able to select encoder before selecting video
* Fixing #176 Unable to change queue order or delete task from queue since 4.1.0 (thanks to Etz)
* Fixing #185 need to specify channel layout when downmixing (thanks to Ugurtan)
* Fixing #187 cleaning up partial download of FFmpeg (thanks to Todd Wilkinson)
* Fixing #190 add missing chromaloc parameter for x265 (thanks to Etz)
* Fixing that returning item back from queue of a different encoder type would crash Fastflix
* Fixing HDR10 details to be track specific (thanks to Harybo)
cdgriffith added a commit that referenced this issue Apr 13, 2021
* Adding #109 NVENC HEVC support based on FFmpeg (thanks to Zeid164)
* Adding NVEenC encoder for HEVC and AVC
* Adding #166 More robust queue that is recoverable
* Adding ability to extract HDR10+ metadata if hdr10plus_parser is detected on path
* Adding #178 selector for number of autocrop positions throughout video (thanks to bmcassagne)
* Adding Windows 10 notification for queue complete success
* Adding #194 fast two pass encoding (thanks to Ugurtan)
* Adding Confirm dialogue for cancel encode and replace currently working on video
* Changing AVC defaults and recommendations for CRF to higher values
* Changing VP9 to default to mkv instead of webm format to support more audio codecs
* Fixing German translations (thanks to SMESH)
* Fixing #171 Be able to select encoder before selecting video
* Fixing #176 Unable to change queue order or delete task from queue since 4.1.0 (thanks to Etz)
* Fixing #185 need to specify channel layout when downmixing (thanks to Ugurtan)
* Fixing #187 cleaning up partial download of FFmpeg (thanks to Todd Wilkinson)
* Fixing #190 add missing chromaloc parameter for x265 (thanks to Etz)
* Fixing #209 Double spaces were removed in incoming filenames, causing no file found (thanks to stilicrafter)
* Fixing that deinterlace detection could crash program due to CPython bug issue #43423 (thanks to macx)
* Fixing that returning item back from queue of a different encoder type would crash Fastflix
* Fixing HDR10 details to be track specific (thanks to Harybo)
* Fixing returning from queue works with duplicated audio tracks

Co-authored-by: SMESH <4199206+smesh109@users.noreply.github.com>
Co-authored-by: TGMais <2453844+tgmais@users.noreply.github.com>
@cdgriffith
Copy link
Owner

@cdgriffith
Copy link
Owner

When you convert to BT.709 you need to scale planes to different chroma sample location with -vf scale. @ValZapod

I don't fully follow, do you have an example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@cdgriffith @E-t-z and others