During the time a series of articles regarding using FFmpeg as a HLS streaming server has been published. This article is an overview on all published articles:
- Using FFmpeg as a HLS streaming server (Part 1) – HLS Basics
- Using FFmpeg as a HLS streaming server (Part 2) – Enhanced HLS Segmentation
- Using FFmpeg as a HLS streaming server (Part 3) – Multiple Bitrates
- Using FFmpeg as a HLS streaming server (Part 4) – Multiple Video Resolutions
- Using FFmpeg as a HLS streaming server (Part 5) – Folder Structure
- Using FFmpeg as a HLS streaming server (Part 6) – Independent Segments
- Using FFmpeg as a HLS streaming server (Part 7) – Fixing Peak Bitrate
- Using FFmpeg as a HLS streaming server (Part 8) – Reducing delay
- Using FFmpeg as a HLS streaming server (Part 9) – Multiple Audio Languages
Also helpful articles related are:
Hi Martin,
thank you for this documentation an the explainations, it has helped me very much.
Is there a way to secure the server side, so that only authorized partys can stream to the rtmp server? I want to prevent that anyone but me can stream to the server while it’s running.
I thought of using a cryptic/complex application name as a a safety measure.
But when I use a different (incorrect) application name in OBS, ffmpeg only throws a warning and tells me that it expected a different name, but it still accepts the stream.
Could this check be enforced to fail in that case?
I checked the ffmpeg documentation and streaming guide, but couldn’t find anythig.
In the meantime, as a workaround, I secured the port on the operating system with the local firewall so only connections from whitelisted IPs get accepted.
Best regards
thomas
Hi Thomas,
Typically stream keys are used for securing the connection (like youtube live or twitch). Just add a second parameter to the URL like rtmp://martin-riedl.de/stream01/mysecretkey
This secret key must the be sent correctly from OBS otherwise the connection is refused from FFmpeg.
It’s documented here:
https://ffmpeg.org/ffmpeg-all.html#rtmp
There is also a second option (never used it myself):
Username and password in the URL (see documentation linked above).
Thanks for the great information!
What might be my complete misunderstanding of HLS is what’s the right way of cleaning up old segments and the m3u8 playlist? Say I want to only keep the last hour or day around?
My application is moving from YT live streaming of an older 1080p H.264 camera to a newer 34k with H.265 and YT only support HLS and DASH for this. With RTSP -> RTMP this was simple.
The parameter hls_playlist_type tells FFmpeg to keep all old segments. Remove this parameter to keep only the last few segments. By default FFmpeg keeps 5 segments. You can also change this with the parameter
hls_list_size: Set the maximum number of playlist entries. If set to 0 the list file will contain all the segments. Default value is 5.
https://ffmpeg.org/ffmpeg-all.html#Options-44
Hallo Martin,
danke für die sehr ausführliche Beschreibung.
Ich nutze folgende Codezeile um einen Kamerastream für OBS aufzusplitten um eine Replay-Funktion nutzen zu können:
ffmpeg -f dshow \
-i video=”HD Web Camera”:audio=”Mikrofon (HD Web Camera)” \
-preset superfast -f mpegts -flush_packets 0 \
-udp://192.168.95.210:5001 \
-hls_wrap 6 -hls_segment_filename -hls_playlist_type \
VideosCam01\Camera_1_%03d.ts -y \
VideosCam01\Camera_1.m3u8 -y
Was müsste ich ergänzen, um zusätzlich ein “Short-Replay”, also nur die letzten 5 Minuten aufzuzeichnen?
Viele Grüße
Hallo Martin.
Everything is great, everything works, but!
If you make an HSL broadcast from an rtsp stream, then ffplay, mpv, potPlayer cannot rewind to the beginning of the broadcast. It is possible to watch only in Live mode. vlc can rewind freely. But I can’t start vlc so that it starts watching from the beginning of the broadcast.