logo
Video Call
On this page

Set Video Encoding Mode

2024-01-02

Feature Overview

When developers publish and play video streams, they can make detailed settings for encoding and decoding, and can enable the video large and small stream encoding mode.

Video Large and Small Stream Encoding

Video large and small stream encoding divides the stream into a base layer and an enhancement layer. This encoding mode can provide a better experience for users with different network conditions, also known as large and small streams.

The base layer guarantees the most basic video quality, while the enhancement layer is a supplement to the base layer. For users with good networks, both the base layer and enhancement layer can be pulled to obtain a better experience. For users with poor network conditions, pulling only the base layer can guarantee basic video quality.

When developers encounter the following situations in connection or stream mixing services, it is recommended to use the video large and small stream encoding feature:

  • Need to display video streams of different quality on different terminals.
  • Need to maintain the smoothness of connection in poor network environments.
  • Need to adaptively pull the quality of video streams according to network conditions.
Note

Video large and small stream encoding uses ZEGO's private protocol. The pulling side can only pull video streams of different layers from the ZEGO server.

Implementation Steps

To use video large and small stream encoding, you need to enable video large and small stream encoding before publishing, and then specify the layered video to be pulled when pulling. The detailed steps are as follows.

Note

The initially created stream defaults to the large stream.

Enable Small Stream Encoding

Before publishing (startPublishingStream(@startPublishingStream)), call the enableDualStream interface to enable or disable the video small stream encoding feature.

// Enable small stream
zg.enableDualStream(localStream);

Set Small Stream Video Parameters

As needed, before publishing (startPublishingStream(@startPublishingStream)) and calling enableDualStream to enable small stream, call the setLowStreamParameter interface to set the small stream resolution, frame rate, width and height.

Warning
  • The parameters of the small stream cannot be greater than those of the large stream.
  • Some browsers do not support the large and small stream mode. For example, when macOS Safari 16 uses the H.264 encoding format, it does not support pushing small streams. At this time, you can switch to VP8 encoding or update the browser version, or try switching to other browsers.

zg.setLowStreamParameter(localStream, {width: 320, height: 240, frameRate: 15, bitRate: 400});

Pulling Side Specifies Layered Video to Pull

After the publishing side enables video large and small stream encoding, when the pulling side calls the startPlayingStream interface to pull streams, it can select the specified video layer type in the optional streamType parameter. At this time, the pulling side will pull the appropriate video layer according to the network situation by default. For example, in weak networks, only the base layer is pulled.

Developers can also pass in specific pull parameters to pull a specific video layer. The currently supported video layers are as follows:

Enumeration ValueDescription
0Small stream type
1Large stream type
2Automatically switch between large and small streams according to network status

Taking pulling the base layer as an example:

// Pull small stream
zg.startPlayingStream("streamID", {streamType: 0});

FAQ

Large and small streams are layered video encoding. Before pulling streams at the receiving end, users can set streamType to choose large or small streams when calling startPlayingStream according to their network conditions. They can also set it to default or not pass parameters to let ZEGO automatically choose for you.

The default resolution width and height of the base layer of video large and small stream encoding are 160 x 120, the frame rate is 15, and the bitrate is 50 kbps. You can modify the small stream parameters through setLowStreamParameter as needed. The small stream parameters cannot be greater than the large stream parameters.

Video large and small stream encoding uses ZEGO's private protocol. The pulling side can only pull video streams of different layers from the ZEGO server.

  • In the CDN forwarding scenario, the stream pushed by the publishing side to the ZEGO server can use video large and small stream encoding, and the stream with video large and small stream encoding can also be pulled from the ZEGO server. However, the stream forwarded by the ZEGO server to the CDN server cannot use video large and small stream encoding, but will be a high-quality stream. The stream pulled from CDN is consistent with the bitrate and resolution of the enhancement layer in video large and small stream encoding.
  • In the direct CDN push scenario, since it does not go through the ZEGO server, video large and small stream encoding is invalid. The resolution and bitrate of the stream pulled from CDN are consistent with the resolution and bitrate set by the publishing user.

How to solve the screen abnormality problem (such as black screen, green screen, flower screen, etc.) when interworking between Web platform and Native platform?

Previous

Basic Beauty

Next

Set Video Encoding Attributes

On this page

Back to top