How to generate multiple resolutions HLS using FFmpeg for live streaming [closed]
Asked Answered
C

1

9

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
Crossindex answered 18/4, 2022 at 15:6 Comment(0)
O
17

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.

One answered 24/4, 2022 at 3:51 Comment(3)
Hi, The stream file generated on SRS - ffmpeg, doesn't support to play on iOS Safari. live.indiefire.io/romchos/name-480p.m3u8 this is made using SRS-ffmpeg according to the guide. This stream is working for Windows Chrome. prnt.sc/72MAxMUqxP2o This stream isn't working for iPhone Safari. prnt.sc/X5bwPYBgVQ21 You can simply check it by livepush.io/hls-player/index.htmlChewink
would you like to answer to this question? is it related with srs.conf? #76650296Chewink
@Chewink Alright, I have answered it.One

© 2022 - 2024 — McMap. All rights reserved.