Trouble adding multiple subtitle tracks to HLS variant stream

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Trouble adding multiple subtitle tracks to HLS variant stream

Michael Hwang
Hi all,

I'm trying to convert a video into two HLS streams. This file has one
video track, one audio track, and seven subtitle tracks, only three of
which I am interested in.

The resulting HLS streams will be a "high quality" and "standard
quality" video stream, which, through the magic of var_stream_map, use
the same audio track. These streams are played back via a hls.js-based

Here is the call to ffmpeg to produce the two streams, sans subtitles:

ffmpeg -i "input_file.mkv" \
-map '[hd]' -c:v:0 libx264 -b:v:0 3800k \
-map '[sd]' -c:v:1 libx264 -b:v:1 2000k \
-map 0:1 -c:a:0 aac -b:a:0 192k -ac 2 \
-var_stream_map "a:0,agroup:audio v:0,agroup:audio v:1,agroup:audio" \
-f hls -master_pl_name master.m3u8 -hls_time 4 -hls_list_size 0
-hls_segment_type fmp4 -hls_segment_filename "live_%v_%04d.ts"

If I want to add subtitles, I have to first convert them to webvtt by adding:

-map '0:2' -c:s:0 webvtt \
-map '0:3' -c:s:1 webvtt \
-map '0:4' -c:s:2 webvtt

However, I'm not sure how to add my subtitles to the variant stream map.

I assumed at first that I could use "sgroup" in the same manner as "agroup":

-var_stream_map "a:0,agroup:audio s:0,sgroup:subtitle
s:1,sgroup:subtitle s:2,sgroup:subtitle
v:0,agroup:audio,sgroup:subtitle v:1,agroup:audio,sgroup:subtitle"

However, I get this error:

>No streams to mux were specified
>Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
>Error initializing output stream 0:1 --

So it seems like s: cannot be alone in its own variant stream.

If I drop the third subtitle track, I can get the first two to show up
properly in master.m3u8 like this:

-var_stream_map "a:0,agroup:audio

But of course this limits me to only as many subtitle tracks as I have
video streams.

Does anyone know what var_stream_map syntax I should use to get my
third subtitle track to show up?



(I'm using a static ffmpeg build; here's the version info:)

ffmpeg version N-54088-gb0203fa72b-static  Copyright (c) 2000-2020 the FFmpeg
built with gcc 8 (Debian 8.3.0-6)
configuration: --enable-gpl --enable-version3 --enable-static
--disable-debug --disable-ffplay --disable-indev=sndio
--disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r
--enable-gnutls --enable-gmp --enable-libgme --enable-gray
--enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf
--enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband
--enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis
--enable-libopus --enable-libtheora --enable-libvidstab
--enable-libvo-amrwbenc --enable-libvpx --enable-libwebp
--enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d
--enable-libxvid --enable-libzvbi --enable-libzimg
libavutil      56. 58.100 / 56. 58.100
libavcodec     58.105.100 / 58.105.100
libavformat    58. 54.100 / 58. 54.100
libavdevice    58. 11.101 / 58. 11.101
libavfilter     7. 87.100 /  7. 87.100
libswscale      5.  8.100 /  5.  8.100
libswresample   3.  8.100 /  3.  8.100
libpostproc    55.  8.100 / 55.  8.100
ffmpeg-user mailing list
[hidden email]

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".