- Introduction to Video
- Stream video files
- Start live streaming
- Configure broadcast software
- Live streaming from your app
- Reduce live stream latency
- Manage Stream Keys
- Stream recordings of live streams
- Live streaming FAQs
- Stream live to 3rd party platforms
- Use a custom domain for live streaming
- Handle live stream disconnects
- Stream simulated live
- Debug live stream issues
- Add live captions
- Make API requests
- Play your videos
- Enable static MP4 renditions
- Download for offline editing
- Embed videos for social media
- Listen for webhooks
- Secure video playback
- Create clips from your videos
- Get images from a video
- Create timeline hover previews
- Adjust audio levels
- Add watermarks to your videos
- Add subtitles to your videos
- Minimize processing time
- Upload files directly
- Autoplay your videos
- Stream an audio-only version of your video
- Synchronize video playback
- Integrate with your CMS
Handle Live Stream Disconnects
In this guide we will walk through how to handle disconnects that happen during live streams.
In this guide:
How Mux handles disconnects
How Mux handles disconnects
How to handle reconnects from the Player/Client side
How to handle reconnects from the Player/Client side
Understand what happens to the encoder based on the reconnect_window parameter
Reconnect windows and reduced latency
Reconnect windows and reduced latency
Why reconnect windows are disabled
Before reading this guide, you created and set up a Live Stream by following these steps:
- You have connected your encoder (for example OBS, Wirecast, your live streaming app) to an RTMP ingest server as covered in this guide: Configure Broadcast Software).
- Mux sends the
video.live_stream.connected
event to your environment. - When the encoder starts sending media to the ingest server, the webhook events
video.live_stream.recording
and thenvideo.live_stream.active
are delivered to your environment.
If everything goes smoothly, the encoder will keep sending media and the server will keep processing it, creating video segments and updating the HLS playlists with new pieces of video (to understand in a how this works read Reduce live stream latency). Since all of this streaming is happening live, the ingest server needs to know what it should do when the encoder disconnects unexpectedly.
What happens when the live stream disconnects either intentionally or due to a drop in the network? Mux sends the video.live_stream.disconnected
event for the live stream to your environment. This is where the reconnect_window
comes into play.
Reconnect windows
When you create a Mux Live Stream assetAPI, the live stream object keys include a parameter called reconnect_window
in the Request JSON.
The Reconnect Window is the time in seconds that Mux should wait for the streaming software to reconnect before considering the live stream finished and completing the recorded asset. As a default, Mux sets reconnect_window
to 60 seconds, but this can be adjusted to any value between 0.1 to 300 seconds.
When a live stream disconnects, outcome depends on whether the encoder can reconnect before the reconnect window expires. There are two possible scenarios.
In scenario 1, the encoder re-connects
The ingest server will wait for the duration of the reconnect_window
before it ends the live stream. While the encoder is disconnected, media is no longer being sent, so the HLS playlists are not getting new segments of video.
Stalled player during live stream
A stalled player during a live stream happens when the live stream is still active, but the HLS manifest file is not getting new video segments appended to it.
The player will enter a stalled
state if it runs out of buffer. To avoid this, consider adding extra buffer to your player.
If the encoder reconnects before the reconnect_window
expires then the HLS playlist will resume appending new video segments to the live stream.
In scenario 2, the Encoder expires
The following events will occur when the reconnect window expires:
Mux writes an
EXT-X-ENDLIST
tag to the HLS playlist. According to the HLS specification: EXT-X-ENDLIST: Indicates that no more media files will be added to the playlist file. This tells the player this stream is over and no more media is coming. Your player should emit anended
event, or something equivalent.The live stream will transition from
active
back toidle
Mux will create a new asset. The
active_asset_id
while the live stream was active will be finalized. If the same live stream goes live again at a later time, then the live stream will get a newactive_asset_id
and a new asset will be created.
When streaming either with reduced_latency
or low_latency
BETA on your live stream, reconnect windows are automatically disabled. This means that as soon as a disconnect happens the HLS playlist will be ended with the EXT-X-ENDLIST
tag and the asset will be finalized. If a reconnect happens after that, you will need to reload the source in your player and Mux will start creating a new asset.
If you are using lower latency options this is one of the tradeoffs to consider. Read more in the Live Stream Latency Guide about Reduced and Low Latency.