From 292c4338c0968ac150930240bf615bb76e7eee74 Mon Sep 17 00:00:00 2001 From: wang-bin Date: Tue, 17 Dec 2024 23:25:48 +0800 Subject: [PATCH] add mkv webvtt patch https://github.com/wang-bin/mdk-sdk/issues/262 --- .../0034-matroska-support-S_TEXT-WEBVTT.patch | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 patches/master/0034-matroska-support-S_TEXT-WEBVTT.patch diff --git a/patches/master/0034-matroska-support-S_TEXT-WEBVTT.patch b/patches/master/0034-matroska-support-S_TEXT-WEBVTT.patch new file mode 100644 index 0000000..0101bf4 --- /dev/null +++ b/patches/master/0034-matroska-support-S_TEXT-WEBVTT.patch @@ -0,0 +1,108 @@ +From cff3e71ddd009f940385a952bd080456e1fca3f3 Mon Sep 17 00:00:00 2001 +From: wang-bin +Date: Tue, 17 Dec 2024 23:21:57 +0800 +Subject: [PATCH 34/34] matroska: support S_TEXT/WEBVTT + +--- + libavformat/matroska.c | 1 + + libavformat/matroskadec.c | 27 +++++++++++++++++++++++++++ + 2 files changed, 28 insertions(+) + +diff --git a/libavformat/matroska.c b/libavformat/matroska.c +index d0ecfbeb6a..23c4ad6949 100644 +--- a/libavformat/matroska.c ++++ b/libavformat/matroska.c +@@ -63,6 +63,7 @@ const CodecTags ff_mkv_codec_tags[]={ + {"D_WEBVTT/CAPTIONS" , AV_CODEC_ID_WEBVTT}, + {"D_WEBVTT/DESCRIPTIONS", AV_CODEC_ID_WEBVTT}, + {"D_WEBVTT/METADATA" , AV_CODEC_ID_WEBVTT}, ++ {"S_TEXT/WEBVTT" , AV_CODEC_ID_WEBVTT}, + + {"S_TEXT/UTF8" , AV_CODEC_ID_SUBRIP}, + {"S_TEXT/UTF8" , AV_CODEC_ID_TEXT}, +diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c +index 0e150f9138..c0d8e59920 100644 +--- a/libavformat/matroskadec.c ++++ b/libavformat/matroskadec.c +@@ -3765,6 +3765,7 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska, + MatroskaTrack *track, + AVStream *st, + uint8_t *data, int data_len, ++ MatroskaBlockMore *blockmore, int nb_blockmore, // style + uint64_t timecode, + uint64_t duration, + int64_t pos) +@@ -3773,14 +3774,29 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska, + uint8_t *id, *settings, *text, *buf; + int id_len, settings_len, text_len; + uint8_t *p, *q; ++ int webm_style = !strncmp(track->codec_id, "D_WEBVTT/", 9); + int err; + + if (data_len <= 0) + return AVERROR_INVALIDDATA; + ++ if (!webm_style) { ++ text = data; ++ text_len = data_len; ++ if (nb_blockmore <= 0) ++ goto make_pkt; ++ data = blockmore->additional.data; ++ data_len = blockmore->additional.size; ++ } ++ + p = data; + q = data + data_len; + ++ if (webm_style) ++ goto parse_id; ++ goto parse_settings; ++ ++parse_id: + id = p; + id_len = -1; + while (p < q) { +@@ -3796,7 +3812,11 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska, + if (p >= q || *p != '\n') + return AVERROR_INVALIDDATA; + p++; ++ if (webm_style) ++ goto parse_text; ++ goto make_pkt; + ++parse_settings: + settings = p; + settings_len = -1; + while (p < q) { +@@ -3812,7 +3832,12 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska, + if (p >= q || *p != '\n') + return AVERROR_INVALIDDATA; + p++; ++ if (webm_style) ++ goto parse_text; ++ goto parse_id; + ++// parse_comment ++parse_text: + text = p; + text_len = q - p; + while (text_len > 0) { +@@ -3823,6 +3848,7 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska, + text_len = len; + } + ++make_pkt: + if (text_len <= 0) + return AVERROR_INVALIDDATA; + +@@ -4215,6 +4241,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf + } else if (st->codecpar->codec_id == AV_CODEC_ID_WEBVTT) { + res = matroska_parse_webvtt(matroska, track, st, + out_data, out_size, ++ blockmore, nb_blockmore, + timecode, lace_duration, + pos); + if (!buf) +-- +2.39.5 (Apple Git-154) +