CoSMoSoftware / OBS-studio-webrtc

This is a fork of OBS-studio with generic support for webrtc. It leverages the same webrtc implementation most browsers use.
http://www.cosmosoftware.io
GNU General Public License v2.0
586 stars 131 forks source link

Incorrect color interpretation when streaming via WebRTC #365

Open wanderingcode opened 1 year ago

wanderingcode commented 1 year ago

Since upgrading to OBS 28 the video color is lifted when streaming with WebRtc.
If I switch the stream to Millicast RTMP then the colors are accurate. This was not an issue with OBS 27.2.4 via WebRTC.

In the photos below, the top color chart is Resolve which is the source. That's fed through a Black Magic UltraStudio Mini and received into OBS via a BLack Magic UltraStudio Mini. The bottom color chart is the received stream in a web browser. See the photos below to highlight the color shift when using WebRTC.

Streaming via RTMP Screenshot 2023-02-17 at 1 26 20 PM-ResolveAndRTMP

Streaming via WebRTC

Screenshot 2023-02-17 at 1 27 09 PM-ResolveAndWebRtc

ludocosmo commented 1 year ago

Hi,

I also notice a difference in colors, but it happens both for RTMP and WebRTC for version 27.2.4 as well as for 28.1.2.

Settings:

I stream using the following static image as source: image

Received image displayed in Chrome 109.0.5414.119

Received images are identical, whether they have been streamed using RTMP or WebRTC, OBS 27.2.4 or OBS 28.1.2. There is a color difference from the original static image.

ludocosmo commented 1 year ago

Trying to stream the same static image to Facebook using regular OBS.

Settings:

Source image: image

Received image displayed in Facebook in Chrome 110.0.5481.177

For comparison, this is the image received in Chrome when streaming from OBS WebRTC 28.1.2: image

There is a color difference from the original static image, both when streaming using regular OBS and WebRTC OBS.

ludocosmo commented 1 year ago

I am able to get a slight difference in colour rendering by selecting a different colour format.

This is my source static image: image

Streaming using colour format I420 (no difference when streaming with WebRTC, RTMP, OBS 27.2.4 and 28.1.2) image

We can notice that:

Streaming using colour format NV12 image

We can notice that there is a tiny difference for cyan and green when using colour format NV12 or I420.

============= Here is what happens for your streaming.

Your source image: image

Streaming with RTMP: image

We can notice that all colours and greys are different between source image and streamed image.

Streaming with WebRTC: image

We can notice that all colours and greys are different between RTMP streamed image and WebRTC streamed image.

What are your settings (colour format, colour range, codec):

wanderingcode commented 1 year ago

In our tests the following combo has always produced accurate results and my tests were run with:

codec: VP8 ColorSpace: Rec 601 Pixel Format: NV12 Color Range: Partial (On OBS 28) SDR White Level 300 nits HDR Peak Level 1000 Nits

From your FB tests it looks like this may be an issue in the original OBS and not the WebRTC implementation?

Using these settings I see accurate color reproduction in OBSWebRTC-27.2.4, but not in V28.

The screenshots below shows OBS window on the bottom, and Chrome 110.0.5481.177 on top. Running on MacOS 13.2.1

Below is a screen shot using OBS-WebRTC 27.2.4 (Release 1.3.2)

Screenshot 2023-03-01 at 09 38 56-OBS27 2 4-vp8

And here is a screen shot with OBSWebRTC-28.1.1

Screenshot 2023-03-01 at 09 49 30-OBS-28 1 1-vp8
ludocosmo commented 1 year ago

I reproduced the problem with your settings.

Source image: image

Stream from OBS 1.3.2-27.2.4: image

Stream from OBS 1.4.1-28.1.1: image

Key setting is color space: Rec 601 With color space 709, received images from streaming with OBS 27 and OBS 28 are identical. But with color space 601, received images from streaming with OBS 27 and OBS 28 are different as shown above.

I am investigating the origin of this difference for color space 601.

wanderingcode commented 1 year ago

Thank you for your efforts on this. VP8 spec lists Rec601 as the correct color space, and so far that's the only way I've been able to get accurate color rendering is with the above settings.

I never fully understood why h264 and other codecs don't render the colors correctly in this workflow. (Side note) So far I haven't found a listed color space in the specs for VP9 or AV1. If you happen to see those anywhere I'd love to discover that!

The problem is in OBS 28 Rec601 is no longer is accurate. At first I thought it was incorrectly using Rec701 color space, but my tests show a different color rendering for 601 and 709, both of which are incorrect.

In these photos, top row is via chrome, middle row is OBS window, and bottom row is the source PNG I used.

OBS 27.2.4 Rec601:

Screenshot 2023-03-01 at 11 19 13-OBS_27 2 4-WebRtc-vp8-nv12-rec601-partial

OBS 27.2.4 Rec709:

Screenshot 2023-03-01 at 11 31 01-OBS_27 2 4-VP8-NV12-Rec709-partial

OBS 28.1.1 Rec601:

Screenshot 2023-03-01 at 13 34 12-OBS_28 1 1-VP8-NV12-Rec601-Limited

OBS 28.1.1 Rec709:

Screenshot 2023-03-01 at 13 38 44-OBS_28 1 1-VP8-NV12-Rec709-Limited
ludocosmo commented 1 year ago

I confirm there is an issue in OBS 28 about color space 601. I saved raw frames delivered by OBS before encoding to compare them.

Color management in OBS 28 has been modified a lot as compared to OBS 27. I have not yet identified how they changed management of color space for delivery of raw frames to encoder.

wanderingcode commented 1 year ago

Thank you for doing the raw frame comparison. Let me know if there is more I can do to help discover the root of the issue.

ludocosmo commented 1 year ago

Root of the issue has been identified as a difference in default format of raw frames to be delivered to libwebrtc for encoding.

wanderingcode commented 1 year ago

Excellent! Thank you so much for your efforts in tracking this down and getting it corrected.

wanderingcode commented 1 year ago

Any word on when this fix will be implemented? Thanks