zmwangx / rust-ffmpeg

Safe FFmpeg wrapper.
Do What The F*ck You Want To Public License
1.2k stars 195 forks source link

Implement wrapper for sws_getCoefficients() #174

Open JonnyBurger opened 4 months ago

JonnyBurger commented 4 months ago

Added new set_colorspace_details method for Context (swscaler).

By default, you can use sws_scale, but it by default assumes the default colorspace, which I understand to be BT.601. So if a video with a difference colorspace (BT.709 or BT.2020) is being input, then the colors shifts.

Using this function, you can control it!

For those curious, here is how I intend to use this to convert frames to RGB:

  1. Call let context = Context::get()
  2. Call context.set_colorspace_details
    1. input_space: Pass the value of video.color_space()
    2. src_range: Pass the value of video.color_range()
    3. dst_range: In my case, I want to convert it to RGB, so I want full range, therefore I pass color::Range::JPEG
    4. brightness: I set to to 0 to make no correction
    5. contrast and saturation: I set it to 1 << 16 to make no correction

I have no experience, I just read https://www.canva.dev/blog/engineering/a-journey-through-colour-space-with-ffmpeg/. If you can, please review carefully.