Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/FFmpegReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading