We’ve noticed that any video recorded on iPhone 12 onwards appears washed out and tinted in a weird way when played via VideoPlayer using url pointing at the local file on device.
We’re using Unity 2021.3.5f1.
We believe that the problem is that iPhone 12 on record video in HDR, which uses the HEVC (H.265) format.
Can anyone from Unity speak to this?
Can you output the file metadata with MediaInfo if you can or share the file in DM? We officially support HEVC on iPhone 12 and most of our devices used to test are iPhone 12, so it should work. Do you get any errors other than the artifacts? Can you share a screenshot of what you mean?
Here’s our video - left is how it should look, right is the same video loaded in Unity, using a RawImage. We don’t have any filters, post effects or anything like that.
I’ll DM you the video now!
Here is the output from MediaInfo. There are three potential issues.
Video
ID : 1
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main 10@L4.1@Main
HDR format : Dolby Vision, Version 1.0, dvhe.08.04, BL+RPU, HLG compatible
Codec ID : hvc1
Codec ID/Info : High Efficiency Video Coding
Duration : 59 s 470 ms
Bit rate : 15.2 Mb/s
Width : 1 920 pixels
Clean aperture width : 1 920 pixels
Height : 1 080 pixels
Clean aperture height : 1 080 pixels
Display aspect ratio : 16:9
Rotation : 90°
Frame rate mode : Variable
Frame rate : 30.000 FPS
Minimum frame rate : 28.571 FPS
Maximum frame rate : 30.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 10 bits
Bits/(Pixel*Frame) : 0.244
Stream size : 108 MiB (99%)
Title : Core Media Video
Encoded date : UTC 2022-09-08 14:28:48
Tagged date : UTC 2022-09-08 14:29:46
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : HLG
Matrix coefficients : BT.2020 non-constant
Codec configuration box : hvcC+dvvC
- Your HEVC clip has a bit depth of 10 bits, which is not well supported on every platform. For example, Windows doesn’t support it.
- I don’t know if you saw it, but the color in your video is shifted. The reason is your video color space is BT.2020, and we only support BT.709 and BT.601.
- And as you mention, the video has HDR, and the blurriness is probably for that. We would need to investigate more on the subject, but the HDR aspect of it possibly means there are multiple images per frame for multiple exposure levels.
I don’t think it is something we can easily fix or find a workaround for. I would appreciate it if you could write your use case on our roadmap Audio and video workflow roadmap | Unity. It helps us plan for these kinds of needs and allows us to prioritize what to work on next. I hope it helps!
Thanks for this!
The blurriness is me - wanted to hide my coworker’s face
I’ll triple check this with my team, but I’m certain the clip was recorded using the standard iPhone 12 (or in other cases, 12 and above) camera app. We’ve had some reports from our users too.
We think it’s the case that the bit depth and color space is something that Apple is doing by default - but it’s very strange that your team hasn’t been able to reproduce it!
Perhaps our issue is caused by the use of this plugin to access the phone’s photo library - although I can’t quite see why that would change anything, since it’s ultimately just returning a file path.
I just tried loading the file itself into Unity and it’s imported with the wrong colors when both in the preview and when loaded via a VideoPlayer.
Oh, I see. I thought the “washed out and tinted in a weird way” was the blurriness and was not sure
To be clear, the bit depth will probably work on some platforms. But it is in the danger zone where it will break on some platforms because the platform doesn’t support it like Windows. HEVC is another thing some platforms just don’t have or don’t support a bit depth of 10. So if you plan to support multiple platforms, you will maybe have some issues with these clips.
If the tint and washed is the color then you can test this theory by converting the clip to bt709.
https://stackoverflow.com/questions/64981984/ffmpeg-transcode-uhd-h265-to-sdr-h264-without-color-loss
And finally no, Apple doesn’t do the YUV conversion. We are doing it. It is why we have to support BT.2020 for it to work.
Right! Is it then weird that we’re seeing this on iOS? Our app is iOS only, and so aside from testing in editor we’re recording and viewing videos on iOS exclusively.
Hi! Is there any update on this? I’ve tried reading up on formats but this isn’t something I really understand (and appears to be quite complex!).
It’d be useful if you could help us establish if this is an error in Unity or something in our setup that we need to correct for.
We’re both creating video and testing entirely with Apple devices, so it seems unlikely that the issue is due to the platforms we’re using.
We don’t support BT.2020 so not a bug. You can convert your file using this command
ffmpeg -i "IMG_5127 2.mov" -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v h264 -crf 19 -preset ultrafast color_output.mp4
I tested it with your file and it does show the right color now. I will send it to you.
I see! Thanks very much, this has been incredibly helpful. We’re looking into some asset store FFMPEG converters now, so that snippet should be handy.
I’ll update this thread with a solution if we find one.
The converted video you sent works great, although I should note for other devs that the video file doesn’t import into Unity as a Video Asset, but rather as a DefaultAsset - but it loads fine via local or remote URL.
The one thing that still confuses me is that video recorded on iPhone 12+ is supported and are some of the devices tested by your team - we’ve seen this pretty reliably from users using the default camera app on those devices, so I’m a bit unsure what we’ve done differently! Is it that you’ve been explicitly testing non-BT.2020 recordings from those devices because it’s not supported?
Weird I will have a look.
We are making sure the VideoPlayer is supported on the iPhone 12+. We don’t test that video recorded on iPhone 12+ is supported, and we don’t support every possible file configuration. What we share with the recorder is the codec but everything else is different. Contrary to AVFoundation, when we need to add a feature, we need to implement it on all platforms Unity support. So it is always more challenging to add a feature that is not supported on all platforms. While saying that the fact the video recorder on iPhone is using BT.2020, shows that BT.2020 is now mature enough that companies start using it. It is probably something we need to look into but I can’t give you an ETA for this.
Thank you! That’s super clear. Hopefully this thread is useful for others.
We’re optimistic about this asset store package as a solution.