diff mbox series

[FFmpeg-devel] libavformat/webvttenc: Allow (but discard) additional streams

Message ID BYAPR04MB52223BE4FAD1D0F06E650B46BA110@BYAPR04MB5222.namprd04.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel] libavformat/webvttenc: Allow (but discard) additional streams
Related show


Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Soft Works Feb. 18, 2020, 2:26 a.m. UTC
This allows having a video stream as reference stream  when using the segment muxer:

The video stream serves as a kind of 'heartbeat' to ensure that VTT segments are generated regularly, even when there aren't any subtitle packets for a while.

ffmpeg -i INPUT -map 0:3 -c:0 webvtt -map 0:0 -c:v:0 copy -f segment -segment_format webvtt -segment_time 6 -write_empty_segments 1 -y "sub_segment3%d.vtt"

 libavformat/webvttenc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff mbox series


diff --git a/libavformat/webvttenc.c b/libavformat/webvttenc.c index 61b7f54622..be85c03130 100644
--- a/libavformat/webvttenc.c
+++ b/libavformat/webvttenc.c
@@ -49,8 +49,8 @@  static int webvtt_write_header(AVFormatContext *ctx)
     AVCodecParameters *par = ctx->streams[0]->codecpar;
     AVIOContext *pb = ctx->pb;
-    if (ctx->nb_streams != 1 || par->codec_id != AV_CODEC_ID_WEBVTT) {
-        av_log(ctx, AV_LOG_ERROR, "Exactly one WebVTT stream is needed.\n");
+    if (par->codec_id != AV_CODEC_ID_WEBVTT) {
+        av_log(ctx, AV_LOG_ERROR, "First stream must be WebVTT.\n");
         return AVERROR(EINVAL);
@@ -68,6 +68,9 @@  static int webvtt_write_packet(AVFormatContext *ctx, AVPacket *pkt)
     int id_size, settings_size;
     uint8_t *id, *settings;
+    if (pkt->stream_index != 0)
+        return 0;
     avio_printf(pb, "\n");
     id = av_packet_get_side_data(pkt, AV_PKT_DATA_WEBVTT_IDENTIFIER,