Skip to content

Feature request: sRGB colourspace / explicit transfer curve support #1968

Closed

Description

@gsuberland

I'm working on an open accessibility library for measuring photosensitive epilepsy risk as per the WCAG 2.0 guidance, similar to the proprietary Harding test used in broadcasting. This test involves measuring the relative luminance of video content over time to detect patterns that may cause people with PSE to suffer seizures. Right now there are no convenient open libraries for perfoming this test, so my aim is to implement one.

The WCAG 2.0 guidance specifies that relative luminance is to be measured in the sRGB colourspace, i.e. a space with the ITU709 primaries and white point but with an alternative transfer function. At the moment, PyAV only supports ITU709 with the default transfer curve. FFmpeg supports the sRGB colour space by specifying bt709 but with the TRC set to iec61966_2_4.

Since my application is centered around decoding the correct luminance, it is sensitive to using the correct transfer function and simply using ITU709 with the incorrect transfer curve is not appropriate. I could manually convert from ITU709 to sRGB by applying the respective OETF and EOTF in sequence, but this incurs a performance penalty and leads to quantisation error.

I would like to see support in PyAV for the sRGB colour space, either as a new option in av.video.reformatter.Colorspace or via support for explicitly setting the transfer curve. The latter would be the most flexible option.

Activity

  1. gsuberland commented on Jul 26, 2025

    @gsuberland
    Author

    I am not 100% certain, but I think the approach would be to replace this sws_scale call:

    lib.sws_scale(
    self.ptr,
    # Cast for const-ness, because Cython isn't expressive enough.
    <const uint8_t**>frame.ptr.data,
    frame.ptr.linesize,
    0, # slice Y
    frame.ptr.height,
    new_frame.ptr.data,
    new_frame.ptr.linesize,
    )

    With a call to sws_scale_frame instead, after setting the color_trc field of the AVFrame struct to a value in the AVColorTransferCharacteristic enum, which for sRGB would be AVCOL_TRC_IEC61966_2_1.

  2. added a commit that references this issue on Feb 28, 2026
    b35ea65
  3. added a commit that references this issue on Feb 28, 2026
    8760006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions