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
inaccurate conversion from YCbCr Narrow range to RGB Full range #109
Comments
|
I can not reproduce this issue: This prints 38004. For your 100% magenta question, your 10-bit inputs are already quantized, so why would you expect it to produce an exact result? The input vector (16-bit) [22149, 53433, 59134] produces bit-exact 16-bit output. |
|
Thank you for looking into this so promptly. Unfortunately, I've not worked with vapoursynth before and I can't yet reproduce your reproduction steps myself. But assuming zimg itself is working correctly, would it be too much to ask you to see if you can reproduce the issue using the ffmpeg command I am using?
I am expecting an exact result because there is no good reason to not have an exact result and the fact my input is quantised already shouldn't matter that much.
Can you please clarify what this input vector represents and what output does it produce? Thanks! |
|
Pwrhaps error came from fact that zscale override matrix to rgb one for rgb output pixel formats? |
Of course it matters. If your input is inexact, the correct result is for the output to be inexact. You can work the math out yourself.
I used the Rec.2020 matrix to compute the real-valued YUV corresponding to R=1, G=0, B=1, and then I rounded it to 16-bit. From ITU-R BT.2020-2: Quantizing it to 16-bit values: Your 10-bit input (346, 835, 924) maps to: Which is correct only to the 3rd decimal point, whereas a 16-bit number requires around 5 decimal points of precision. It is therefore not surprising that your input is off by 2/65535, which is on the order of the 5th decimal place. |
Here you are second guessing what the original intent behind the input code value was. When I supply code value 346 on input to the matrix conversion I expect it to be treated as 346.000 rather than 346.078125. I don't really want to focus on the magenta situation, as you say it's only 2/65535 off and there is a bigger issue that would be good to get to the bottom of: Have you got a view regarding this comment above?
|
Getting offended by maths is a new one. Different strokes, different folks perhaps... So we see that your "original intent" is to produce the color (65533, -8, 65544), and it is only clipping that is allowing you to have the delusion that you are close to (65535, 0, 65535). |
|
Trust me, I had done my maths on these colour chips before submitting the original ffmpeg bug report. I know there is clipping required for the YCbCr triplet (0x015a, 0x343, 0x039c). Sorry for repeating myself, but have you got a view on the more serious discrepancy 58% White when ffmpeg zscale is used? |
|
I have not been able to set up a FFmpeg debug environment, as I have no involvement w/ vf_zscale. It will probably take a few more days to investigate. |
|
I looked at the log output in the first post, which appears to indicate that z.lib is not involved in converting to RGB.
I tried to reproduce this with an FFmpeg build that I compiled myself, but I could not determine how to convert to RGB by reading the documentation (https://ffmpeg.org/ffmpeg-filters.html#zscale-1). |
|
There is user supplied command above... |
|
@cepesh Could you use zscale=other parameters as usual,format=rgb48le instead of what are you using currently? |
|
@cepesh I did some Googling and found that you must add 'format=gbrp16le' after 'zscale'. Otherwise, FFmpeg instructs z.lib to perform a no-op conversion from YUV to YUV, and instead uses its internal code to convert to RGB. After I did this, I verified that I got '38004' when converting from '572'. This bug(?) exists in FFmpeg, not z.lib. |
Hi, I've been advised to raise a ticket here rather than on the ffmpeg trac system. Original issue description, source and output files can be found here: https://trac.ffmpeg.org/ticket/8034
The problem is that when I convert from a v210 YCbCr BT.2020 NCL narrow-range file to an RGB TIFF full-range, some code values are incorrect. For simplicity of reproduction I've focused on just three colours, but it doesn't mean that there are other value errors present.
Here's a copy of the ffmpeg bug text:
Summary of the bug: inaccurate conversion from BT.2020 NCL YCbCr Narrow range to BT.2020 RGB Full range using zscale filter
How to reproduce (on the latest github windows build ffmpeg-20190722-3883c9d-win64-static):
100% White - CORRECT
Source YCbCr value = 0x03ac, 0x0200, 0x0200 (940, 512, 512)
Observed RGB value = 65535, 65535, 65535
Expected RGB value = 65535, 65535, 65535
58% White - INCORRECT
Source YCbCr value = 0x023c, 0x0200, 0x0200 (572, 512, 512)
Observed RGB value = 39423, 39423, 39423
Expected RGB value = 38004, 38004, 38004
100% Magenta - ALMOST CORRECT
Source YCbCr value = 0x015a, 0x343, 0x039c
Observed RGB value = 65535, 0, 65535
Expected RGB value = 65533, 0, 65535
The text was updated successfully, but these errors were encountered: