To create a livestream with Twilio Live, you create two different resources:
- A MediaProcessor, to join a Video Room and create the livestream content from the Room
- A PlayerStreamer, to send that livestream to a Player SDK
Both PlayerStreamer and MediaProcessor resources end via commands from the REST API or when the MediaProcessor's maximum duration has been reached, unless there is an error in the stream. They do not end automatically when you leave the Video Room that's being streamed.
It is important that you stop these resources via the API when the livestream is over, both for billing and account quota management. Each account has a limit on the number of concurrent PlayerStreamer and MediaProcessor resources it can have. Livestreams are billed per minute streamed, so to avoid unnecessary usage charges, we recommend ending the resources as soon as you no longer need them. View Twilio Live pricing here.
Additionally, you can set the MediaProcessor's maximum duration based on how long you anticipate your streams to last, so the resources automatically terminate after a specific amount of time if you forget to terminate them via the API. By default, a MediaProcessor's maximum duration is 300 seconds (5 minutes). If you retain this default value, the live stream will terminate after five minutes. You can update the maximum duration when creating the MediaProcessor.
You can use the REST API to understand your current resource usage. Use the API to retrieve lists of PlayerStreamers that are in the
started state and MediaProcessors that are in the
started state to verify that you are only running the livestreaming resources you need. PlayerStreamer's in
started state and MediaProcessors in the
started state are considered resources with active usage.
When a livestream finishes, you need to terminate all the resources related to that specific live stream. This is how your application should manage Twilio Live's resources (see the sequence diagram below for further clarification):
- Create a PlayerStreamer
- Create a MediaProcessor using the PlayerStreamer and specifying a Media Extension
- Streaming session starts, media flows and the audience joins
- Streaming session ends
- Explicitly end the MediaProcessor
- Explicitly end the PlayerStreamer