Skip to content

Color shift on cv::cudacodec::VideoReader when using multiple threads reading videos from different color spaces in parallel #3934

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

Open
laurentchicoine opened this issue May 12, 2025 · 1 comment

Comments

@laurentchicoine
Copy link

Following latest updates to fix YUV Conversion #3828, I started to notice an issue with some video colors that is flickering. The issue only happens when launching multiple video readers from multiple threads on a single process (using Python) and when these videos have a different color space for example some videos with yuvj420p (BT470) and others in yuv420p.

In my use case, as a video is being read, new VideoReader are being created on seperate threads.

When investigating the issue I found that this is caused because the code is using a global constant matYuv2Color that is being updated in SetMatYuv2Rgb with call to cudaMemcpyToSymbol.
https://github.com/opencv/opencv_contrib/blame/eebd8977e158d81a4aaf41653a038b82cf6507d4/modules/cudacodec/src/cuda/ColorSpace.cu#L11

So therefore instanciating a new video reader seems to alter that common constant in some way causing a shift of color since the values in the matrix are different for the other video. I'm not yet 100% sure this is the issue since I did not yet work on fixing it.

I'm unsure how to best resolve this optimally for a proper PR.

@cudawarped since you worked on the original fix.

@cudawarped
Copy link
Contributor

@laurentchicoine This is something I've been meaning to fix since I submitted the original PR. The fix is to pass the yuv2rgb conversion matrix each time a frame is converted. I'll take a look next week.

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

2 participants