All Products
Search
Document Center

ApsaraVideo Live:Switch between layouts based on SEI

Last Updated:Nov 20, 2024

This topic describes how viewer clients receive information about layout changes from single-streamer streaming to co-streaming.

When the layout changes from single-streamer streaming to co-streaming, ApsaraVideo Live automatically adds a supplemental enhancement information (SEI) frame to the stream. The SEI frame contains layout information about all participants in the live stream. You can enable SEI listening on the viewer clients to allow them to detect layout changes. This helps address the latency issue when the stream is pulled from a content delivery network (CDN). You can configure SEI settings in the ApsaraVideo Live console.

The following table describes the structure of an SEI frame.

Data type

Parameter

Description

Video stream information

stream

The information about the streamer.

uid: the user ID of the streamer.

The layout information of the area where the streamer is streaming. Take note of the following layout parameters:

  • paneid: the sequence number of the area in the pane. Valid values: [0,8].

  • zorder: the layer of the area. Valid values: [0,99].

  • x: the x-coordinate of the area in the canvas. The value is normalized.

  • y: the y-coordinate of the area in the canvas. The value is normalized.

  • w: the width of the area. The value is normalized.

  • h: the height of the area. The value is normalized.

  • vol: the volume of the streamer. Unit: dB. Valid values: [0,255].

  • vad: detects human voice. Valid values: [0,150]. 150 indicates that human voice is detected and a value other than 150 indicates the period of time during which the volume of human voice decreases to 0.

If a single streamer is streaming, the SEI message that viewers receive contains information about only one participant. If co-streaming or battle occurs, the SEI message that viewers receive contains information about multiple participants.

For example, when the streamer whose user ID is 111 is streaming, an SEI frame in the following format is sent to the viewer side:

{"stream":[{"uid":"111","paneid":-1,"zorder":0,"x":0,"y":0,"w":0,"h":0,"type":0,"ms":0,"vol":0,"vad":0}]}

When the streamer whose user ID is 111 is co-streaming with a co-streamer whose user ID is 222, an SEI frame in the following format is sent to the viewer side:

{"stream":[{"uid":"111","paneid":0,"zorder":1,"x":0,"y":0.25,"w":0.5,"h":0.5,"type":0,"ms":0,"vol":1,"vad":119},{"uid":"222","paneid":1,"zorder":1,"x":0.5018382,"y":0.25,"w":0.5,"h":0.5,"type":0,"ms":0,"vol":60,"vad":123}]}

Viewers can determine whether a streaming layout changes based on the number of stream arrays. If only one stream array exists, a single streamer is streaming. If more than one stream array exists, co-streaming or battle occurs. The layout information of the participants indicates the position of each participant in the mixed stream.

The following sample code provides an example on how to use ApsaraVideo Player to parse an SEI frame:

Sample code for Android:

mAliPlayer = AliPlayerFactory.createAliPlayer(mContext);

PlayerConfig playerConfig = mAliPlayer.getConfig();
// Configure SEI frame parsing for audio-only or video-only streams in the FLV format to reduce the startup time.
// Configure the start buffer time. A larger value indicates more stable startup. However, an excessively large value may affect the startup time. Specify this parameter based on your business requirements.
playerConfig.mStartBufferDuration = 1000;
// Configure the cache required for stuttering to recover. Specify a larger value in poor network conditions. We recommend that you set the value to 500 for an audio-only stream and 3000 for a video stream.
playerConfig.mHighBufferDuration = 500;
// Enable SEI listening.
playerConfig.mEnableSEI = true;
mAliPlayer.setConfig(playerConfig);

mAliPlayer.setAutoPlay(true);

mAliPlayer.setOnErrorListener(errorInfo -> {
    mAliPlayer.prepare();
});

mAliPlayer.setOnSeiDataListener(new IPlayer.OnSeiDataListener() {
    @Override
    public void onSeiData(int i, byte[] bytes) {

    }
});

Sample code for iOS:

self.cdnPlayer = [[AliPlayer alloc] init];
self.cdnPlayer.delegate = self;
AVPConfig *config = [self.cdnPlayer getConfig];
config.enableSEI = YES;
[self.cdnPlayer setConfig:config];

// Listen to SEI-related callbacks.
- (void)onSEIData:(AliPlayer*)player type:(int)type data:(NSData *)data {
    if (data.bytes){
        NSString *str = [NSString stringWithUTF8String:data.bytes];
        // Process the SEI message.
    }
}