[FFmpeg-devel] [PATCH] Use private option to specify WebVTT kind

Matthew Heaney matthewjheaney at google.com
Thu Jun 13 01:22:38 CEST 2013


WebVTT subtitle tracks have four kinds. Certain downstream muxers
(such as for WebM) need to know which WebVTT kind this is, in order to
specify the codec id of the output track.

A new private input option, "-kind", has been added to the WebVTT
demuxer.  It accepts as a value any of "subtitles" (the default),
"captions", "descriptions", and "metadata".  The kind option value is
used to assign a value to the stream disposition flag, to which four
new values have been added, corresponding the four WebVTT kinds.
---
 doc/APIchanges          |  3 +++
 libavformat/avformat.h  |  7 ++++++
 libavformat/version.h   |  2 +-
 libavformat/webvttdec.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 1ab17c2..4a05703 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -16,6 +16,9 @@ libavutil:     2012-10-22
 API changes, most recent first:
 
 
+2013-06-12 - xxxxxxx - lavf 55.10.100 - avformat.h
+  Add AV_DISPOSITION_* flags to indicate text track kind.
+
 2013-06-05 - fc962d4 - lavu 52.13.0 - mem.h
   Add av_realloc_array and av_reallocp_array
 
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 1d7ba45..bd911ec 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -636,6 +636,13 @@ typedef struct AVIndexEntry {
 #define AV_DISPOSITION_ATTACHED_PIC      0x0400
 
 /**
+ * To specify text track kind (different from subtitles default).
+ */
+#define AV_DISPOSITION_CAPTIONS     0x10000
+#define AV_DISPOSITION_DESCRIPTIONS 0x20000
+#define AV_DISPOSITION_METADATA     0x40000
+
+/**
  * Options for behavior on timestamp wrap detection.
  */
 #define AV_PTS_WRAP_IGNORE      0   ///< ignore the wrap
diff --git a/libavformat/version.h b/libavformat/version.h
index b2221d2..45932d4 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 55
-#define LIBAVFORMAT_VERSION_MINOR  9
+#define LIBAVFORMAT_VERSION_MINOR 10
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
diff --git a/libavformat/webvttdec.c b/libavformat/webvttdec.c
index 7d9910b..2335ca4 100644
--- a/libavformat/webvttdec.c
+++ b/libavformat/webvttdec.c
@@ -29,9 +29,21 @@
 #include "subtitles.h"
 #include "libavutil/bprint.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+
+enum WebVTTKind {
+    WEBVTT_KIND_FIRST = 0,
+    WEBVTT_KIND_SUBTITLES = WEBVTT_KIND_FIRST,
+    WEBVTT_KIND_CAPTIONS,
+    WEBVTT_KIND_DESCRIPTIONS,
+    WEBVTT_KIND_METADATA,
+    WEBVTT_KIND_LAST = WEBVTT_KIND_METADATA
+};
 
 typedef struct {
+    const AVClass *class;
     FFDemuxSubtitlesQueue q;
+    enum WebVTTKind kind;
 } WebVTTContext;
 
 static int webvtt_probe(AVProbeData *p)
@@ -67,6 +79,21 @@ static int webvtt_read_header(AVFormatContext *s)
     st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
     st->codec->codec_id   = AV_CODEC_ID_WEBVTT;
 
+    switch (webvtt->kind) {
+    case WEBVTT_KIND_CAPTIONS:
+      st->disposition |= AV_DISPOSITION_CAPTIONS;
+      break;
+    case WEBVTT_KIND_DESCRIPTIONS:
+      st->disposition |= AV_DISPOSITION_DESCRIPTIONS;
+      break;
+    case WEBVTT_KIND_METADATA:
+      st->disposition |= AV_DISPOSITION_METADATA;
+      break;
+    case WEBVTT_KIND_SUBTITLES:
+    default:
+        break;
+    };
+
     av_bprint_init(&header, 0, AV_BPRINT_SIZE_UNLIMITED);
     av_bprint_init(&cue,    0, AV_BPRINT_SIZE_UNLIMITED);
 
@@ -186,6 +213,35 @@ static int webvtt_read_close(AVFormatContext *s)
     return 0;
 }
 
+#define OFFSET(x) offsetof(WebVTTContext, x)
+#define KIND_FLAGS AV_OPT_FLAG_SUBTITLE_PARAM
+
+static const AVOption options[] = {
+    { "kind", "Kind of WebVTT track",
+      OFFSET(kind), AV_OPT_TYPE_INT, { .i64 = WEBVTT_KIND_SUBTITLES },
+      WEBVTT_KIND_FIRST, WEBVTT_KIND_LAST, KIND_FLAGS, "WEBVTT_KIND" },
+    { "subtitles", "WebVTT subtitles kind",
+      0, AV_OPT_TYPE_CONST, { .i64 = WEBVTT_KIND_SUBTITLES },
+      INT_MIN, INT_MAX, 0, "WEBVTT_KIND" },
+    { "captions", "WebVTT captions kind",
+      0, AV_OPT_TYPE_CONST, { .i64 = WEBVTT_KIND_CAPTIONS },
+      INT_MIN, INT_MAX, 0, "WEBVTT_KIND" },
+    { "descriptions", "WebVTT descriptions kind",
+      0, AV_OPT_TYPE_CONST, { .i64 = WEBVTT_KIND_DESCRIPTIONS },
+      INT_MIN, INT_MAX, 0, "WEBVTT_KIND" },
+    { "metadata", "WebVTT metadata kind",
+      0, AV_OPT_TYPE_CONST, { .i64 = WEBVTT_KIND_METADATA },
+      INT_MIN, INT_MAX, 0, "WEBVTT_KIND" },
+    { NULL }
+};
+
+static const AVClass webvtt_demuxer_class = {
+    .class_name  = "WebVTT demuxer",
+    .item_name   = av_default_item_name,
+    .option      = options,
+    .version     = LIBAVUTIL_VERSION_INT,
+};
+
 AVInputFormat ff_webvtt_demuxer = {
     .name           = "webvtt",
     .long_name      = NULL_IF_CONFIG_SMALL("WebVTT subtitle"),
@@ -196,4 +252,5 @@ AVInputFormat ff_webvtt_demuxer = {
     .read_seek2     = webvtt_read_seek,
     .read_close     = webvtt_read_close,
     .extensions     = "vtt",
+    .priv_class     = &webvtt_demuxer_class,
 };
-- 
1.8.3



More information about the ffmpeg-devel mailing list