diff options
author | James Almer <jamrial@gmail.com> | 2018-09-21 16:18:15 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2018-09-26 15:17:14 -0300 |
commit | 8439656503e9189bc34dcb71aa3fc76a20d6a4b2 (patch) | |
tree | 7bc2b443bafb38e3c8166da0c14b75c665f072f9 /libavformat | |
parent | 794079e81529f63e32ffc3e8ac4a9dae3b80e765 (diff) | |
download | ffmpeg-8439656503e9189bc34dcb71aa3fc76a20d6a4b2.tar.gz |
avformat/matroskaenc: refactor checks for allowed codecs in WebM
Use the new ff_webm_codec_tags[] array for this purpose.
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/matroskaenc.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 90fbaa93f4..4d837c7e60 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1238,8 +1238,17 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, if (st->disposition & AV_DISPOSITION_FORCED) put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGFORCED, 1); - if (mkv->mode == MODE_WEBM && par->codec_id == AV_CODEC_ID_WEBVTT) { + if (mkv->mode == MODE_WEBM) { const char *codec_id; + if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) { + for (j = 0; ff_webm_codec_tags[j].id != AV_CODEC_ID_NONE; j++) { + if (ff_webm_codec_tags[j].id == par->codec_id) { + codec_id = ff_webm_codec_tags[j].str; + native_id = 1; + break; + } + } + } else if (par->codec_id == AV_CODEC_ID_WEBVTT) { if (st->disposition & AV_DISPOSITION_CAPTIONS) { codec_id = "D_WEBVTT/CAPTIONS"; native_id = MATROSKA_TRACK_TYPE_SUBTITLE; @@ -1253,6 +1262,14 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, codec_id = "D_WEBVTT/SUBTITLES"; native_id = MATROSKA_TRACK_TYPE_SUBTITLE; } + } + + if (!native_id) { + av_log(s, AV_LOG_ERROR, + "Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.\n"); + return AVERROR(EINVAL); + } + put_ebml_string(pb, MATROSKA_ID_CODECID, codec_id); } else { // look for a codec ID string specific to mkv to use, @@ -1294,17 +1311,6 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL); } - if (mkv->mode == MODE_WEBM && !(par->codec_id == AV_CODEC_ID_VP8 || - par->codec_id == AV_CODEC_ID_VP9 || - par->codec_id == AV_CODEC_ID_AV1 || - par->codec_id == AV_CODEC_ID_OPUS || - par->codec_id == AV_CODEC_ID_VORBIS || - par->codec_id == AV_CODEC_ID_WEBVTT)) { - av_log(s, AV_LOG_ERROR, - "Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.\n"); - return AVERROR(EINVAL); - } - switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: mkv->have_video = 1; |