Hello,

Its regarding ticket #5067(avformat:open): crash on Mapping Multicast TV Stream to HLS with "Exactly one WebVTT stream is needed" as message

I have attached patch for hls not failing in condition where subtitles streams are of bitmap type and ts containing data streams mapped to output.

But this patch have side effect, that user is not warned that stream that are shown as mapped in logs are actually ignored by hls segmeter.

I have not added errors/warning about ignoring streams, since I was unable to decide whether they should be warning or error.

Thanks
Anshul Maheshwari

>From e266babd729f1ed90c8956090f9e9658c85e13a9 Mon Sep 17 00:00:00 2001
From: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
Date: Sun, 13 Dec 2015 20:45:02 +0530
Subject: [PATCH] hls supports only webVTT as subtitles

Signed-off-by: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
---
 libavformat/hlsenc.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index adcf7df..0bbea39 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -285,10 +285,13 @@ static int hls_mux_init(AVFormatContext *s)
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st;
         AVFormatContext *loc;
-        if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE)
+        if (s->streams[i]->codec->codec_id == AV_CODEC_ID_WEBVTT)
             loc = vtt_oc;
-        else
+        else if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
+            s->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
             loc = oc;
+        else
+            continue;
 
         if (!(st = avformat_new_stream(loc, NULL)))
             return AVERROR(ENOMEM);
@@ -612,7 +615,7 @@ static int hls_write_header(AVFormatContext *s)
         hls->has_video +=
             s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO;
         hls->has_subtitle +=
-            s->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE;
+            s->streams[i]->codec->codec_id == AV_CODEC_ID_WEBVTT;
     }
 
     if (hls->has_video > 1)
@@ -714,10 +717,11 @@ static int hls_write_header(AVFormatContext *s)
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *inner_st;
         AVStream *outer_st = s->streams[i];
-        if (outer_st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE)
-            inner_st = hls->avf->streams[i];
-        else if (hls->vtt_avf)
+        if (hls->vtt_avf && outer_st->codec->codec_id == AV_CODEC_ID_WEBVTT)
             inner_st = hls->vtt_avf->streams[0];
+        else if(outer_st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
+               outer_st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
+            inner_st = hls->avf->streams[i];
         else {
             /* We have a subtitle stream, when the user does not want one */
             inner_st = NULL;
@@ -750,13 +754,17 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
     int ret, can_split = 1;
     int stream_index = 0;
 
-    if( st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE ) {
+    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
+       st->codec->codec_type == AVMEDIA_TYPE_AUDIO ) {
+        oc = hls->avf;
+        stream_index = pkt->stream_index;
+    } else if( hls->vtt_avf && st->codec->codec_id == AV_CODEC_ID_WEBVTT) {
         oc = hls->vtt_avf;
         stream_index = 0;
     } else {
-        oc = hls->avf;
-        stream_index = pkt->stream_index;
+	return 0;
     }
+
     if (hls->start_pts == AV_NOPTS_VALUE) {
         hls->start_pts = pkt->pts;
         hls->end_pts   = pkt->pts;
-- 
2.1.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to