- 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
Start live streaming
In this guide you will learn how to build a live streaming platform with Mux live streaming.
In this guide:
1
Get an API Access Token
1
Get an API Access Token
The Mux Video API uses a token key pair that consists of a Token ID and Token Secret for authentication. Generate a new Access Token in the settings of your Mux account dashboard.
2
Create a unique Live Stream
2
Create a unique Live Stream
A Live Stream resource in Mux will be used to push live content via RTMP. Each live stream has a unique stream key.
3
Start broadcasting
3
Start broadcasting
Use any streaming app or hardware device that supports RTMP streaming.
4
Play live stream
4
Play live stream
Use the PLAYBACK_ID for the live stream to start playback in your application.
5
Stop broadcast
5
Stop broadcast
Stop the broadcast from the streaming app or hardware.
6
Manage your Mux Live streams
6
Manage your Mux Live streams
Delete, update, and more live stream functionalities are available via the Video Live stream API methods
Whether you’re looking to build “Twitch for X”, online classrooms, a news & sports broadcasting platform or something the world’s never seen before, the Mux Live Streaming API makes it easy to build live video into your own software. With a simple API call you get everything you need to push a live stream and play it back at high quality for a global audience.
The Mux Video API uses a token key pair that consists of a Token ID and Token Secret for authentication. If you haven't already, generate a new Access Token in the Access Token settings of your Mux account dashboard.
The access token should have Mux Video Read and Write permissions.
Access Tokens also belong to an Environment. Be sure to use the same Environment when using Mux Video and Mux Data together, so the data from Mux Data can be used to optimize your Mux Video streams.
Detailed API ReferenceAPI
The Live Stream object in the Mux API is a record of a live stream of video that will be pushed to Mux. To create your first Live Stream, POST request to the /live-streams endpointAPI.
You can either replace ${MUX_TOKEN_ID}
and ${MUX_TOKEN_SECRET}
with your own access token details or make sure to export those environment variables with the correct values first.
curl https://api.mux.com/video/v1/live-streams \
-H "Content-Type: application/json" \
-X POST \
-d '{ "playback_policy": ["public"], "new_asset_settings": { "playback_policy": ["public"] } }' \
-u ${MUX_TOKEN_ID}:${MUX_TOKEN_SECRET}
The response will include a Playback ID and a Stream Key.
- Playback IDsAPI for a Live Stream can be used the same way as Playback IDs for an Asset. You can use it to play video, get images from a video or build timeline hover previews with your player.
- The Stream Key is a secret that can be used along with Mux's RTMP Server URL (see table below) to configure RTMP streaming software.
Important
The Stream Key should be treated as a private key for live streaming. Anyone with the key can use it to stream video to the Live Stream it belongs to, so make sure your users know to keep it safe. If you lose control of a stream key, you can either delete the Live Stream or reset the stream keyAPI
{ "data": { "id": "QrikEQpEXp3RvklQSHyHSYOakQkXlRId", "stream_key": "super-secret-stream-key", "status": "idle", "playback_ids": [ { "policy": "public", "id": "OJxPwQuByldIr02VfoXDdX6Ynl01MTgC8w02" } ], "created_at": "1527110899" } }
Mux also allows you to set a few additional options on your live stream. When enabled, you can support more use cases.
"latency_mode": "reduced"
Mux live streams have an option for "reduced latency". When"latency_mode": "reduced"
is enabled, we treat your stream a little differently to minimize glass-to-glass latency. The latency reduces to about 10-15 seconds compared to 30 seconds typically without enabling this option. For more details, please refer to the Live Stream Latency guide.low_latency
BETA Similar to `"reduced"
latency option,"latency_mode": "low"
live streams reduce the glass-to-glass latency to as low as 4 seconds but the latency can vary depending on your viewer's geographical location and internet connectivity. For more details, please refer to the Live Stream Latency guide.audio_only
Mux live streams is ready for Audio specific use cases too. For example, you can host Live Podcasts or broadcast Radio Shows. Whenaudio_only
is enabled, we only process the audio track, even dropping the video track if broadcast.
You can find more details about the options on the Create Live StreamAPI.
Mux supports live streaming using the RTMP protocol, which is supported by most broadcast software/hardware as well as open source software for mobile applications.
Your users or your client app will need software that can push an RTMP stream. That software will be configured using the Stream Key from the prior step along with Mux's RTMP Server URL. Mux supports both RTMP and RTMPS:
RTMP Server URL | Description | Common Applications |
---|---|---|
rtmp://global-live.mux.com:5222/app | Mux's standard RTMP entry point. Compatible with the majority of streaming applications and services. | Open Source RTMP SDKs, most app-store streaming applications. |
rtmps://global-live.mux.com:443/app | Mux's secure RTMPS entry point. Compatible with less streaming applications, but offers a higher level of security. | OBS, Wirecast, Streamaxia RTMP SDKs |
Learn more about:
- How to configure broadcast software for when users will be using their own streaming software, e.g. Twitch live streamers
- How to live stream from a mobile app for when users will live stream using your mobile app
Important
Mux's RTMP server URL uses port number 5222 and not the standard RTMP port number 1935. If your encoder does not provide a method to change the port number, please contact help@mux.com with your encoder details.
If you want to live stream with a protocol other than RTMP, let us know!
The broadcast software will describe how to start and stop an RTMP session. Once the session begins, the software will start pushing live video to Mux and the Live Stream will change its status to active
indicating it is receiving the RTMP stream and is playable using the Playback ID.
Broadcasting Webhooks
When a Streamer begins sending video and the Live Stream changes status, your application can respond by using Webhooks. There are a few related events that Mux will send. You application may benefit from some or none of these events, depending on the specific user experience you want to provide.
video.live_stream.connected
- The Streamer's broadcasting software/hardware has successfully connected with Mux servers. Video is not yet being recorded and is not yet playable.video.live_stream.disconnected
- The Streamer's broadcasting software/hardware has disconnected from Mux servers, either intentionally or unintentionally because of a network drop.video.live_stream.recording
- Video is being recorded and prepared for playback. The recording of the live stream (the Active Asset) will include video sent after this point. If your UI has a red "recording" light, this would be the event that turns it on.video.live_stream.active
- The Live Stream is now playable using the Live Stream's Playback ID or the Active Asset's Playback IDvideo.live_stream.idle
- The Streamer's broadcasting software/hardware previously disconnected from Mux servers and thereconnect_window
has now expired. The recording of the live stream (the Active Asset) will now be considered complete. The next time video is streamed using the same Stream Key it will create a new Asset for the recording.video.asset.live_stream_completed
- This event is fired by the Active Asset when the Live Stream enters theidle
state and the Active Asset is considered complete. The Asset's playback URL will switch to being an "on-demand" (not live) video.
To play back a live stream, use the PLAYBACK_ID
that was returned when you created the Live Stream along with stream.mux.com to create an HTTP Live Streaming (HLS) playback URL.
https://stream.mux.com/{PLAYBACK_ID}.m3u8
implementation 'com.google.android.exoplayer:exoplayer-hls:2.X.X'
// Create a player instance.
SimpleExoPlayer player = new SimpleExoPlayer.Builder(context).build();
// Set the media item to be played.
player.setMediaItem(MediaItem.fromUri("https://stream.mux.com/{PLAYBACK_ID}.m3u8"));
// Prepare the player.
player.prepare();
See the playback guide for more information about how to integrate with a video player.
After you have everything working integrate Mux Data with your player for monitoring playback performance.
When the Streamer is finished they will stop the broadcast software/hardware, which will disconnect from the Mux servers. After the reconnect_window
time (if any) runs out, the Live Stream will transition to a status of idle
.
Mux automatically disconnects clients after 12 hours. Contact us if you require longer live streams.
After you have live streams created in your Mux environment, you may find some of these other endpoints handy:
- Create a live streamAPI
- List live streamsAPI
- Retrieve a live streamAPI
- Delete a live streamAPI
- Create a live stream playback IDAPI
- Delete a live stream playback IDAPI
- Reset a stream key for a live streamAPI
- Signal a live stream is finishedAPI
- Disable a live streamAPI
- Enable a live streamAPI
- Create a live stream simulcast targetAPI
- Delete a live stream simulcast targetAPI
- Retrieve a live stream simulcast targetAPI
More Video methods and descriptions are available at the API DocsAPI.