Experimental support to correctly convert 10-bit color into 8-bit colorspace.

This commit is contained in:
Jonathan Thomas
2025-01-05 22:04:24 -06:00
parent dd2a70c9f2
commit 2f576e282f

View File

@@ -1505,6 +1505,26 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) {
SwsContext *img_convert_ctx = sws_getContext(info.width, info.height, AV_GET_CODEC_PIXEL_FORMAT(pStream, pCodecCtx), width,
height, PIX_FMT_RGBA, scale_mode, NULL, NULL, NULL);
// Determine the source and destination color ranges
int srcRange = (pFrame->color_range == AVCOL_RANGE_JPEG) ? 1 : 0;
int dstRange = 0; // Output as limited range (e.g., 8-bit broadcast range)
// Get the source and destination color coefficients
const int *srcCoeff = sws_getCoefficients(pFrame->colorspace);
const int *dstCoeff = sws_getCoefficients(AVCOL_SPC_BT709); // Assume output is BT.709
// Set the color space details in the SwsContext
sws_setColorspaceDetails(
img_convert_ctx,
srcCoeff,
srcRange,
dstCoeff,
dstRange,
0, // brightness adjustment (default: 0)
1 << 16, // contrast adjustment (default: 1.0 in 16.16 fixed-point)
1 << 16 // saturation adjustment (default: 1.0 in 16.16 fixed-point)
);
// Resize / Convert to RGB
sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0,
original_height, pFrameRGB->data, pFrameRGB->linesize);