logo
Live Streaming
On this page

RTMP Push Stream to ZEGO Server


Introduction

In live streaming scenarios, hosts can push audio and video streams to ZEGO servers via RTMP push streaming tools to achieve low latency. Viewers can use ZEGO Express SDK to play streams.

RTMP push streaming tools refer to third-party tools that push streams via RTMP addresses, mainly including hardware push streaming devices, software OBS, etc.

Prerequisites

  • You have contacted ZEGOCLOUD Technical Support to enable the permission for RTMP tools to push streams to ZEGO servers.
  • Prepare an RTMP push streaming tool, such as OBS.

Usage

Get RTMP Push URL

Please contact ZEGOCLOUD Technical Support to enable the service, and obtain the RTMP push URL through the RTMP Push Dispatch server-side interface.

Use RTMP Tool to Push Stream

The following section takes OBS as an example to introduce the RTMP tool's push streaming operation.

Set Push URL

  1. Open the OBS tool, and click "Settings" in the "Controls" tab at the bottom toolbar to enter the settings interface.
  1. Click "Stream" to enter the stream settings tab, and select the service type as "Custom Streaming Server".

  2. Fill in the obtained RTMP push URL into the "Server" and "Stream Key" fields.

  • Server: Corresponds to the RTMP push URL, namely rtmp://hosts/AppName/

    Please note that the RTMP push URL is different from the push URL in CDN Push Authentication and cannot be mixed up. Please pay attention to distinguish when using them.

  • Stream Key: Corresponds to the RTMP push stream name, namely "streamID".

  1. Click "OK" to save the above settings.

Set Push Source

  1. Click the "+" button in the "Sources" tab at the bottom toolbar.
  1. Select an input source as needed, such as "Display Capture".

Use OBS to Push Stream

  1. Click "Start Streaming" in the "Controls" tab at the bottom toolbar to push the audio and video stream to the set push URL. When a green light appears at the bottom, it indicates successful push streaming.
  1. To stop push streaming, click "Stop Streaming" in the "Controls" tab.
Warning

After using the RTMP tool to push streams, users cannot receive notifications of audio and video stream additions or deletions through the onRoomStreamUpdate callback. They can obtain them through the following two ways:

  • After using the RTMP tool to push streams, the business server sends the third-party push "streamID" to other users in the room through business signaling to notify other users in the room that streams have been added or deleted.
  • You can use ZEGO's server-side Add Room Stream and Delete Room Stream interfaces to add or delete a stream to the specified room, and send the "streamID" information to other users in the room. At this time, other users can receive notifications of audio and video stream additions or deletions through the onRoomStreamUpdate callback.

Use SDK to Play or Stop Playing Stream

Call the startPlayingStream interface and pass in the "streamID" of the RTMP push stream (namely the "Stream Key" set in section 3.2.1) to play the stream.

createCanvasView Interface Usage Demo

  • The interface will automatically choose to use TextureRenderer or PlatformView based on the "enablePlatformView" parameter set when creating the engine and the platform-supported method.
  • Android and iOS platforms will choose between TextureRenderer and PlatformView based on the "enablePlatformView" parameter set when creating the engine.
  • Web, Windows, and MacOS are not affected by the "enablePlatformView" parameter set when creating the engine, and only use the supported method.

Get the Widget for preview, then use viewID to create a ZegoCanvas object and start preview.

// Add this Widget to the page's rendering tree to display the preview screen
_playViewWidget = await ZegoExpressEngine.instance.createCanvasView((viewID) {
    _playViewID = viewID;

    // Set the playing canvas
    ZegoCanvas canvas = ZegoCanvas.view(viewID);

    // Start playing
    ZegoExpressEngine.instance.startPlayingStream(streamID,
        canvas: canvas,
        config: ZegoPlayerConfig(ZegoStreamResourceMode.OnlyCDN,videoCodecID: ZegoVideoCodecID.Default, roomID: roomID));
});

Call the stopPlayingStream interface and pass in the "streamID" of the RTMP push stream (namely the "Stream Key" set in section 3.2.1) to stop playing the remote pushed audio and video stream.

// Stop playing stream
ZegoExpressEngine.instance.stopPlayingStream(streamID);

If you used createCanvasView when playing streams, you need to call the destroyCanvasView interface to destroy it.

// _playViewID is the viewID obtained when calling [createCanvasView]
ZegoExpressEngine.instance.destroyCanvasView(_playViewID);

FAQ

1. How does the business server know whether the RTMP push streaming tool has started or stopped push streaming?

ZEGO provides publish_start start push streaming and publish_stop stop push streaming callback notifications. If needed, please contact ZEGOCLOUD Technical Support to configure.

Previous

Single Stream Transcoding

Next

OBS Streaming with WHIP Protocol

On this page

Back to top