logo
Video Call
On this page

Common Video Configuration

2024-02-28

Introduction

During video calls or live streaming, developers can specify related configurations for publishing and playing stream videos as needed, such as video capture resolution, video encoding output resolution, video frame rate, bitrate, view mode, and mirror mode.

  • Resolution:
    • Video resolution: A parameter used to measure the amount of data in an image, usually expressed as ppi.
    • Capture resolution: The resolution of the screen provided by capture devices such as cameras.
    • Encoding resolution: The resolution of the screen after encoding processing.
  • Bitrate: The number of bits transmitted per second, in bps (bit per second).
  • Frame rate: A measure of the number of video frames displayed per unit time, measured in "frames per second" (Frame Per Second, fps).

Setting appropriate video resolution, frame rate, and bitrate can provide users with a better experience in audio and video scenarios. Choosing the appropriate mirror mode and view mode allows developers to provide personalized video display modes.

Download Sample Source Code

Please refer to Download Sample Source Code to obtain the source code.

For related source code, please check the files in the "/ZegoExpressExample/Examples/CommonFeatures/CommonVideoConfig" directory.

Prerequisites

Before setting video configurations, ensure that:

Usage Steps

1 Modify Video Configuration

Modify video configuration by calling the setVideoConfig interface. Users can either customize parameters or use preset values for settings.

Warning

Relevant video configurations need to be set before publishing stream (startPublishingStream) or preview (startPreview). After publishing stream, only encoding resolution and bitrate modifications are supported.

Custom Parameter Settings

Call the setVideoConfig interface to modify publishing stream video configuration. Through this interface, you can set video frame rate, bitrate, video capture resolution, and video encoding output resolution. If no special settings are made, the SDK will automatically apply resolution, bitrate, and frame rate suitable for the selected scenario based on the selected scenario to obtain the best experience effect. For details, please refer to Scenario-based Audio and Video Configuration.

Note

If the playing stream end needs to play 60-frame streams, you need to contact technical support. For details, please refer to Does ZEGO Express SDK support pulling 60-frame streams?

Taking setting video capture resolution to 360p, encoding resolution to 360p, bitrate to 600 kbps, and frame rate to 15 fps as an example:

// Need to set relevant video configurations before preview (startPreview) and publishing stream (startPublishingStream)
ZegoVideoConfig videoConfig;

videoConfig.captureHeight = 360;
videoConfig.captureWidth = 640;
videoConfig.encodeHeight = 360;
videoConfig.encodeWidth = 640;
videoConfig.fps = 15
videoConfig.bitrate = 600;

// Set video configuration
ZegoExpressEngine::getEngine()->setVideoConfig(videoConfig);
Note

The width and height resolution on mobile devices is opposite to that on PC. For example, the resolution of 360p on mobile devices is 360 × 640, while the resolution of 360p on PC is 640 × 360.

Using Preset Values

In addition to custom setting parameters, you can also use the preset combination values provided by ZEGO Express SDK. The preset combination values of ZegoVideoConfigPreset are as follows:

ZegoVideoConfigPresetCapture Resolution
(Width × Height)
Encoding Resolution
(Width × Height)
Frame Rate (fps)Bitrate (kbps)
ZEGO_VIDEO_CONFIG_PRESET_180P320 × 180320 × 18015300
ZEGO_VIDEO_CONFIG_PRESET_270P480 × 270480 × 27015400
ZEGO_VIDEO_CONFIG_PRESET_360P640 × 360640 × 36015600
ZEGO_VIDEO_CONFIG_PRESET_540P960 × 540960 × 540151200
ZEGO_VIDEO_CONFIG_PRESET_720P1280 × 7201280 × 720151500
ZEGO_VIDEO_CONFIG_PRESET_1080P1920 × 10801920 × 1080153000

Example code when calling the setVideoConfig interface to use preset values:

// Use preset values for video settings
ZegoVideoConfig vConfig(ZEGO_VIDEO_CONFIG_PRESET_360P);
engine->setVideoConfig(vConfig);

2 Modify Video View Mode

Warning

Before setting the video view mode, you need to stop preview or playing stream first, otherwise it cannot take effect.

By modifying the "viewMode" parameter of the view object ZegoCanvas, you can modify the view mode of the video. Currently, the following three video rendering fill modes are supported:

Enumeration ValueDescription
ZEGO_VIEW_MODE_ASPECT_FITAspect ratio scaling, there may be black borders.
ZEGO_VIEW_MODE_ASPECT_FILLAspect ratio scaling fills the entire View, some parts may be cropped.
ZEGO_VIEW_MODE_SCALE_TO_FILLFills the entire View, the image may be stretched.

The effects of the three video rendering fill modes are shown in the figure:

  • The view resolution shown in the figure above is 320 × 390 (width × height), and the video resolution is 340 × 340 (width × height).
  • In the figure above, the original video size length equals width, and the view size length is greater than width. Therefore, in the "ZEGO_VIEW_MODE_ASPECT_FIT" rendering mode, black borders appear on the top and bottom of the video; if the view size width is greater than length at this time, then in the "ZEGO_VIEW_MODE_ASPECT_FIT" rendering mode, black borders will appear on the left and right sides of the video.

Taking setting the preview view mode to "ZEGO_VIEW_MODE_ASPECT_FIT" and starting preview as an example:

// winId is the video preview window handle
ZegoCanvas previewCanvas(ZegoView(winId));
// Set view mode to ZEGO_VIEW_MODE_ASPECT_FIT
previewCanvas.viewMode = ZEGO_VIEW_MODE_ASPECT_FIT;
// Start preview
engine->startPreview(&previewCanvas);

3 Set Mirror Mode

Note

This function can be set before or after publishing stream, and takes effect immediately after setting.

Before publishing stream or after stopping publishing stream, you can set whether the local preview video and the published video enable mirror mode by calling setVideoMirrorMode. Currently, the following four mirror modes are supported:

Enumeration ValueDescription
ZEGO_VIDEO_MIRROR_MODE_NO_MIRRORNeither the local preview nor the video seen by the playing stream end is a mirrored image.
ZEGO_VIDEO_MIRROR_MODE_ONLY_PREVIEW_MIRROROnly the local preview is a mirrored image. This mode is used by default.
ZEGO_VIDEO_MIRROR_MODE_ONLY_PUBLISH_MIRROROnly the video seen by the playing stream end is a mirrored image.
ZEGO_VIDEO_MIRROR_MODE_BOTH_MIRRORBoth the local preview and the video seen by the playing stream end are mirrored images.

The effects of the four mirror modes are as follows:

Taking setting the playing stream end to mirror and local preview not to mirror as an example:

// Set mirror mode so that only the video seen by the playing stream end is a mirrored image
engine->setVideoMirrorMode(ZEGO_VIDEO_MIRROR_MODE_ONLY_PUBLISH_MIRROR);
2024-02-28

Previous

Get the Raw Audio Data

Next

Screen Sharing

On this page

Back to top