0

I'm having video streams containing two audio streams (stereo and surround) like this:

Input #0, mpegts, from 'my-stream.ts':
  Duration: 00:59:58.72, start: 26.658667, bitrate: 8013 kb/s
  Program 1 
    Metadata:
      service_provider: FFmpeg
  Stream #0:0[0x100](deu): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 129 kb/s
  Stream #0:1[0x101](deu): Audio: eac3 (EAC3 / 0x33434145), 48000 Hz, 5.1(side), fltp, 256 kb/s
  Stream #0:2[0x102]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn

Now I'm trying to convert the streams into HLS so it can by played on an android with ExoPlayer and the user can choose between the audio streams (means if the user hits the gear button on the bottom right, both audio streams are offered to select between).

I've tried to convert it with a command like this:

ffmpeg -i my-stream.ts   -map 0:v:0 -map 0:a:0 -map 0:a:1   -codec:v copy   -codec:a copy   -f hls   -hls_time 5   -hls_list_size 0   -hls_segment_filename "segment_%03d.ts"   -master_pl_name "master.m3u8"   -var_stream_map "v:0,a:0 v:0,a:1"   -hls_flags independent_segments   stream_%v.m3u8

but it fails with error

Same elementary stream found more than once in two different variant definitions #0 and #1

I must admit that I have absolutely no idea what all that does, hence I don't know where to go from here.

How to properly create the playlist?

Destroy666
  • 12,350

2 Answers2

0

As the error says, you are using the same video stream in 2 variants, which ffmpeg doesn't like:

-var_stream_map "v:0,a:0 v:0,a:1"

It needs to be 2 different streams:

-var_stream_map "v:0,a:0 v:1,a:1"

And then the mappings need to reflect it:

-map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:1

First pair is for stream 0 (with video stream 0 and audio stream 0), second for stream 1 (with video stream 0 and audio stream 1).

Also:

When var_stream_map is set with two or more variant streams, the filename pattern must contain the string "%v", and this string will be expanded to the position of variant stream index in the generated segment file names

So %v needs to be in segment filename as well.

See also -hls docs for all the options described in detail.

Destroy666
  • 12,350
0

For the records, although this might be off-topic: I found a solution how to create hls streams for playback with ExoPlayer:

ffmpeg -i my-stream.ts \
  -map 0:v:0 -codec:v copy -f hls \
  -hls_time 5 -hls_list_size 0 -hls_flags independent_segments \
  -hls_segment_filename "video_%03d.ts" video.m3u8 \
  -map 0:a:0 -codec:a copy -f hls \
  -hls_time 5 -hls_list_size 0 -hls_flags independent_segments \
  -hls_segment_filename "audio_stereo_%03d.ts" audio_stereo.m3u8 \
  -map 0:a:1 -codec:a copy -f hls \
  -hls_time 5 -hls_list_size 0 -hls_flags independent_segments \
  -hls_segment_filename "audio_dolby_%03d.ts" audio_dolby.m3u8

Unfortunatelly, there is no "master.m3u8" being created, which is needed for ExoPlayer to find streams. Correct me if I'm wrong. Otherwise, it needs to be created manually and may look similar to this:

#EXTM3U
#EXT-X-VERSION:3

Video stream

#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=1920x1080,AUDIO="audio" video.m3u8

Audio streams

#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="Stereo",DEFAULT=YES,AUTOSELECT=YES,URI="audio_stereo.m3u8" #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="DolbySurround",DEFAULT=NO,AUTOSELECT=YES,URI="audio_dolby.m3u8"

Now, when feeding master.m3u8 to ExoPlayer it will let you select between the audio tracks.