[FFmpeg-cvslog] avformat/matroskaenc: refactor checks for allowed codecs in WebM
James Almer
git at videolan.org
Wed Sep 26 21:47:52 EEST 2018
ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Fri Sep 21 16:18:15 2018 -0300| [8439656503e9189bc34dcb71aa3fc76a20d6a4b2] | committer: James Almer
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 at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8439656503e9189bc34dcb71aa3fc76a20d6a4b2
---
libavformat/matroskaenc.c | 30 ++++++++++++++++++------------
1 file 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;
More information about the ffmpeg-cvslog
mailing list