From 7c740f555a7a76a6e0a592c9550f2961455d506b Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 18 Sep 2023 17:14:26 +0300 Subject: [PATCH] Promote colorspace information from decoder to swscale in FFmpeg backend. --- modules/videoio/src/cap_ffmpeg_impl.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index e4431b323e..0fa3b26882 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -1636,6 +1636,7 @@ bool CvCapture_FFMPEG::retrieveFrame(int flag, unsigned char** data, int* step, return false; CV_LOG_DEBUG(NULL, "Input picture format: " << av_get_pix_fmt_name((AVPixelFormat)sw_picture->format)); + CV_LOG_DEBUG(NULL, "Input picture colorspace: " << av_get_colorspace_name(sw_picture->colorspace)); const AVPixelFormat result_format = convertRGB ? AV_PIX_FMT_BGR24 : (AVPixelFormat)sw_picture->format; switch (result_format) { @@ -1695,6 +1696,12 @@ bool CvCapture_FFMPEG::retrieveFrame(int flag, unsigned char** data, int* step, frame.height = video_st->CV_FFMPEG_CODEC_FIELD->height; frame.data = rgb_picture.data[0]; frame.step = rgb_picture.linesize[0]; + + const int* colorspace_coeffs = sws_getCoefficients(sw_picture->colorspace); + sws_setColorspaceDetails(img_convert_ctx, + colorspace_coeffs, sw_picture->color_range, + colorspace_coeffs, convertRGB? 0: sw_picture->color_range, + 0, 1<<16, 1<<16); } sws_scale(