ZEGOCLOUD supports setting up the video configuration during a real-time video call or live streaming, such as video capture and video encoding output resolution, video frame rate, bitrate, view mode, and mirror mode.
Setting the proper video resolution, frame rate, and bitrate to provide a better experience in audio and video scenarios. Setting the appropriate view modes to provide a personalized video display mode.
Basic concepts
Before you begin, make sure you complete the following steps:
If you don't want to manually set the video configuration, you can use the sets of default values provided by the ZEGO Express SDK, the default values of ZegoVideoConfigPreset are as follows:
ZegoVideoConfigPreset | Capture resolution (Width × Height) |
Encoder resolution (Width × Height) |
Frame rate (fps) |
Bitrate (kbps) |
---|---|---|---|---|
PRESET_180P |
180 × 320 |
180 × 320 |
15 |
300 |
PRESET_270P |
270 × 480 |
270 × 480 |
15 |
400 |
PRESET_360P |
360 × 640 |
360 × 640 |
15 |
600 |
PRESET_540P |
540 × 960 |
540 × 960 |
15 |
1200 |
PRESET_720P |
720 × 1280 |
720 × 1280 |
15 |
1500 |
PRESET_1080P |
1080 × 1920 |
1080 × 1920 |
15 |
3000 |
The sample code for using default values is shown below:
ZegoVideoConfig *config = [ZegoVideoConfig configWithPreset:ZegoVideoConfigPreset1080P];
[[ZegoExpressEngine sharedEngine] setVideoConfig:config];
You will need to set up the video configuration before the stream publishing starts (startPublishingStream
) or local video preview starts (startPreview
).
Only the encoder resolution and bitrate can be modified after stream publishing.
To set up the video configuration, call the setVideoConfig
method. If you don't customize your video configuration, ZEGO uses the default values as shown below:
Item | Default value |
---|---|
Resolution | 360p |
Bitrate | 600 kbps |
Framerate | 15 fps |
The following sample code is used for setting the video capture resolution to 360p, encoder resolution to 360p, bitrate to 600 kbps, and frame rate to 15 fps:
//Set Video Config Before StartPreview And StartPublishing
ZegoVideoConfig *videoConfig = [[ZegoVideoConfig alloc] init];
videoConfig.captureResolution = CGSizeMake(360, 640);
videoConfig.encodeResolution = CGSizeMake(360, 640);
videoConfig.fps = 15;
videoConfig.bitrate = 600;
[[ZegoExpressEngine sharedEngine] setVideoConfig:videoConfig];
The width and height resolutions of the mobile terminal are opposite to those of the PC terminal. For example, the 360p resolution of the mobile terminal is 360x640, while the 360P resolution of the PC terminal is 640x360.
To set the video view mode, you will need to stop the local video preview or stop stream playing first; Otherwise, the settings won't take effect.
To set the video view mode, modify the viewMode
property of the ZegoCanvas
object.
Currently, the following three video rendering and filling modes are supported:
Enumerated value | Description |
---|---|
ZegoViewModeAspectFit | Uniform scaling, the image may have black edges. |
ZegoViewModeAspectFill | Uniform scaling and filling the entire View, and images may be cropped. |
ZegoViewModeScaleToFill | Fill the entire View, and the image may be stretched. |
The effects of the three video rendering and filling modes are as shown below:
The resolution of the image shown above is 320 x 390 (width x height), and the video resolution is 340 x 340 (width x height).
As shown above, the height of the original video is equal to the width, while the height of the image is greater than the width. Therefore, in the ZegoViewModeAspectFit
view mode, black edges appear on the top and bottom of the video. If the width of the image is larger than the height, black edges will appear on the left and right sides of the video in ZegoViewModeAspectFit
view mode.
The following sample code is used for setting the view mode to ZegoViewModeAspectFit
and starting the local video preview:
// The following [remotePlayView] is a SurfaceView, TextureView, or SurfaceTexture object on the UI.
ZegoCanvas *previewCanvas = [ZegoCanvas canvasWithView:self.remotePlayView];
// Set the display mode to [ZegoViewModeAspectFit].
previewCanvas.viewMode = ZegoViewModeAspectFit;
// Start the local video preview.
[[ZegoExpressEngine sharedEngine] startPreview:previewCanvas];
This mode can also be set during stream publishing and take effect immediately.
To mirror the video you want to publish or mirror the video in a local video preview, call the setVideoMirrorMode
method before or after the stream publishing.
Currently, the following four mirror modes are supported:
Enumeration value | Description |
---|---|
ZegoVideoMirrorModeNoMirror | Neither Capturer (local video preview) nor stream player gets mirrored images. |
ZegoVideoMirrorModeOnlyPreviewMirror | The image is mirrored only in the local video preview. This mode is used by default. |
ZegoVideoMirrorModeOnlyPublishMirror | Only stream player is expected to see mirrored images. |
ZegoVideoMirrorModeBothMirror | Capturer (local video preview) and stream player are expected to see mirrored images. |
The effects of the four mirror modes are as shown below:
The following sample code is used for setting the mirror mode for the stream player without mirroring the local video preview:
[[ZegoExpressEngine sharedEngine] setVideoMirrorMode:ZegoVideoMirrorModeOnlyPublishMirror];
The Express-video SDK uses the locked portrait mode by default, that is, the video images in the local video preview and the video streams you played are in portrait orientation.
To set the video to landscape mode, call the setAppOrientation
method.
UIInterfaceOrientationLandscapeLeft
to the parameter. UIInterfaceOrientationLandscapeRight
to the parameter.[[ZegoExpressEngine sharedEngine] setAppOrientation:UIInterfaceOrientationLandscapeLeft];
To use the G-Sensor mode (gravity-sensing adaptation) for live streaming or video calling, you will need to listen for the related video image rotation event callbacks and set the corresponding video orientation accordingly.
If you use the SDK for video data capturing, to implement the G-Sensor mode, you will need to use the following 2 methods:
setVideoConfig
: Callback for updates on the phone screen orientation.
setAppOrientation
: Method for setting the video image orientation.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];
-(void)orientationChanged:(NSNotification *)notification {
UIDevice *device = notification.object;
ZegoVideoConfig *videoConfig = [[ZegoExpressEngine sharedEngine] getVideoConfig];
UIInterfaceOrientation orientation = UIInterfaceOrientationUnknown;
switch (device.orientation) {
// Note that UIInterfaceOrientationLandscapeLeft is equal to UIDeviceOrientationLandscapeRight (and vice versa).
// This is because rotating the device to the left requires rotating the content to the right.
case UIDeviceOrientationLandscapeLeft:
orientation = UIInterfaceOrientationLandscapeRight;
videoConfig.encodeResolution = CGSizeMake(640, 360);
break;
case UIDeviceOrientationLandscapeRight:
orientation = UIInterfaceOrientationLandscapeLeft;
videoConfig.encodeResolution = CGSizeMake(640, 360);
break;
case UIDeviceOrientationPortrait:
orientation = UIInterfaceOrientationPortrait;
videoConfig.encodeResolution = CGSizeMake(360, 640);
break;
case UIDeviceOrientationPortraitUpsideDown:
orientation = UIInterfaceOrientationPortraitUpsideDown;
videoConfig.encodeResolution = CGSizeMake(360, 640);
break;
default:
// Unknown / FaceUp / FaceDown
break;
}
[[ZegoExpressEngine sharedEngine] setVideoConfig:videoConfig];
[[ZegoExpressEngine sharedEngine] setAppOrientation:orientation];
}
sendCustomVideoCapturePixelBuffer
method.Process the video frame data with the SDK:
a. In the callback for the updates on the device screen orientation, set the rotation
property of the ZegoVideoEncodedFrameParam
method based on the actual device screen orientation.
b. Pass the video frame data and set the video image orientation parameter with the sendCustomVideoCaptureEncodedData
method for sending processed video data to the SDK.
Why can't I playback the recorded video?
Because in G-Sensor mode, streams' encoder resolution changes, and some third-party players can't compatible with the video that has been modified resolution very well, which results in you may fail to playback the video you recorded.
Therefore, we recommend you don't modify the resolution in the G-Sensor mode during live streaming or video calling.