Просмотр исходного кода

deps/libff: Add ff_format_codec_compatible

derrod 2 лет назад
Родитель
Сommit
4f7a73d149
2 измененных файлов с 29 добавлено и 0 удалено
  1. 26 0
      deps/libff/libff/ff-util.c
  2. 3 0
      deps/libff/libff/ff-util.h

+ 26 - 0
deps/libff/libff/ff-util.c

@@ -447,3 +447,29 @@ void ff_format_desc_free(const struct ff_format_desc *format_desc)
 		desc = next;
 	}
 }
+
+
+bool ff_format_codec_compatible(const char *codec, const char *format)
+{
+	if (!codec || !format)
+		return false;
+
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
+	AVOutputFormat *output_format;
+#else
+	const AVOutputFormat *output_format;
+#endif
+	output_format = av_guess_format(format, NULL, NULL);
+	if (!output_format)
+		return false;
+	
+	const AVCodecDescriptor *codec_desc = avcodec_descriptor_get_by_name(codec);
+	if (!codec_desc)
+		return false;
+	
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(60, 0, 100)
+	return avformat_query_codec(output_format, codec_desc->id, FF_COMPLIANCE_EXPERIMENTAL) == 1;
+#else
+	return avformat_query_codec(output_format, codec_desc->id, FF_COMPLIANCE_NORMAL) == 1;
+#endif
+}

+ 3 - 0
deps/libff/libff/ff-util.h

@@ -62,6 +62,9 @@ ff_format_desc_get_default_name(const struct ff_format_desc *format_desc,
 const struct ff_format_desc *
 ff_format_desc_next(const struct ff_format_desc *format_desc);
 
+// Utility to check compatibility
+bool ff_format_codec_compatible(const char *codec, const char *format);
+
 #ifdef __cplusplus
 }
 #endif