Detailed codec settings can be made as you publish and play the video streams, including enabling the Scalable Video Coding (SVC), hardware codec, and choosing the video codec types.
Scalable video coding (SVC)
SVC is a technique to encode a video sequence into a bitstream that contains multiple sub-bitstreams (called layers)—a base layer and one or more enhancement layers. The base layer provides the basic quality of the video content, and each enhancement layer improves the video quality of its lower layers in a certain dimension: frame rate, resolution, or bitrate. As a result, the stream subscriber can choose to receive and decode only the base layer or the base layer plus a certain number of enhancement layers according to its available bandwidth and terminal characteristics (for example, screen size).
SVC enables your app to meet the following requirements:
Hardware Codec
ZEGOCLOUD supports enabling the hardware codec. After the hardware codec is enabled, the GPU is used for encoding and decoding to reduce CPU usage. You can enable this when the device of some models is hot when publishing or playing high-resolution audio and video streams.
Video codec types
ZEGOCLOUD supports choosing the different video codec types accordingly to realize the coding alignment across platforms.
Use cases:
H.265
.H.264
.Before you implement the video codec feature, make sure you complete the following steps:
To enable SVC before publishing a stream, do the following:
setVideoConfig
method and set the codecID
property of the ZegoVideoConfig
accordingly.codecID
property to ZegoVideoCodecID.SVC
.codecID
property to ZegoVideoCodecID.DEFAULT
, ZegoVideoCodecID.VP8
, or ZegoVideoCodecID.H265
.startPublishingStream
method to start publishing the stream.ZegoVideoConfig videoConfig = new ZegoVideoConfig();
videoConfig.codecID = ZegoVideoCodecID.SVC;
engine.setVideoConfig(videoConfig);
String streamID = "MultiLayer-1";
engine.startPublishingStream(streamID);
With SVC enabled for the stream publisher, you can call the setPlayStreamVideoType
method before or after the stream playing, and the stream subscribers by default receive and decode the most appropriate video quality layers of the stream according to the current network conditions, for example, you will receive and decode the stream of the base layer in the poor network condition.
You can explicitly specify which video quality layers to receive and decode when needed by passing the specific parameters.
The following are the supported video layers:
Enumerated value | Description |
---|---|
ZegoVideoStreamType.DEFAULT | Select the video quality layer automatically according to network conditions. |
ZegoVideoStreamType.SMALL | Select the base layer (smaller resolution). |
ZegoVideoStreamType.BIG | Select the enhancement layer (larger resolution). |
The following is the sample code of selecting the enhancement layer (larger resolution):
engine.setPlayStreamVideoType(playStreamID,ZegoVideoStreamType.BIG);
engine.startPlayingStream(playStreamID);
Because a few types of devices cannot achieve the best effect using the hardware codec (encoding/decoding), the ZEGO SDK uses software codec by default. If you need to use the hardware codec, refer to this section for settings.
To enable the hardware encoding, call the enableHardwareEncoder
method.
This feature only takes effect when it is set before the stream publishing. If it is set after the stream is published, you will need to stop publishing the stream and publish the stream again to make this feature works.
// Enable the hardware encoding.
engine.enableHardwareEncoder(true);
To enable the hardware decoding, call the enableHardwareDecoder
method.
This feature only takes effect when it is set before the stream playing. If it is set after the stream is played, you will need to stop playing the stream and play the stream again to make this feature works.
// Enable the hardware decoding.
engine.enableHardwareDecoder(true);
To set the video codec type, do the following:
setVideoConfig
method and set the codecID
property of the ZegoVideoConfig
class.startPublishingStream
method to start publishing the stream.The following are the supported video codec types:
Enumerated value | Codec | Scenario |
---|---|---|
ZegoVideoCodecID.DEFAULT | The default codec (H.264 ). |
H.264 is a widely used video codec type for high precision video recording, compression, and publishing, with good compatibility. |
ZegoVideoCodecID.SVC | SVC (H.264, SVC ) |
Scenarios that require the use of SVC. |
ZegoVideoCodecID.VP8 | VP8 | Commonly used for the video on webpages. |
ZegoVideoCodecID.H265 | H.265 |
With better compression, but compatibility needs to be considered. |
The following is the sample code of setting the video codec type to H.265
:
ZegoVideoConfig videoConfig = new ZegoVideoConfig();
videoConfig.codecID = ZegoVideoCodecID.H265;
engine.setVideoConfig(videoConfig);
String streamID = "MultiLayer-1";
engine.startPublishingStream(streamID);
What is the difference between the basic representation and the enhanced representation of the same video in resolution and bitrate with SVC?
Currently, the ZEGO Express-Video SDK supports one basic layer and one enhancement layer. So, with SVC, you can have two representations of the same video:
The basic representation that contains only the base layer The enhanced representation that contains both the base layer and the enhancement layer They have the following differences in resolution and bitrate:
The width and height of the resolution of the basic representation is 50% of that of the enhanced representation. So the frame size (width x height) of the basic representation is 25% of that of the enhanced representation. Accordingly, the bitrate of the basic representation is also approximately 25% of that of the enhanced representation. No differences in other aspects. For example:
If you set the encoding resolution to 800 × 600, it will be the resolution of the enhanced layer, and the resolution of the base layer is 400 × 300.
Does SVC work when subscribing to streams from CDNs? Which quality layer do the stream subscribers receive when subscribing to a stream from CDNs?
ZEGO uses private protocols for SVC. That means you can use the SVC feature only when subscribing to streams from ZEGO's streaming media servers.
ZEGO uses private protocols for SVC. That means you can use the SVC feature only when subscribing to streams from ZEGO's streaming media servers.
If you enable stream forwarding to CDN for your app, ZEGO's streaming media servers forward the higher-quality representation of the streams (base layer + enhancement layers) to the CDN. So the streams that the subscribers receive from the CDN are the ones at the higher quality level.
What are the advantages and disadvantages of SVC?
Advantages | Disadvantages |
---|---|
|
|
Difference | H.264 | H.265 |
---|---|---|
Bitrate with same image quality |
- |
H.265 can save 30% bitrate (measured value) compared to H.264. |
Soft coding |
- |
H.265 consumes three times as much computing power as H.264. |
Soft decoding |
- |
H.265 consumes 1.5 times as much computing power as H.264. |
Hard coding & decoding |
All models supports hard coding and decoding. |
Most of models do not support hard decoding. |
Output mixed stream |
Supported |
Supported, but will be more expensive than H.264. For details, contact our sales. |
Scenario |
All |
Recommended: live streaming, interactive audio and video streaming. |