Live streaming RTMP
Last updated: Jul-11-2023
Cloudinary's RTMP live video streaming initiates an RTMP input URI for use with dedicated streaming software and hardware to stream your own video to your users via various platforms.
The RTMP live streaming workflow using Cloudinary is:
- Use an unsigned upload to upload a live streaming manifest using a live streaming upload preset.
- Use the RTMP live output URI from the upload response to start streaming with dedicated streaming software.
- Deliver an HLS adaptive bitrate live stream using the live output URI.
Setup
1. Create a new live streaming upload preset
Create a new unsigned upload preset or modify an existing one to enable live broadcast. You can do this either using the Admin API by setting the live
parameter to true
or via the Cloudinary Console, in the Storage and Access section of the Edit upload preset page, by turning on Live broadcast.
2. Create your live streaming manifest file
The live streaming manifest is a json file that contains the configuration for your live streaming, for example:
The example above sets:
-
input_type
tortmp
. -
targets
for the live stream tohls
for adaptive streaming andfile
for saving the stream to your Cloudinary storage. -
idle_timeout_sec
to 120 seconds to end the stream when idle for the set period. -
max_runtime_sec
to 32000 seconds to end the stream after the set period has elapsed.
See the live streaming reference for all the available parameters.
Initializing a live stream
To initialize an RTMP live stream, upload the live streaming manifest file using the live streaming upload preset you created.
Here is a cURL example for the request:
Response
The JSON response from the upload contains the same parameters as an upload of media or raw files, with the addition of two parameters:
-
live_input_uri
- This is the input uri and contains the server and stream key that need to be entered into your RTMP live streaming software.- The server part is everything up to and including your cloudname. e.g.
rtmp://3.214.86.161:1935/<cloud_name>
- The stream key is the string after your cloudname. e.g.
dh8bxtg97t9cns4bddoa_56753701a34f46cdc6a094e7
- The server part is everything up to and including your cloudname. e.g.
-
live_output_uri
- This is the output uri used to view the live stream and can be displayed using a video player such as the Cloudinary Video Player.
Below is an example response from initializing an RTMP live stream:
Terminating a live stream
A live stream is terminated automatically when either the configured max_runtime_sec
or idle_timeout_sec
have elapsed.
Live streaming reference
This reference lists the available parameters to be included in the streaming manifest json file for RTMP streaming.
Required parameters
Param | Type | Description |
---|---|---|
targets | array | An array of objects defining the output targets for the live stream. Each target is comprised of:
|
input_type | string |
Required for RTMP. The live streaming protocol to use. Possible values: |
Optional parameters
Param | Type | Description |
---|---|---|
input_codec | string | The codec to use for input. Possible values: avc , mpeg2 . Default: avc . |
input_resolution | string | The resolution to use for input. Possible values: hd , sd . Default: hd . |
input_max_bitrate | integer (Mbps) | The maximum bitrate to use for input in Mbps. Default: 10 . |
max_runtime_sec | integer (seconds) | The maximum run time for the stream in seconds before the stream is terminated. Default: 43200 . |
idle_timeout_sec | integer (seconds) | The length of time in seconds that the no input is detected before the stream is terminated. Default: 120 . |
input_loss_image | string (url) | An image URL (PNG or BMP only) to show when input is lost. Default: null . |
- The public ID for the stream will be assigned automatically, you can't manually set the public ID.
- If the video from your live stream exceeds your storage limits, the video will not be stored in your product environment.