From c9f3ceeb56875c7def02e8ecea3d2a1f9f605e8a Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Tue, 26 Nov 2024 16:32:14 +0300
Subject: [PATCH] Exp: do not set ildct flag for qsv_av1/h264/vp9

---
 cinelerra-5.1/cinelerra/ffmpeg.C | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index a857bc3a..d45eb07e 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -2905,6 +2905,16 @@ int FFMPEG::open_encoder(const char *type, const char *spec)
 	FFStream *fst = 0;
 	AVStream *st = 0;
 	AVCodecContext *ctx = 0;
+	
+	/* some encoders dislike ildct flag in ffmpeg 7.0/7.1 */
+	int is_no_ildct;
+	if (!strcmp (codec_name, "av1_qsv") ||
+	!strcmp(codec_name, "h264_qsv") ||
+	!strcmp(codec_name, "vp9_qsv"))
+		is_no_ildct=1;
+	else
+		is_no_ildct=0;
+
 
 	const AVCodecDescriptor *codec_desc = 0;
 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
@@ -3115,7 +3125,7 @@ int FFMPEG::open_encoder(const char *type, const char *spec)
 			av_dict_set(&sopts, "field_order", "tt", 0); 
 			else
 			av_dict_set(&sopts, "field_order", "tb", 0); 
-			if (ctx->codec_id != AV_CODEC_ID_MJPEG) 
+			if (ctx->codec_id != AV_CODEC_ID_MJPEG && !is_no_ildct) 
 			av_dict_set(&sopts, "flags", "+ilme+ildct", 0);
 			break;
 			case ILACE_MODE_BOTTOM_FIRST: 
@@ -3123,7 +3133,7 @@ int FFMPEG::open_encoder(const char *type, const char *spec)
 			av_dict_set(&sopts, "field_order", "bb", 0); 
 			else
 			av_dict_set(&sopts, "field_order", "bt", 0); 
-			if (ctx->codec_id != AV_CODEC_ID_MJPEG)
+			if (ctx->codec_id != AV_CODEC_ID_MJPEG && !is_no_ildct)
 			av_dict_set(&sopts, "flags", "+ilme+ildct", 0);
 			break;
 			case ILACE_MODE_NOTINTERLACED: av_dict_set(&sopts, "field_order", "progressive", 0); break;
-- 
2.47.0

