aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/mux.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-03-19 23:28:36 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-03-22 23:57:19 +0100
commita24bccc23859b37e03cbf395b3349cb4f707b3e0 (patch)
tree6fb3d44ad0b78c8e8ebf9c10c83da94e7ef015c6 /libavformat/mux.c
parent03b04eef72a5f23e30c2d7700b290d915c31d3a1 (diff)
downloadffmpeg-a24bccc23859b37e03cbf395b3349cb4f707b3e0.tar.gz
avformat/mux: Add flag for "only default codecs allowed"
AVOutputFormat has default codecs for audio, video and subtitle and often these are the only codecs of this type allowed. So add a flag to AVOutputFormat so that this can be checked generically. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/mux.c')
-rw-r--r--libavformat/mux.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 134c2875b6..f23eb0188d 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -268,7 +268,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options)
}
break;
}
- if (of->flags_internal & FF_OFMT_FLAG_MAX_ONE_OF_EACH) {
+ if (of->flags_internal & (FF_OFMT_FLAG_MAX_ONE_OF_EACH | FF_OFMT_FLAG_ONLY_DEFAULT_CODECS)) {
enum AVCodecID default_codec_id = AV_CODEC_ID_NONE;
unsigned nb;
if ((unsigned)par->codec_type < FF_ARRAY_ELEMS(default_codec_offsets)) {
@@ -276,7 +276,14 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options)
if (default_codec_offsets[par->codec_type])
default_codec_id = *(const enum AVCodecID*)((const char*)of + default_codec_offsets[par->codec_type]);
}
- if (default_codec_id == AV_CODEC_ID_NONE || nb > 1) {
+ if (of->flags_internal & FF_OFMT_FLAG_ONLY_DEFAULT_CODECS &&
+ default_codec_id != AV_CODEC_ID_NONE && par->codec_id != default_codec_id) {
+ av_log(s, AV_LOG_ERROR, "%s muxer supports only codec %s for type %s\n",
+ of->p.name, avcodec_get_name(default_codec_id), av_get_media_type_string(par->codec_type));
+ ret = AVERROR(EINVAL);
+ goto fail;
+ } else if (default_codec_id == AV_CODEC_ID_NONE ||
+ (of->flags_internal & FF_OFMT_FLAG_MAX_ONE_OF_EACH && nb > 1)) {
const char *type = av_get_media_type_string(par->codec_type);
av_log(s, AV_LOG_ERROR, "%s muxer does not support %s stream of type %s\n",
of->p.name, default_codec_id == AV_CODEC_ID_NONE ? "any" : "more than one",