@@ -1202,6 +1202,22 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,
return 0;
}
+static int extract_number(const char *filename) {
+ const char *dot = strrchr(filename, '.');
+ const char *num_start = dot - 1;
+
+ while (num_start > filename && *num_start >= '0' && *num_start <= '9') {
+ num_start--;
+ }
+
+ num_start++;
+
+ if (num_start == dot)
+ return -1;
+
+ return atoi(num_start);
+}
+
static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs)
{
HLSContext *hls = s->priv_data;
@@ -1294,6 +1310,27 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs
ret = AVERROR(ENOMEM);
goto fail;
}
+ if (vs->has_subtitle) {
+ int vtt_index = extract_number(line);
+ char *vtt_file = av_asprintf(av_basename(vs->vtt_basename), vtt_index);
+ char *new_vtt;
+
+ if (!vtt_file) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ new_vtt = av_strdup(vtt_file);
+ av_free(vtt_file);
+
+ if (!new_vtt) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ ff_format_set_url(vs->vtt_avf, new_vtt);
+ }
+
ff_format_set_url(vs->avf, new_file);
is_segment = 0;
new_start_pos = avio_tell(vs->avf->pb);