7

Note that SRS supports generating individual m3u8 file for a specific resolution. Does SRS also support generating an additional master m3u8 file for the multiple resolutions and bitrate scenario?

Desired master m3u8 example:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=2340800,RESOLUTION=960x540,CODECS=“avc1.4d401f,mp4a.40.2”
index_0.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1170400,RESOLUTION=480x270,CODECS=“avc1.4d4015,mp4a.40.2"
index_1.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=677600,RESOLUTION=480x270,CODECS=“avc1.4d4015,mp4a.40.2”
index_2.m3u8
gforce07
  • 83
  • 1
  • 5

1 Answers1

11

Please use FFmpeg to generate the multiple HLS:

ffmpeg -f flv -i "rtmp://server/live/livestream" \
  -map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 \
  -c:v libx264 -crf 22 -c:a aac -ar 44100 \
  -filter:v:0 scale=w=480:h=360  -maxrate:v:0 600k -b:a:0 500k \
  -filter:v:1 scale=w=640:h=480  -maxrate:v:1 1500k -b:a:1 1000k \
  -filter:v:2 scale=w=1280:h=720 -maxrate:v:2 3000k -b:a:2 2000k \
  -var_stream_map "v:0,a:0,name:360p v:1,a:1,name:480p v:2,a:2,name:720p" \
  -preset fast -hls_list_size 10 -threads 0 -f hls \
  -hls_time 3 -hls_flags independent_segments \
  -master_pl_name "livestream.m3u8" \
  -y "livestream-%v.m3u8"

Note: Rather than converting RTMP to HLS by multiple FFmpeg processes, you should use filters in one FFmpeg process. And FFmpeg keeps the multiple resolutions to gop aligned, to allow user to switch between different streams.

The master m3u8, generated by FFmpeg:

#EXTM3U
#EXT-X-VERSION:6
#EXT-X-STREAM-INF:BANDWIDTH=1210000,RESOLUTION=480x360,CODECS="avc1.640015,mp4a.40.2"
livestream-360p.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=2283600,RESOLUTION=640x480,CODECS="avc1.64001e,mp4a.40.2"
livestream-480p.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=3933600,RESOLUTION=1280x720,CODECS="avc1.64001f,mp4a.40.2"
livestream-720p.m3u8

For detail please read here.

Winlin
  • 1,136
  • 6
  • 25
  • Hi, The stream file generated on SRS - ffmpeg, doesn't support to play on iOS Safari. https://live.indiefire.io/romchos/name-480p.m3u8 this is made using SRS-ffmpeg according to the guide. This stream is working for Windows Chrome. https://prnt.sc/72MAxMUqxP2o This stream isn't working for iPhone Safari. https://prnt.sc/X5bwPYBgVQ21 You can simply check it by https://livepush.io/hls-player/index.html – persec10000 Jul 14 '23 at 11:17
  • would you like to answer to this question? is it related with srs.conf? https://stackoverflow.com/questions/76649796/the-m3u8-files-created-by-srs-wont-play-in-only-ios-safari-but-other-m3u8-file – persec10000 Jul 14 '23 at 11:20
  • @persec10000 Alright, I have answered it. – Winlin Jul 16 '23 at 01:50