const resp = await call.get();
// userId of existing user
const userId = 'jane';
await client.upsertUsers([{ id: userId }]);
const token = client.generateUserToken({ user_id: userId });
const rtmpURL = resp.call.ingress.rtmp.address;
const streamKey = token;
console.log(rtmpURL, streamKey);
RTMP input
RTMP input service overview
RTMP input is a service designed to bridge the gap between RTMP (Real-Time Messaging Protocol) and WebRTC (Web Real-Time Communication). It enables users to stream content using an RTMP client, such as OBS (Open Broadcaster Software), and have that content published to participants in a Call. The service will transcode the received media to ensure compatibility with WebRTC. It will also publish multiple qualities of it with Simulcast.
Please note that this page is about publishing video/audio using RTMP, NOT watching livestreams using RTMP.
About RTMP
RTMP is a real-time streaming protocol created by Adobe, as media container format it uses Flash Video FLV also developed by Adobe.
There’s also an enhanced RTMP protocol, created to support a wider range of newer video codecs like AV1, HEVC and VP8. OBS for example supports AV1 and HEVC. RTMP input service doesn’t support them.
RTMP publishing
This is how you can acquire the necessary information for publishing RTMP using a third-party software.
from getstream.models import UserRequest
call = client.video.call("default", uuid.uuid4())
# create the call where the RTMP will be sent to
response = call.get_or_create()
# ensure we have a user for the host to send video via RTMP
client.upsert_users(
UserRequest(id="tommaso-the-host")
)
# create a token for the user sending video, this can be used as the stream key
stream_key = client.create_token(user_id, expiration=3600)
rtmp_url = response.data.call.ingress.rtmp.address
print(rtmp_url, stream_key)
call := client.Video().Call("default", uuid.New().String())
// create the call where the RTMP will be sent to
response, err := call.GetOrCreate(ctx, &getstream.GetOrCreateCallRequest{})
// ensure we have a user for the host to send video via RTMP
client.UpdateUsers(ctx, &getstream.UpdateUsersRequest{
Users: map[string]getstream.UserRequest{
"tommaso-the-host": {
ID: "tommaso-the-host",
},
},
})
// create a token for the user sending video, this can be used as the stream key
expiration := time.Now().Add(1 * time.Hour)
streamKey, err := client.CreateToken("tommaso-the-host", &StreamJWTClaims{Expire: &expiration})
rtmpURL := response.Data.Call.Ingress.Rtmp.Address
fmt.Println("RTMP URL:", rtmpURL, "Stream Key:", streamKey)
# RTMP URL is: response.call.rtmp.address
curl -X GET "https://video.stream-io-api.com/api/v2/video/call/livestream/${CALL_ID}?api_key=${API_KEY}" \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt"
# Stream key: create a user token
The user(s) streaming from the third-party software will show up as regular users in the call.
You can see an example in the Quickstart.
Streaming into a call with OBS
- Open OBS and go to
Settings
(CMD +, on macOS). - Set the
Stream Type
toCustom
. - Set the
URL
to thertmp_url
you got from the API. - Set the
Stream Key
to thestream_key
you got from the API.
Optimal OBS Video Encoding Settings
To ensure optimal quality and performance when transcoding media from RTMP, follow these recommended H.264 encoding settings:
Go to Settings
:
Video:
- Base Resolution: 1920x1080
- Output Resolution: 1920x1080 (Same as input resolution)
Output:
- Encoder:
x264
- Rate Control:
CBR
(Constant Bit Rate) - Bitrate: 3,000-6,000 kbps (adjust based on your network and type of media being streamed, higher movement will require higher bitrate)
- Keyframe Interval: 2 seconds
- CPU Usage Preset:
veryfast
(balance between quality and encoding speed) - Tune:
zerolatency
The example is for OBS, but any other RTMP client should support adding the same settings
Streaming into a call with restream.io
- Go to restream.io and create an account.
- For streaming to a custom RTMP server, you need to have a paid account.
- Add a new channel and select
Custom RTMP
. - Set the
Server
to thertmp_url
you got from the API. - Set the
Stream Key
to thestream_key
you got from the API.
Streaming a file into a call with FFmpeg
With your call’s RTMP url $CALL_RTMP_URL
and your token streamKey $STREAM_KEY
from publishing.
Run:
ffmpeg -re -stream_loop 400 -i YourVideoFile1080p30fps.mp4 \
-c:v libx264 -preset veryfast -tune zerolatency \
-pix_fmt yuv420p -g 50 -c:a aac -b:a 160k \
-ac 2 -f flv "$CALL_RTMP_URL/$STREAM_KEY"
FAQ
What is the typical latency introduced by RTMP?
RTMP input typically introduces a latency of 2-5 seconds. This can vary based on the network conditions, encoder settings (as the stream will be transcoded), and the performance of the RTMP server. Optimizing encoding settings and ensuring a stable network connection can help minimize this latency.
What are the best practices for setting up OBS for RTMP streaming?
Refer to Optimal OBS Video Encoding Settings.
Do we support both RTMP and RTMPS?
RTMP input service supports exclusively RTMPS. RTMPS is the recommended for secure streaming as it uses SSL/TLS to encrypt the data, providing an additional layer of security over RTMP.
What are the recommended internet connection settings for optimal streaming performance?
- Upload Speed: At least double the target bitrate of your stream. For example, if streaming at 5,000 kbps, ensure an upload speed of at least 10 Mbps.
- Connection Type: Wired Ethernet connection is preferred over Wi-Fi for stability.
- Network Quality: Ensure low packet loss (<1%) and low jitter (<30ms).