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

undesirable color convertsion to YCbCr with X2RGB10 (A2RGB10) #222

Closed
MartinPulec opened this issue Jan 23, 2023 · 13 comments
Closed

undesirable color convertsion to YCbCr with X2RGB10 (A2RGB10) #222

MartinPulec opened this issue Jan 23, 2023 · 13 comments

Comments

@MartinPulec
Copy link

Hi, I'm encountering a problem with patched FFmpeg and oneVPL when using pixel format X2RGB10/A2RGB10. Something is performing unwanted RGB->YUV conversion but pretending that the output stream is in RGB. I'd like to have a 10-bit RGB HEVC, anyways. Steps to reproduce:

ffmpeg -f lavfi -i smptebars -pix_fmt x2rgb10le -t 1 -c:v hevc_qsv rgb10.mp4
ffplay rgb10.mp4    # <- colors are shifted here; it has been converted to YUV but displayed as RGB
# mediainfo '--Output=Video;%ColorSpace%' rgb10.mp4  # confirms RGB

I am using this repo submodule FFmpeg with patches applied. iGPU is the one integrated on Intel i7-1260P. Upstream graphics libraries are installed as described here.

I've tried also "bgra" pixfmt but it says it is unsupported. vuyx and xv30le were OK (but encoding YCbCr obviously).

@MartinPulec
Copy link
Author

Just for illustration how it should look:

correct

and how the output actually looks:

incorrect

@MartinPulec
Copy link
Author

MartinPulec commented Feb 1, 2023

AFAIK, the opposite problem holds also for hevc_qsv decoder - if input HEVC stream is a RGB, the decoder decompresses the data depending on bit-depth into XV36, XV30 or VUYX pixfmt (thus YCbCr) but no actual color conversion happens. The decompressed data are original RGB but presented in YCbCr pixel format.

@xhaihao
Copy link
Contributor

xhaihao commented Feb 6, 2023

I've tried also "bgra" pixfmt but it says it is unsupported.

bgra should be supported but you should boot your Linux kernel with HuC support. According to https://github.com/intel/media-driver/blob/master/docs/media_features.md#supported-encoding-input-format-and-max-resolution, HuC is required for RGB input.

@MartinPulec
Copy link
Author

Thanks a lot, I didn't know about this stuff at all, I'll give it a try.

Anyways, perhaps more interesting for our users would to keep/compress 10-bit RGB directly, without CS conversion - should it work? The rightmost column of this table says 'N' for all "Inputs'. But if Input means encode, it contradicts what I've seen - the RGB->YUV conversion was actually performed, but the stream itself identifies as internally RGB.

@wenbinc-Bin
Copy link
Contributor

I can reproduce the problem and I am working on it.

@MartinPulec
Copy link
Author

@wenbinc-Bin thanks a lot!

@xhaihao I can confirm that 8-bit RGB (bgra) works correctly in the HuC mode with patched FFmpeg when set AVCodecContext::low_power == 1.

@wenbinc-Bin
Copy link
Contributor

The cause is that ffmpeg pass sRGB in MatrixCoefficient to VPL but VPL doesn't encode video as RGB. It convert frame to YUV. However VPL still set this flag in stream header. FFmpeg will treat this stream as RGB but actually it is YUV.

@alatteri
Copy link

alatteri commented Feb 9, 2023

Hi @wenbinc-Bin .... I'm not sure from your reply if this is something your team is going to be able to fix or not.
Thanks.

The cause is that ffmpeg pass sRGB in MatrixCoefficient to VPL but VPL doesn't encode video as RGB. It convert frame to YUV. However VPL still set this flag in stream header. FFmpeg will treat this stream as RGB but actually it is YUV.

@wenbinc-Bin
Copy link
Contributor

I will submit patch to fix this.

@wenbinc-Bin
Copy link
Contributor

@MartinPulec
Copy link
Author

Great, thanks for that. I've quickly tested it and it works, the that encoded stream has now correct colors when decoded. Not a big deal but I guess that comment in patch is inverted (RGB gets converted to YCbCr, not vice versa)?

@wenbinc-Bin
Copy link
Contributor

Thank you for pointing it out.

@wenbinc-Bin
Copy link
Contributor

patch is merged: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20230213084926.543371-1-wenbin.chen@intel.com/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants