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

Color difference between preview and render #3850

Closed
m1gu3l opened this issue May 9, 2024 · 8 comments · Fixed by #3855 or #3857
Closed

Color difference between preview and render #3850

m1gu3l opened this issue May 9, 2024 · 8 comments · Fixed by #3855 or #3857
Labels
bug Something isn't working

Comments

@m1gu3l
Copy link

m1gu3l commented May 9, 2024

There's very noticeable difference in how Video and OffthreadVideo handles colors.

From a color, f.e. #00BDF2, let's create a JPEG, a PNG and a video.
blue.jpeg

blue.png

ffmpeg -f lavfi -i color=c=#00BDF2:s=1920x1080:r=30 -vf "format=yuv420p, colorspace=iall=bt601-6-525:all=bt709:fast=1" -t 10 -c:v libx264 -profile:v main output.mp4

output.mp4

Having these assets, let's create Remotion video.

<Composition
  id="BlueVideo"
  width={640}
  height={480}
  fps={25}
  durationInFrames={120}
  component={() => (
    <AbsoluteFill>
      <Sequence from={0} durationInFrames={30}>
        <Img src="http://localhost:8080/assets/blue.jpg" />
        <div
          style={{
            position: 'absolute',
            backgroundColor: '#00BDF2',
            padding: 20,
          }}
        >
          JPEG
        </div>
      </Sequence>
      <Sequence from={30} durationInFrames={30}>
        <Img src="http://localhost:8080/assets/blue.png" />
        <div
          style={{
            position: 'absolute',
            backgroundColor: '#00BDF2',
            padding: 20,
          }}
        >
          PNG
        </div>
      </Sequence>
      <Sequence from={60} durationInFrames={30}>
        <Video src="http://localhost:8080/assets/output.mp4" />
        <div
          style={{
            position: 'absolute',
            backgroundColor: '#00BDF2',
            padding: 20,
          }}
        >
          VIDEO
        </div>
      </Sequence>
      <Sequence from={90} durationInFrames={30}>
        <OffthreadVideo src="http://localhost:8080/assets/output.mp4" />
        <div
          style={{
            position: 'absolute',
            backgroundColor: '#00BDF2',
            padding: 20,
          }}
        >
          OFFTHREAD VIDEO
        </div>
      </Sequence>
    </AbsoluteFill>
  )}
/>

While previewing in Remotion Studio everything looks fine; after rendering though OffthreadVideo produces invalid color.

BlueVideo.mp4

Tested on current Remotion (4.0.153) and FFmpeg 6.0-6ubuntu1

@m1gu3l m1gu3l added the bug Something isn't working label May 9, 2024
@JonnyBurger
Copy link
Member

You can also render in bt709 in Remotion with a flag: https://www.remotion.dev/docs/cli/render#--color-space

We'll make this the default in Remotion 5.0!

@m1gu3l
Copy link
Author

m1gu3l commented May 9, 2024

The final (broken) video was rendered in BT709

@JonnyBurger JonnyBurger reopened this May 9, 2024
@JonnyBurger
Copy link
Member

Alright, thanks for filing!

I will take a look.

@JonnyBurger
Copy link
Member

Thanks!

I managed to improve the output:

New:
new

Old:

old

When adding a video, Remotion extracts the frames using Rust and returns images to the browser.
This input video is bt709, so when we extract frames, it is approximately sRGB format, but we returned .bmp.

We get better results when we return .png's instead which we can tag as sRGB.
Chrome interprets this better.

When doing a conversion, there is always a bit of color loss, but it is way less now.

@m1gu3l
Copy link
Author

m1gu3l commented May 10, 2024

That's really close, looking good!

Thanks for quick fix 😀

@JonnyBurger
Copy link
Member

Unfortunately this regressed and was the wrong way to go about it.
It only worked for this shade of blue.

This change will be reverted in 4.0.155.

I'm making another attempt which seems more promising.

@JonnyBurger
Copy link
Member

Will try to fix this with #3857

@m1gu3l
Copy link
Author

m1gu3l commented May 16, 2024

Is there a way I could support you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants