UnityPlugin-AVProVideo icon indicating copy to clipboard operation
UnityPlugin-AVProVideo copied to clipboard

Color Shift Between Quicktime and AV Pro for Android

Open avclubvids opened this issue 2 years ago • 30 comments

There is a noticeable color shift between an h265 played in Quicktime or other video players on OSX and Unity/AVP/Android. It is not a simple gamma shift, as hue and saturation are affected too. Reference images:

h265 in Quicktime (correct):

Screenshot 2023-02-07 at 12 09 53 PM

h265 in Unity using AVP (incorrect, looks like this on a Quest as well):

Screenshot 2023-02-07 at 12 09 33 PM

h265 in Unity using the Unity Video Player (pretty much correct):

Screenshot 2023-02-14 at 12 42 24 AM

h265 in Unity using AVP + manual color correction with Post Processing Stack v2 (subjective but acceptable):

Screenshot 2023-02-24 at 8 03 41 PM

h265 converted to h264 using ffmpeg to change color metadata, in Unity using AVP with no post-processing (close to correct):

Screenshot 2023-02-25 at 1 49 47 AM
  • Unity version: 2021.3.8.f1
  • AVPro Video version: Core 2.7.3
  • Operating system version: OSX 13.1
  • Device model: MBP 16-inch, 2019
  • Video specs (resolution, frame-rate, codec, file size): 4096x4096, 29.97fps, h265, 8.68GB

To Reproduce

  1. load an h265 in Unity load into a MediaPlayer, and observe color shift by comparing it with the same file open in a video player like Quicktime

My thought is that the color space flags in the files are either being read incorrectly or there needs to be a user-editable setting for what AVP should assume a video is in terms of gamma and gamut. The above h264 is close enough to be acceptable, I made it using the advice in this thread: https://github.com/RenderHeads/UnityPlugin-AVProMovieCapture/issues/55.

The h265 shows this in ffprobe:

Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709/bt709/unknown, progressive), 4096x4096 [SAR 1:1 DAR 1:1], 110595 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)

And the h264 I made from it is:

Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 4096x4096 [SAR 1:1 DAR 1:1], 12303 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)

avclubvids avatar Feb 25 '23 10:02 avclubvids

So both Android and macOS editor are producing the same output, but this differs from the output as seen in Quicktime?

I'm a little confused as the ffprobe output you've pasted at the end is showing the codec as being h264 in both cases, although the first one is using the full colour range (yuvj420p).

Are you able to share your test video? If so please send a link to it to [email protected] mentioning this issue in the emails subject. It will certainly help in trying to diagnose what is happening.

MorrisRH avatar Feb 25 '23 18:02 MorrisRH

Sorry I gave the wrong ffprobe data for the h265 (...too many test videos...). I'm emailing you 4 different files I just made for testing, I'm stepping through them now in Unity to see what is what. Here's the ffprobe for them:

4k_testPatterns_sRGB_g22_h264_video_v001.mov: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/unknown, progressive), 4096x4096 [SAR 1:1 DAR 1:1], 3658 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)

4k_testPatterns_sRGB_g22_h264_full_v001.mov: Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709/bt709/unknown, progressive), 4096x4096 [SAR 1:1 DAR 1:1], 3892 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)

4k_testPatterns_sRGB_g22_h265_full_v001.mov: Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(pc, bt709/bt709/unknown, progressive), 4096x4096 [SAR 1:1 DAR 1:1], 993 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)

4k_testPatterns_sRGB_g22_h265_video_v001.mov: Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(tv, bt709/bt709/unknown, progressive), 4096x4096 [SAR 1:1 DAR 1:1], 894 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)

avclubvids avatar Feb 27 '23 20:02 avclubvids

@MorrisRH - to answer your question:

So both Android and macOS editor are producing the same output, but this differs from the output as seen in Quicktime?

Yes, that is correct. Full-range movie files appear the same in Resolve/Quicktime/etc. but they have a large shift when viewed in Unity's editor using AVP, as well as in the headset (Quest 2) with a built app.

avclubvids avatar Feb 27 '23 20:02 avclubvids

Ok, screenshot comparisons of the above 4 video files are below. In each screencap Unity/AVP are on the left and Quicktime is on the right. As you can see there is an issue where videos with Full range pixel values ("pc" flag in ffprobe) are definitely not read correctly in AVP/Unity. Even the Video range ("tv" flag in ffprobe) files are not totally correct - there is a slight red hue to everything in AVP. Worth noting: h264 and h265 have the same color throughout so this is not a codec issue per se:

h264 Full Range: h264_full

h264 Video range: h264_video

h265 Full range: h265_full

h265 Video range: h265_video

avclubvids avatar Feb 28 '23 02:02 avclubvids

Sorry I gave the wrong ffprobe data for the h265 (...too many test videos...). I'm emailing you 4 different files I just made for testing, I'm stepping through them now in Unity to see what is what. Here's the ffprobe for them:

4k_testPatterns_sRGB_g22_h264_video_v001.mov: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/unknown, progressive), 4096x4096 [SAR 1:1 DAR 1:1], 3658 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)

4k_testPatterns_sRGB_g22_h264_full_v001.mov: Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709/bt709/unknown, progressive), 4096x4096 [SAR 1:1 DAR 1:1], 3892 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)

4k_testPatterns_sRGB_g22_h265_full_v001.mov: Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(pc, bt709/bt709/unknown, progressive), 4096x4096 [SAR 1:1 DAR 1:1], 993 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)

4k_testPatterns_sRGB_g22_h265_video_v001.mov: Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(tv, bt709/bt709/unknown, progressive), 4096x4096 [SAR 1:1 DAR 1:1], 894 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)

Still waiting for these to arrive, but that'll be really helpful - thanks.

MorrisRH avatar Feb 28 '23 08:02 MorrisRH

I emailed a Dropbox link to [email protected] - did it possibly get stuck in a spam folder?

avclubvids avatar Feb 28 '23 08:02 avclubvids

We've not received it. Nothing in the spam folder either. How long ago did you send it? Could you double check the email address and resend please?

Chris-RH avatar Feb 28 '23 09:02 Chris-RH

It's definitely sent to the email address provided... here, there's nothing sensitive about this link so please see if this works:

https://www.dropbox.com/sh/lfthpjk2r32z86s/AAAZlDZ3E-4am58Xde5i8IOta?dl=0

avclubvids avatar Feb 28 '23 18:02 avclubvids

Thanks for the link. I've downloaded the videos and will investigate.

MorrisRH avatar Mar 03 '23 09:03 MorrisRH

@MorrisRH I ran out of room in my Dropbox so I had to move those videos out, let me know if you still need them and I'll put them back and send the new generated link

avclubvids avatar Mar 15 '23 05:03 avclubvids

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 25 '23 07:03 stale[bot]

@MorrisRH @Chris-RH – are you guys seeing this color shift on your end?

avclubvids avatar Mar 25 '23 17:03 avclubvids

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 26 '23 00:04 stale[bot]

Was this issue ever able to be resolved?

avclubvids avatar Apr 26 '23 07:04 avclubvids

Its still being looked into

Chris-RH avatar Apr 26 '23 10:04 Chris-RH

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 08 '23 23:05 stale[bot]

Can you see if there has been any improvement with the latest release (2.8.1) please? :)

Chris-RH avatar Jun 30 '23 12:06 Chris-RH

I'm testing with more media and settings now, but initially, it looks like the reddish tint is gone. Is there anything in particular that I should A/B in the new version with the old?

avclubvids avatar Jun 30 '23 18:06 avclubvids

I've chased my tail thinking QuickTime was ground truth before. I then found out Apple uses a nonstandard gamma space. https://larryjordan.com/articles/caution-premiere-pro-final-cut-pro-x-and-quicktime-player-dont-show-the-same-color-the-same-way/

Try opening the video in VLC or ElMedia Player which I've found behave like every other video player on the planet except QuickTime.

acgourley avatar Jul 28 '23 05:07 acgourley

In this case the ground truth is Resolve, which I have a 1:1 color match with in Quicktime, then once it hits AVP in Unity the color shift appears. The color matches in Resolve, QT, VLC, DJV_View, and CineSync.

avclubvids avatar Jul 28 '23 06:07 avclubvids

I see. Actually I am seeing something similar, AVPro not reading yuvj420p (PC range) files correctly. For example, those captured from a GoPro. I took a video of a color calibration card, and loaded it in the AVPro demo to compare it to the Quicktime rendition.

I believe AVPro's reading of the file is not correctly converting from the PC color range to the TV color range. As a result, it's showing darks darker, and lights lighter. I made a screenshot below with my findings (the luminance value is of the 3rd grey from the left). You can see my test file here.

Screenshot 2023-08-01 at 6 20 16 PM

Note: other viewers agree with Quicktime, so it's not just the Quicktime gamma curve selection at play here.

acgourley avatar Aug 02 '23 01:08 acgourley

Yes, that is quite a clear difference. Interesting that such a small difference in luminance value can make a big difference,

Chris-RH avatar Aug 02 '23 10:08 Chris-RH

Thanks for the test media. There is definitely an issue with 10bit full range videos not being handled correctly. We will get this fixed for the next release

MorrisRH avatar Aug 03 '23 07:08 MorrisRH

I sent the 10-bit file by mistake in my previous post. The screenshot above is of the 8-bit file. I just bring that up to indicate I believe it's a PC range issue, not a 10-bit issue.

8 Bit Test Clip 10 Bit Test Clip

I haven't actually done the test on the 10-bit one, so I hope having both in your hands will be helpful for confirmation.

p.s. you guys are awesome thanks for always being on top of things.

acgourley avatar Aug 03 '23 15:08 acgourley

I've fixed up macOS and iOS so that full range is now handled correctly and the fix will make it into the next release.

MorrisRH avatar Aug 25 '23 10:08 MorrisRH

will the fix also work in Android? that's what started all these troubles... (Quest 2)

avclubvids avatar Aug 25 '23 14:08 avclubvids

Can you give us a short update on the issue with Android @acgourley ?

  • Do you have a video that shows it off (maybe we already have it?) and is it encoded as full colour range?
  • Are you in Linear or Gamma colour space?
  • Are you using OES or none-OES?
  • What shader are you using?
  • Have you tried other devices than the Quest 2?

Ste-RH avatar Aug 31 '23 15:08 Ste-RH

I never tried on android, that was @avclubvids

acgourley avatar Sep 06 '23 15:09 acgourley

Apologies, picked the wrong person from the auto list :)

Ste-RH avatar Sep 06 '23 16:09 Ste-RH

I've fixed up macOS and iOS so that full range is now handled correctly and the fix will make it into the next release.

I wanted to confirm 2.8.5 seems to be working for me on OSX, with the displayed color very close to quicktimes for the same video. For anyone testing this, make sure to restart Unity after updating AVPro.

acgourley avatar Sep 07 '23 20:09 acgourley