Convert RTSP to HLS using FFmpeg

Kelp
Kelp
Apr 26, 2018 · 2 min read

If you want to play the streaming on iOS devices. You should use HTTP Live Streaming (HLS). HLS is the only one way to play the streaming for iOS.

FFmpeg supports convert the RTSP streaming to HLS. FFmpeg calls it “segment”. This is a document about segment arguments.
https://www.ffmpeg.org/ffmpeg-formats.html#segment_002c-stream_005fsegment_002c-ssegment

ffmpeg -fflags nobuffer \
-rtsp_transport tcp \
-i rtsp://your-rtsp-server:8554/CH001.sdp \
-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 1 \
-segment_list_size 3 \
-segment_format mpegts \
-segment_list /tmp/stream/index.m3u8 \
-segment_list_type m3u8 \
-segment_list_entry_prefix /stream/ \
/tmp/stream/%d.ts
FFmpeg will generate index.m3u8, 1.ts, 2.ts,3.ts, ….
index.m3u8 is a list file. It will tell the player what files should be downloaded and played.

Then you should start your server(express or gin) let the browser can access files.

Set the src attribute of <video> in your html file.

<video id="video-player" controls preload="none">
<source src="/stream/index.m3u8" type="application/x-mpegURL">
</video>
You can play the streaming on the Safari of iOS devices.

androvideo

Andro Video

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store