libobs/media-io: Restore color range conversion

FFmpeg needs color range during context init to handle conversions.
sws_setColorspaceDetails after the fact is too late.
This commit is contained in:
jpark37 2022-09-25 11:47:36 -07:00 committed by Jim
parent 743117f080
commit 3dd0f895f8
2 changed files with 17 additions and 9 deletions

View file

@ -297,11 +297,7 @@ static size_t video_get_input_idx(const video_t *video,
static bool match_range(enum video_range_type a, enum video_range_type b)
{
//return (a == VIDEO_RANGE_FULL) == (b == VIDEO_RANGE_FULL);
/* TODO: Restore test when full NV12 to limited NV12 works */
UNUSED_PARAMETER(a);
UNUSED_PARAMETER(b);
return true;
return (a == VIDEO_RANGE_FULL) == (b == VIDEO_RANGE_FULL);
}
static enum video_colorspace collapse_space(enum video_colorspace cs)

View file

@ -19,6 +19,7 @@
#include "video-scaler.h"
#include <libavutil/imgutils.h>
#include <libavutil/opt.h>
#include <libswscale/swscale.h>
struct video_scaler {
@ -188,16 +189,27 @@ int video_scaler_create(video_scaler_t **scaler_out,
goto fail;
}
scaler->swscale = sws_getCachedContext(NULL, src->width, src->height,
format_src, dst->width,
dst->height, format_dst,
scale_type, NULL, NULL, NULL);
scaler->swscale = sws_alloc_context();
if (!scaler->swscale) {
blog(LOG_ERROR, "video_scaler_create: Could not create "
"swscale");
goto fail;
}
av_opt_set_int(scaler->swscale, "sws_flags", scale_type, 0);
av_opt_set_int(scaler->swscale, "srcw", src->width, 0);
av_opt_set_int(scaler->swscale, "srch", src->height, 0);
av_opt_set_int(scaler->swscale, "dstw", dst->width, 0);
av_opt_set_int(scaler->swscale, "dsth", dst->height, 0);
av_opt_set_int(scaler->swscale, "src_format", format_src, 0);
av_opt_set_int(scaler->swscale, "dst_format", format_dst, 0);
av_opt_set_int(scaler->swscale, "src_range", range_src, 0);
av_opt_set_int(scaler->swscale, "dst_range", range_dst, 0);
if (sws_init_context(scaler->swscale, NULL, NULL) < 0) {
blog(LOG_ERROR, "video_scaler_create: sws_init_context failed");
goto fail;
}
ret = sws_setColorspaceDetails(scaler->swscale, coeff_src, range_src,
coeff_dst, range_dst, 0, FIXED_1_0,
FIXED_1_0);