- Introduction to Video
- Stream video files
- Start live streaming
- 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
Broadcast real-time video to a live stream
Connect your space to a live stream by adding a broadcast.
In this guide:
1
Create a Broadcast
1
Create a Broadcast
Creating a broadcast prepares the system to send video from your space to a live stream.
2
Start the broadcast
2
Start the broadcast
Send the video and audio from your space participants to the live stream.
3
(Optional) Stop the Broadcast
3
(Optional) Stop the Broadcast
Stop sending spaces video and audio to the live stream.
Full API ReferenceAPI
Let’s walk through the steps necessary to broadcast your space. First up, join your space from at least one browser session.
Next, you’ll need to find a live stream to connect to the broadcast. If you don’t have one, you can create one as shown below (you'll need to provide the values for your MUX_TOKEN_ID
and MUX_TOKEN_SECRET
):
curl https://api.mux.com/video/v1/live-streams \ -X POST \ -d '{ "playback_policy": "public", "new_asset_settings": { "playback_policy": "public" } }' \ -H "Content-Type: application/json" \ -u ${MUX_TOKEN_ID}:${MUX_TOKEN_SECRET}
Be sure to note down the id
for the live stream that is returned, as you’ll need that live stream ID for the rest of this guide. We’ll refer to this as ${LIVE_STREAM_ID}
going forward.
Next up, let’s create a broadcast
. Simply put, a broadcast acts as a bridge between a space to a live stream. When you create a broadcast
on a space
, the audio and video from your space are linked to a particular live stream.
Typically, a broadcast will be created on a space to prepare for the live stream. Then, the broadcast can be started to actually start sending the video and audio to the live stream. When you're ready to stop broadcasting to the live stream, simply stop the broadcast, as shown below.
Here's an example of creating a broadcast on a space (specified by ${SPACE_ID}
) to a live stream (specified by ${LIVE_STREAM_ID}
).
curl https://api.mux.com/video/v1/spaces/${SPACE_ID}/broadcasts \ -H "Content-Type: application/json" \ -X POST \ -d '{"live_stream_id" : "${LIVE_STREAM_ID}"}' \ -u ${MUX_TOKEN_ID}:${MUX_TOKEN_SECRET}
As you might expect, it's important to capture the id
of the broadcast from the response to this call so that you can use it in later actions. In this guide, we'll refer to that ID as ${BROADCAST_ID}
Full API ReferenceAPI
Now that our broadcast has been created, we can start the broadcast. To do this, we POST
to the start
endpoint, as shown below.
curl https://api.mux.com/video/v1/spaces/${SPACE_ID}/broadcasts/${BROADCAST_ID}/start \ -H "Content-Type: application/json" \ -X POST \ -u ${MUX_TOKEN_ID}:${MUX_TOKEN_SECRET}
To ensure that the broadcast is working correctly, you can go to the Mux Dashboard, find the live stream, and check that the broadcast of your space is being sent to the live stream. It should look something like this:
Full API ReferenceAPI
Finally, in order to stop broadcasting your space to the live stream, we'll call the stop
endpoint.
curl https://api.mux.com/video/v1/spaces/${SPACE_ID}/broadcasts/${BROADCAST_ID}/stop \ -H "Content-Type: application/json" \ -X POST \ -u ${MUX_TOKEN_ID}:${MUX_TOKEN_SECRET}
Please note that a broadcast will also automatically stop if all of the participants leave a space, or the space itself is removed. A broadcast will also be automatically stopped if the live stream is deleted or exceeds its time limit.