Search code examples
http-live-streaminglive-streamingsimple-realtime-server

DVR RTMP Stream into HLS (m3u8) in SRS


For SRS SaaS, DRV output are HLS (m3u8), mentioned at here https://github.com/ossrs/srs/issues/2856 and here: https://mp.weixin.qq.com/s/UXR5EBKZ-LnthwKN_rlIjg.

Same idea also discussed recently https://www.bilibili.com/video/BV1234y1b7Pv?spm_id_from=333.999.0.0 At around timestamp 9:50, mentioned that, for SRS SaaS, DRV output are HLS (m3u8).

Question: can we also DVR RTMP Stream into HLS (m3u8) in SRS , as only mp4 and flv options are discussed in wiki https://github.com/ossrs/srs/wiki/v4_EN_DVR


Solution

  • The answer is SRS supports DVR to FLV/MP4 file, and you could also use HLS as DVR, because what DVR does is to covert RTMP to file such as FLV/MP4/HLS.

    If you only want to get a record file of live streaming, you could simply use the DVR of SRS, you will see a variety of files is generated. It works like this:

    OBS --RTMP--> SRS --DVR--> FLV/MP4 file
    

    But you could also use HLS to DVR the live stream, and it's more complex and powerful way. For example, if you stop publishing, adjust the params of encoder or just change one, then continue publishing, how to DVR it to one file?

    If you use DVR of SRS, you will get multiple files, because each stream is covert to a file, and DVR will start a new file when another publishing starts.

    If you use HLS, you need to write a backend server, and you will get the on_hls callback, you could determine writing to previous m3u8 or start a new one, it's controlled by your backend server, and because you must write a backend server so it's more complex. It works like this:

    OBS --RTMP--> SRS --HLS--> m3u8/ts file
                   +
                   +--on-hls---------> Your Backend Server
                     (HTTP Callback)
    

    There is an example about how to use HLS to covert RTMP to a VoD file, please read srs-cloud for detail.