Parcourir la source

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.
jpark37 il y a 3 ans
Parent
commit
fb972b2520
2 fichiers modifiés avec 17 ajouts et 9 suppressions
  1. 1 5
      libobs/media-io/video-io.c
  2. 16 4
      libobs/media-io/video-scaler-ffmpeg.c

+ 1 - 5
libobs/media-io/video-io.c

@@ -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)

+ 16 - 4
libobs/media-io/video-scaler-ffmpeg.c

@@ -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);