FFMPEG:Convert RTSP live stream to HLS

If you want to display a RTSP Live stream into a browser in linux, you can do so by transcoding it to HLS. You can use ffmpeg in order to do that.

To convert the RTSP live stream into hls the command is

$ ffmpeg -fflags nobuffer \
 -rtsp_transport tcp \
 -i <your rtsp url>\
 -vsync 0 \
 -copyts \
 -vcodec copy \
 -movflags frag_keyframe+empty_moov \
 -an \
 -hls_flags delete_segments+append_list \
 -f segment \
 -segment_list_flags live \
 -segment_time 0.5 \
 -segment_list_size 1 \
 -segment_format mpegts \
 -segment_list <output directory>/index.m3u8 \
 -segment_list_type m3u8 \
 -segment_list_entry_prefix <output directory>/ \
 <output directory>/%3d.ts

After running this command you will find the index.m3u8 file along with multiple .ts (segment files) in the output directory that you specify in the command.

In this the index.m3u8 is the playlis file and .ts files are the fragments. You need to serve these files using any http server. I used goof for this.

To display this video in a browoser, you need to include this index.m3u8 file in the video tag in your html page, for example.

<video id="video-player" controls preload="none">
    <source src="/output-directory/index.m3u8" type="application/x-mpegURL">
</video>

Once this is done, navigate to the html page from your browser, you will be able to see the live stream on linux without using any flash plugin.

References: