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
Unified · Split
| @@ -2293,6 +2293,7 @@ static int hls_write_header(AVFormatContext *s) · 2292 unmodified lines | |||
| 2293 | VariantStream *vs = NULL; | 2293 | VariantStream *vs = NULL; |
| 2294 | 2294 | ||
| 2295 | for (i = 0; i < hls->nb_varstreams; i++) { | 2295 | for (i = 0; i < hls->nb_varstreams; i++) { |
| 2296 | int subtitle_streams = 0; | ||
| 2296 | vs = &hls->var_streams[i]; | 2297 | vs = &hls->var_streams[i]; |
| 2297 | 2298 | ||
| 2298 | ret = avformat_write_header(vs->avf, NULL); | 2299 | ret = avformat_write_header(vs->avf, NULL); |
| @@ -2313,10 +2314,11 @@ static int hls_write_header(AVFormatContext *s) · 14 unmodified lines | |||
| 2313 | } | 2314 | } |
| 2314 | 2315 | ||
| 2315 | if (outer_st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) | 2316 | if (outer_st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) |
| 2316 | inner_st = vs->avf->streams[j]; | 2317 | inner_st = vs->avf->streams[j - subtitle_streams]; |
| 2317 | else if (vs->vtt_avf) | 2318 | else if (vs->vtt_avf) { |
| 2318 | inner_st = vs->vtt_avf->streams[0]; | 2319 | inner_st = vs->vtt_avf->streams[0]; |
| 2319 | else { | 2320 | subtitle_streams++; |
| 2321 | } else { | ||
| 2320 | /* We have a subtitle stream, when the user does not want one */ | 2322 | /* We have a subtitle stream, when the user does not want one */ |
| 2321 | inner_st = NULL; | 2323 | inner_st = NULL; |
| 2322 | continue; | 2324 | continue; |
| @@ -2403,6 +2405,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) · 80 unmodified lines | |||
| 2403 | int is_ref_pkt = 1; | 2405 | int is_ref_pkt = 1; |
| 2404 | int ret = 0, can_split = 1, i, j; | 2406 | int ret = 0, can_split = 1, i, j; |
| 2405 | int stream_index = 0; | 2407 | int stream_index = 0; |
| 2408 | int subtitle_streams = 0; | ||
| 2406 | int range_length = 0; | 2409 | int range_length = 0; |
| 2407 | const char *proto = NULL; | 2410 | const char *proto = NULL; |
| 2408 | int use_temp_file = 0; | 2411 | int use_temp_file = 0; |
| @@ -2412,13 +2415,16 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) · 3 unmodified lines | |||
| 2412 | for (i = 0; i < hls->nb_varstreams; i++) { | 2415 | for (i = 0; i < hls->nb_varstreams; i++) { |
| 2413 | vs = &hls->var_streams[i]; | 2416 | vs = &hls->var_streams[i]; |
| 2414 | for (j = 0; j < vs->nb_streams; j++) { | 2417 | for (j = 0; j < vs->nb_streams; j++) { |
| 2418 | if (vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { | ||
| 2419 | subtitle_streams++; | ||
| 2420 | } | ||
| 2415 | if (vs->streams[j] == st) { | 2421 | if (vs->streams[j] == st) { |
| 2416 | if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { | 2422 | if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { |
| 2417 | oc = vs->vtt_avf; | 2423 | oc = vs->vtt_avf; |
| 2418 | stream_index = 0; | 2424 | stream_index = 0; |
| 2419 | } else { | 2425 | } else { |
| 2420 | oc = vs->avf; | 2426 | oc = vs->avf; |
| 2421 | stream_index = j; | 2427 | stream_index = j - subtitle_streams; |
| 2422 | } | 2428 | } |
| 2423 | break; | 2429 | break; |
| 2424 | } | 2430 | } |
| @@ -2647,7 +2653,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) · 222 unmodified lines | |||
| 2647 | if (ret < 0) { | 2653 | if (ret < 0) { |
| 2648 | return ret; | 2654 | return ret; |
| 2649 | } | 2655 | } |
| 2650 | |||
| 2651 | } | 2656 | } |
| 2652 | 2657 | ||
| 2653 | vs->packets_written++; | 2658 | vs->packets_written++; |