diff options
author | Steven Liu <liuqi05@kuaishou.com> | 2021-07-20 20:07:36 +0800 |
---|---|---|
committer | Steven Liu <lq@chinaffmpeg.org> | 2021-08-19 18:24:15 +0800 |
commit | c64d56a2f53455f803456811873ff08fce98e122 (patch) | |
tree | d9cce5153284ffcc7c7dff9e8796fd844c611275 /libavformat/hlsenc.c | |
parent | 5dc1b4b9979c84efc3b81bcb2c244e71e22a951a (diff) | |
download | ffmpeg-c64d56a2f53455f803456811873ff08fce98e122.tar.gz |
avformat/hlsenc: minus subtitle streams count when subtitle stream between video and audio streams
because subtitles streams will be written to webvtt m3u8 list
so the stream index should minus subtitles streams count when subtitle
between audio and video streams.
testcase:
before patch:
ffmpeg -i input -map 0:a:0 -map 0:s:0 -map 0:v:0 -f hls aaaa.m3u8
will EXC_BAD_ACCESS
after patch:
ffmpeg -i input -map 0:a:0 -map 0:s:0 -map 0:v:0 -f hls aaaa.m3u8
will ok
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
Diffstat (limited to 'libavformat/hlsenc.c')
-rw-r--r-- | libavformat/hlsenc.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 8cd938eb97..7c37bc50b9 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2293,6 +2293,7 @@ static int hls_write_header(AVFormatContext *s) VariantStream *vs = NULL; for (i = 0; i < hls->nb_varstreams; i++) { + int subtitle_streams = 0; vs = &hls->var_streams[i]; ret = avformat_write_header(vs->avf, NULL); @@ -2313,10 +2314,11 @@ static int hls_write_header(AVFormatContext *s) } if (outer_st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) - inner_st = vs->avf->streams[j]; - else if (vs->vtt_avf) + inner_st = vs->avf->streams[j - subtitle_streams]; + else if (vs->vtt_avf) { inner_st = vs->vtt_avf->streams[0]; - else { + subtitle_streams++; + } else { /* We have a subtitle stream, when the user does not want one */ inner_st = NULL; continue; @@ -2403,6 +2405,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) int is_ref_pkt = 1; int ret = 0, can_split = 1, i, j; int stream_index = 0; + int subtitle_streams = 0; int range_length = 0; const char *proto = NULL; int use_temp_file = 0; @@ -2412,13 +2415,16 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) for (i = 0; i < hls->nb_varstreams; i++) { vs = &hls->var_streams[i]; for (j = 0; j < vs->nb_streams; j++) { + if (vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { + subtitle_streams++; + } if (vs->streams[j] == st) { if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { oc = vs->vtt_avf; stream_index = 0; } else { oc = vs->avf; - stream_index = j; + stream_index = j - subtitle_streams; } break; } @@ -2647,7 +2653,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) { return ret; } - } vs->packets_written++; |