You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: sRGB colourspace / explicit transfer curve support #1968
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.
# 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.
Activity
gsuberland commentedon Jul 26, 2025
I am not 100% certain, but I think the approach would be to replace this
sws_scalecall:PyAV/av/video/reformatter.pyx
Lines 211 to 220 in 3cb9b63
With a call to
sws_scale_frameinstead, after setting thecolor_trcfield of theAVFramestruct to a value in theAVColorTransferCharacteristicenum, which for sRGB would beAVCOL_TRC_IEC61966_2_1.Add ColorTrc, ColorPrimaries, etc., closes #1968
Add ColorTrc, ColorPrimaries, etc., closes PyAV-Org#1968