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. |
20th August 2021, 16:15 | #1 | Link |
Registered User
Join Date: Aug 2021
Location: Sea of Doubts
Posts: 28
|
Chroma sample location. What should I do?
Hi!
I'm transcoding a 4K HDR10 bluray to 1080 HDR10 H.265. Input & outpuput are YUV420p10. I'm using ffmpeg for the whole process. Chroma sample location for the bluray should be top-left... but it's center-left. So... what should I do?
Would this *trans-locating degrade the image further considering I am downscaling at the same time? Any cons/pros I should be aware before doing/not doing this? |
20th August 2021, 21:17 | #2 | Link | |
Registered User
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,407
|
Quote:
Trying to figure out the correct offsets for the chroma planes while downscaling has always been oddly confusing for me.
__________________
madVR options explained |
|
20th August 2021, 22:41 | #3 | Link |
Registered User
Join Date: Aug 2021
Location: Sea of Doubts
Posts: 28
|
As I'm using ffmpeg for this, looking at the docs there's two filters, chromashift and zscale with chromalin and chromal options.
Do they perform the same operation? Which should I use? PS: I'm beggining to learn/understand the theoretical part of all of this... so please excuse me if I'm asking stupid questions. |
20th August 2021, 22:51 | #4 | Link |
Registered User
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,407
|
I am not sure what to use in ffmpeg.
__________________
madVR options explained |
21st August 2021, 00:05 | #5 | Link |
Registered User
Join Date: Aug 2021
Location: Sea of Doubts
Posts: 28
|
Just to check if I know what I'm doing (I'm not too confident about that):
Chromashift apparently moves chroma horizontally and/or vertically. zscale chromalin > chromal sets the chroma location for the input video and then for the output video... and I suppose that, being a scaler filter, it will scale it down taking the chroma position I've set into account automagically. As I understand it now, I am dealing with an already subsampled video, and I cannot change that. I am encoding again, so I can only make sure this time the location is done properly spec-wise... so I'm telling the encoder "pick the sample HERE" and don't look back. What I don't understand is wether starting with an already subsampled video instead of an original RGB or YUV444 makes the process different and something has to be done to lessen any undesirable side-effect like, say, some king of moiré-ish chroma-bomb. I don't even know if what I've just wrote makes sense. Damn lack of education o'mine. |
21st August 2021, 11:24 | #6 | Link |
Registered User
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,407
|
Ah, that makes sense then. chromalin and chromal sounds correct.
During the scaling process the scaler can move the chroma planes slightly, relative to the luma. They are separate already, and being scaled already, so there aren't any downsides compared to starting with full resolution chroma. If you needed to move the chroma while keeping it the same resolution there would be a minor quality drop starting with subsampled chroma, but nothing like moiré, just minor blurring and/or ringing depending on the scaling method used.
__________________
madVR options explained |
21st August 2021, 17:26 | #7 | Link |
Registered User
Join Date: Aug 2021
Location: Sea of Doubts
Posts: 28
|
Re-reading my posts and your answers I'm noticing that I may be missing something.
When we talk about "chroma sample location" I understand this term refers to where, in a 3x3 grid, we pick the sample to perform the chroma subsampling to 4:2:0. You seem to be talking about moving chroma planes. Is it the same thing and I'm failing to grasp it or am I poorly explaining what I mean (due to my lack of knowledge)? Last edited by bokeron2020; 21st August 2021 at 21:30. |
21st August 2021, 22:03 | #8 | Link |
Registered User
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,407
|
It is tricky to think about.
For chroma placement, once you are working with the 4:2:0 data, don't think of it as "picking the sample to perform the chroma subsample to 4:2:0". Instead it is aligning chroma samples with the luma samples. The subsampling process has already been done. Subsampling chroma to 4:2:0 is simply downscaling the chroma data to half the resolution horizontally and vertically; hopefully this involves more than picking samples (e.g. a bicubic resize). This results in three planes of pixels; Y (at full resolution) and Cb and Cr (both at half resolution). This downscaling can be done with the output pixels aligned with different luma pixels (different chroma locations), so the player has to pick the correct chroma pixels to combine with the luma pixels when converting it all back to RGB. If you need to "move" the chroma plane half a pixel without scaling then you end up blending pixels together in the process of figuring out what the "correct" chroma value is for the new pixel that is half way between the two original chroma pixels. However, if you do this while also downscaling you are inventing all new pixels anyway, so you just need to align the resize kernel so the new pixels are shifted that half pixel in the final output (which represents a whole pixel in the input when doing a 50% scaled output). This kind of shift during the scaling process does not increase the mixing/bluring of neighboring chroma pixels compared to the same downscaling ratio without the shift. Did this help, or make it worse?
__________________
madVR options explained |
21st August 2021, 22:53 | #9 | Link |
Registered User
Join Date: Aug 2021
Location: Sea of Doubts
Posts: 28
|
Both!
It helps a lot. I need to shift paradigms to understand what I'm really doing. I'm still on it, though, so much of what you've explained makes sense but still in a fuzzy way. At the same time there's a lot to learn and work on to just reach "working knowledge" and do it properly, so this is another one bit of data I need to muster up the brains for. Thank you! Last edited by bokeron2020; 21st August 2021 at 22:55. |
23rd August 2021, 19:32 | #10 | Link |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,771
|
To add complexity, since shifting chroma a half pixel is invisible in most cases at 4K resolution, it's unclear how much UHD 4K encoding actually uses a source with chromaloc 2 versus using a chromaloc 0 source that then gets flagged at 2 for UHD BD spec compatibility. I don't recall ever seeing a mezzanine elementary stream with chromaloc specified.
|
23rd August 2021, 23:20 | #11 | Link |
Registered Developer
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,348
|
Mezzanine streams would often be 422, no? That difference would only apply for the final 420 encode. As long as they are actually encoding for UHD BD from a proper master that is likely not 420 itself, there is no reason to not downsample the chroma in the right position, instead of lie about it.
__________________
LAV Filters - open source ffmpeg based media splitter and decoders |
24th August 2021, 00:22 | #12 | Link |
Registered User
Join Date: Aug 2021
Location: Sea of Doubts
Posts: 28
|
Is there any tool (free, if possible) or procedure to determine real chroma location instead of trusting the chromaloc flag ?
EDIT: Also, a question regarding how important all of this is outside of the professional field. >>What are the "real world" consequences of just flagging it topleft no matter what and be done with it? I mean, any differences for a home user now or in the future? I'm finding a smorgasbord of BluRays and downloadable content with flags all over the place and I'm beggining to question if I'm not being a victim of diminishing returns, because correcting what others did wrong without knowing how wrong they really did it is getting on my nerves. I want to do it properly if I'm not gonna die trying... and right now it looks like I would... Last edited by bokeron2020; 24th August 2021 at 03:12. |
24th August 2021, 08:24 | #13 | Link |
Registered User
Join Date: Feb 2020
Posts: 541
|
Please wait untill this patch series is applied. https://patchwork.ffmpeg.org/project...bjp@gmail.com/
"transcoding a 4K HDR10 bluray to 1080" I do not understand this part. HDR Blu-rays must all use top-left. Did you check what is printed in Mediainfo? As for your question: early ITU-T H.265 specs did not care about chroma siting at all. Now, in latest spec used for Blu-rays, including Dolby Vision for BT.2020 and BT.2100 (last one is HDR, first is SDR) top left location is mandated, you can see that in Mediainfo (4:2:0 (Type 2)). When you encode for Profile 5 Dolby Vision you use default AVC left chroma (just Type 0 in mediainfo), even though is BT.2100. That is not used on Blu-ray though. Please note that the actual value is in VUI in SPS of HEVC bitstream itself. It is not usually tagged in container, though mkv does have such metadata. "mezzanine elementary stream with chromaloc specified." Are you kidding me? Mezzanine is 16 bit DCI-P3 (no BT.2020) with PQ transfer RGB. RGB does not have chroma. And does not have chroma siting. Same about siting in YCbCr 422 and 444 (422 technically does have it but it is only 1 used, not 6 (with 3 used) in 420). "Is there any tool (free, if possible) or procedure to determine real chroma location instead of trusting the chromaloc flag ?" No. Though there are test patterns. As for how you do it... @nev said it: Code:
-vf 'scale=out_color_matrix=bt709:out_h_chr_pos=0:out_v_chr_pos=128' HEVC type 2 should be 0:0 from what I can tell (pixfmt.h calls this AVCHROMA_LOC_TOPLEFT) Last edited by Balling; 25th August 2021 at 06:11. |
24th August 2021, 15:05 | #14 | Link | ||
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,905
|
Quote:
Yep. Every time I get a masterfile is 4:2:2 either 10bit or 12bit planar, same goes for our internal mezzanine files which are 4:2:2 planar 10bit, so the chroma location thing doesn't apply for masterfiles as it's always in the classic MPEG-2 position. Quote:
(Not that I care much as I would have to dither it down to 10bit planar anyway as per our specs, but still, it would be nice to see a real world 16bit file). |
||
24th August 2021, 16:53 | #15 | Link |
Registered User
Join Date: Aug 2021
Location: Sea of Doubts
Posts: 28
|
These last messages are quite informative to me, and I understand professionals/experts take this matters to a higher level, but I'm still wondering what to do. So... please let me just for a moment return to my particular situation, and repeat one last question to understand the importance of this for a home user.
What are the "real world" consequences of :
I mean, any differences for a home user now or in the future? I'm finding a smorgasbord of BluRays and downloadable content with flags all over the place and I'm beggining to question if I'm not being a victim of diminishing returns, because correcting what others did wrong without knowing how wrong they really did it is getting on my nerves. I want to do it properly if I'm not gonna die trying... and right now it looks like I would... |
25th August 2021, 05:43 | #16 | Link |
Registered User
Join Date: Feb 2020
Posts: 541
|
HDR Blu-rays must already have top left chroma siting. So 2. "Not converting and just flagging it topleft". That is not done with -vf scale. That is just done with bsf filter.
https://ffmpeg.org/ffmpeg-bitstream-...c_005fmetadata ffmpeg -i file.mp4 -c copy -bsf:v hevc_metadata=chroma_sample_loc_type=2 file1.mp4 Obviously 0, 1, 2, 3, 4, 5 are possible but also -1 can be applied to remove any chroma siting info from VUI in SPS. "What are the "real world" consequences of" You can read that in this post https://www.avsforum.com/threads/spe.../post-60439344 and this pattern https://www.avsforum.com/threads/spe.../post-60430955 Last edited by Balling; 25th August 2021 at 06:42. |
25th August 2021, 16:19 | #17 | Link | |
Registered User
Join Date: Aug 2021
Location: Sea of Doubts
Posts: 28
|
They must but apparently not all of them have it. The same can be said for downloadable content. Some are 0, some are 2.
Quote:
But when will that happen, when I keep out-of-specs videos or when I flag them without properly converting? What I'm trying to decide for now is... should I convert to within-specs or could I ignore the specs and keep it like that?
|
|
25th August 2021, 17:31 | #18 | Link | ||
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,905
|
Quote:
Taken that aside, there's a staggering amount of incorrect material out there in the web almost always 'cause it has been re-encoded by someone who had no clue whatsoever about what he was doing. So, let's suppose we have the following scenario: - UHD file with MPEG-2 chroma location flag and that is actually with the MPEG-2 chroma location - UHD file with the MPEG-2 chroma location flag that is instead with the 4:2:0 Type 2 chroma location The first one, although some might argue that it's not standard, doesn't have any problem whatsoever when you play it back on a compatible device 'cause the metadata and the location are both correct, so my advice would be to leave it as it is. The second one is a problem 'cause the flag says 4:2:0 while the chroma location is 4:2:0 Type 2, so the decoder will use the wrong location when decoding and it will lead to artifacts. Some people like our Ben say that it's not so noticeable, especially at 4K resolution, which is actually true as people tend not to notice this that much, however it's technically not correct and will lead to degradation when decoding. In that case, I would suggest you to re-encode the file and fix the chroma location with ffmpeg. A quick example: since in Avisynth I generally work with the old MPEG-2 alignment, whenever I have to output a 4:2:0 Type2, I use: Code:
ffmpeg.exe -i "AVS Script.avs" -vf scale=out_color_matrix=bt2020nc:out_h_chr_pos=0:out_v_chr_pos=0 -pix_fmt yuv420p16le -strict -1 -an -f yuv4mpegpipe - | x265.exe --y4m - --dither So far no one ever complained about this kind of conversion and I even sent those files to Samsung for the Samsung The Wall demonstration with Sky contents before the whole COVID-19 pandemic happened and no one ever said anything, which means that it was ok. Quote:
Oh God... something went wrong down the production chain if the chroma location is wrong in an official bluray, like if it's 4:2:0 Type2 in metadata but it's actually MPEG-2 4:2:0 inside and what bothers me is that those kind of things shouldn't happen since there's generally a rigorous automatic and manual QC for those kind of things... Well, now I've lost faith in humanity ehehehehehe No, I mean, jokes aside, if you find things wrong on contents downloaded on the web, you should correct them 'cause it's almost always the case that whoever re-encoded that had no clue about what he was doing. As technologies get more and more advanced, people get more prone to make mistakes, so we did see that coming, but professionally wise they should be ok. |
||
26th August 2021, 10:40 | #19 | Link |
Registered User
Join Date: Feb 2020
Posts: 541
|
"you to re-encode the file and fix the chroma location with ffmpeg."
You do not need to reencode the file. My command above will do it losslessly, changing just one value all over bitstream ffmpeg -i file.mp4 -c copy -bsf:v hevc_metadata=chroma_sample_loc_type=0 file1.mp4. As for your command of Samsung the wall, please show mediainfo. Did you actually tag the file? It should print YUV 4:2:0 (Type 2), where type 2 is the actual info in VUI. Mediainfo can read all 6 types of chroma siting. I can also confirm that Code:
-vf scale=out_color_matrix=bt2020nc:out_h_chr_pos=0:out_v_chr_pos=0 Last edited by Balling; 26th August 2021 at 10:46. |
26th August 2021, 20:46 | #20 | Link | |||
Registered User
Join Date: Aug 2021
Location: Sea of Doubts
Posts: 28
|
Thanks for your answer! It helps me, along with all the previous answers, to know where I stand, what to do ATM and directions to learn at least enough to reach a basic working knowledge for a home user.
The are two points I'd like to ask about again: Quote:
Quote:
Why not zscale? And why not to use integrated ffmpeg x265 codec? Quote:
The bad blurays I've found are mostly local market editions dating back to the first bucnh of HDR releases and some documentaries, concerts, etc, from small publishers. Some buy&keep downloadable movies have shown also this problem (ie, from chili.com), though it mostly predates non-released in Spain content that I have to find elsewhere, like "Space Adventure Cobra" which sometimes seem to be encoded by a blind monkey. One last question about missing metadata. Any free tool out there to calculate MaxCLL,MaxFALL? |
|||
|
|