History

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

Steven Liu committed 5 years ago

Commit c64d56a1 parent 5dc1b4b1 file · +10 −5Browse files

Unified · Split

libavformat/hlsenc.c+10−5
@@ -2293,6 +2293,7 @@ static int hls_write_header(AVFormatContext *s) · 2292 unmodified lines
22932293 VariantStream *vs = NULL;
22942294
22952295 for (i = 0; i < hls->nb_varstreams; i++) {
2296+ int subtitle_streams = 0;
22962297 vs = &hls->var_streams[i];
22972298
22982299 ret = avformat_write_header(vs->avf, NULL);
@@ -2313,10 +2314,11 @@ static int hls_write_header(AVFormatContext *s) · 14 unmodified lines
23132314 }
23142315
23152316 if (outer_st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE)
2316− inner_st = vs->avf->streams[j];
2317− else if (vs->vtt_avf)
2317+ inner_st = vs->avf->streams[j - subtitle_streams];
2318+ else if (vs->vtt_avf) {
23182319 inner_st = vs->vtt_avf->streams[0];
2319− else {
2320+ subtitle_streams++;
2321+ } else {
23202322 /* We have a subtitle stream, when the user does not want one */
23212323 inner_st = NULL;
23222324 continue;
@@ -2403,6 +2405,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) · 80 unmodified lines
24032405 int is_ref_pkt = 1;
24042406 int ret = 0, can_split = 1, i, j;
24052407 int stream_index = 0;
2408+ int subtitle_streams = 0;
24062409 int range_length = 0;
24072410 const char *proto = NULL;
24082411 int use_temp_file = 0;
@@ -2412,13 +2415,16 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) · 3 unmodified lines
24122415 for (i = 0; i < hls->nb_varstreams; i++) {
24132416 vs = &hls->var_streams[i];
24142417 for (j = 0; j < vs->nb_streams; j++) {
2418+ if (vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2419+ subtitle_streams++;
2420+ }
24152421 if (vs->streams[j] == st) {
24162422 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
24172423 oc = vs->vtt_avf;
24182424 stream_index = 0;
24192425 } else {
24202426 oc = vs->avf;
2421− stream_index = j;
2427+ stream_index = j - subtitle_streams;
24222428 }
24232429 break;
24242430 }
@@ -2647,7 +2653,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) · 222 unmodified lines
26472653 if (ret < 0) {
26482654 return ret;
26492655 }
2650−
26512656 }
26522657
26532658 vs->packets_written++;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t