[FFmpeg-devel] avformat/matroska: webvtt codec ID according to specification

Submitted by Max E. Aubrey on June 11, 2019, 12:17 a.m.

Details

Message ID 20190611001703.25843-1-maxeaubrey@gmail.com
State New
Headers show

Commit Message

Max E. Aubrey June 11, 2019, 12:17 a.m.
This preserves the old behaviour so as not to break reading "invalid"
files.

Signed-off-by: Max E. Aubrey <maxeaubrey@gmail.com>
---
 libavformat/matroska.c    | 2 ++
 libavformat/matroskaenc.c | 8 ++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/matroska.c b/libavformat/matroska.c
index 4d18d147fc..ccebb031ff 100644
--- a/libavformat/matroska.c
+++ b/libavformat/matroska.c
@@ -60,6 +60,7 @@  const CodecTags ff_mkv_codec_tags[]={
     {"A_VORBIS"         , AV_CODEC_ID_VORBIS},
     {"A_WAVPACK4"       , AV_CODEC_ID_WAVPACK},
 
+    // compatibility for decoding invalid files from old ffmpeg
     {"D_WEBVTT/SUBTITLES"   , AV_CODEC_ID_WEBVTT},
     {"D_WEBVTT/CAPTIONS"    , AV_CODEC_ID_WEBVTT},
     {"D_WEBVTT/DESCRIPTIONS", AV_CODEC_ID_WEBVTT},
@@ -70,6 +71,7 @@  const CodecTags ff_mkv_codec_tags[]={
     {"S_TEXT/ASCII"     , AV_CODEC_ID_TEXT},
     {"S_TEXT/ASS"       , AV_CODEC_ID_ASS},
     {"S_TEXT/SSA"       , AV_CODEC_ID_ASS},
+    {"S_TEXT/WEBVTT"    , AV_CODEC_ID_WEBVTT},
     {"S_ASS"            , AV_CODEC_ID_ASS},
     {"S_SSA"            , AV_CODEC_ID_ASS},
     {"S_VOBSUB"         , AV_CODEC_ID_DVD_SUBTITLE},
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index cef504fa05..04da367a34 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1265,9 +1265,13 @@  static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
 
         put_ebml_string(pb, MATROSKA_ID_CODECID, codec_id);
     } else {
-        // look for a codec ID string specific to mkv to use,
+        // use specification webvtt codec ID string to avoid old compatiblity string
+        // then look for a codec ID string specific to mkv to use,
         // if none are found, use AVI codes
-        if (par->codec_id != AV_CODEC_ID_RAWVIDEO || par->codec_tag) {
+        if (par->codec_id == AV_CODEC_ID_WEBVTT) {
+            put_ebml_string(pb, MATROSKA_ID_CODECID, "S_TEXT/WEBVTT");
+            native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
+        } else if (par->codec_id != AV_CODEC_ID_RAWVIDEO || par->codec_tag) {
             for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
                 if (ff_mkv_codec_tags[j].id == par->codec_id && par->codec_id != AV_CODEC_ID_FFV1) {
                     put_ebml_string(pb, MATROSKA_ID_CODECID, ff_mkv_codec_tags[j].str);