- 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 your own live captions
- Add auto-generated live captions
- Build real-time video experiences
- 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
- 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
Learn more about Reconnect Window and how to add a slate image
How to handle reconnects from the Player/Client side without a slate image
How to handle reconnects from the Player/Client side without a slate image
Understand what happens to the encoder based on the reconnect_window parameter
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 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 Window
When you create the Live StreamAPI or update the Live StreamAPI, you can set the reconnect_window
parameter in the Request JSON.
The Reconnect Window is the time in seconds that Mux should wait for the live stream broadcasting 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 to 1800 seconds.
Reconnect Window and slates
When you create the Live StreamAPI or update the Live StreamAPI,
you can set the reconnect_slate_url
BETA parameter with the URL of the slate image.
When Mux stops receiving the media, Mux adds the slate image as a video frame to the live stream. This event of not receiving media disconnects the encoder and starts the reconnect_window
time interval.
Mux stops adding the slate image when Mux starts receiving media again or the reconnect window time interval expires.
Enable slates for standard
, reduced
, and low
BETA latency mode live streams:
- For
standard
latency live streams, set theuse_slate_for_standard_latency
BETA parameter totrue
and make sure thereconnect_window
parameter value is greater than 0s. Live streams, created before the slate image functionality was available, will not automatically start using slates until this parameter is set. - For
reduced
andlow
BETA latency mode live streams, set thereconnect_window
parameter value to greater than 0s.
Mux selects one of the following images as the default slate image depending on the live stream's video aspect ratio. The default slate image is used unless you
set the reconnect_slate_url
BETA parameter. We recommended setting the slate image whose aspect ratio matches the live stream's video aspect ratio. You can modify
the reconnect_slate_url
BETA parameter using the update the Live StreamAPI.
Mux downloads the slate image, hosted at the URL set as reconnect_slate_url
BETA parameter value, at the start of the live stream recording.
So, you must ensure the image is always downloadable from the URL. When Mux can not download the image, the image show above is used as the slate image and
the video.live_stream.warning
webhook event is fired. Below is an example of the video.live_stream.warning
webhook event body:
{ "type": "video.live_stream.warning", "object": { "type": "live", "id": "CiinCsHA2EbsU00XwzherzjWAek3VmtUz8" }, "id": "3a56ac3d-33da-4366-855b-f592d898409d", "environment": { "name": "Production", "id": "j0863n" }, "data": { "warning": { "type": "custom_slate_unavailable", "message": "Unable to download custom reconnect slate image from URL 'http://example.com/bad_url.png' -- using black frames for slate if needed." }, "stream_key": "5203dc64-074a-5914-0dfc-ce007f5db53a", "status": "idle", "id": "CiinCsHA2EbsU00XwzherzjWAek3VmtUz8", "active_asset_id": "0201p02fGKPE7MrbC269XRD7LpcHhrmbu0002" }, "created_at": "2022-07-14T21:08:27.000000Z", "accessor_source": null, "accessor": null, "request_id": null }
When Mux is not receiving any media, the viewer experience depends on whether Mux starts receiving media before the reconnect window expires. We strongly recommend updating the Live StreamAPI to add a slate image. However, there are two possible scenarios when you do not want to add the slate image.
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 disconnects
If the encoder does not reconnect before the reconnect_window
expires, the following events will occur:
- 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.