Video Call
  • iOS
  • Android : Java
  • Web
  • Flutter
  • React Native
  • Electron
  • Unity3D
  • Cocos Creator
  • Windows
  • macOS
  • Linux
  • Overview
  • Develop your app
    • Quick start
    • Enhance basic feature
      • Use Tokens for authentication
      • Config your video based on scenes
      • Check the room connection status
      • Set up common video config
      • Set up common audio config
  • Best practices
    • Implement a video call for multiple users
    • Implement call invitation
    • Implement a live audio room
  • Upgrade using advanced features
    • Advanced features
      • Configure the video
        • Watermark the video/Take snapshots
        • Improve your appearance in the video
        • Beautify & Change the voice
        • Configure video codec
        • Output the video in H.265
      • Improve video quality
        • Configure bandwidth management
        • Test network and devices in advance
        • Visualize the sound level
        • Monitor streaming quality
      • Message signaling
        • Convey extra information using SEI
        • Broadcast real-time messages to a room
        • Quotas and limits
      • Play media files
        • Play media files
        • Play sound effects
      • Share the screen
      • Mix the video streams
      • Publish multiple video streams
      • Encrypt the video streams
      • Record video media data
    • Distincitve features
      • Join multiple rooms
      • Customize the video and audio
      • Set the voice hearing range
      • Transfer traffic via the cloud proxy server
      • Use the bit mask
      • Play streams via URL
      • Play a transparent gift special effect
      • AI Voice Changer
      • In-game voice chat
  • Upgrade using Add-on
  • Resources & Reference
    • SDK
    • Sample codes
    • API reference
      • Client APIs
      • Server APIs
    • Debugging
      • Error codes
      • Logging/Version number
    • FAQs
    • Key concepts
  • Documentation
  • Video Call
  • Upgrade using advanced features
  • Advanced features
  • Configure the video
  • Configure video codec

Configure video codec

Last updated:2023-05-17 19:00

Introduction

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:

  • Different end-user devices need to play the same live video stream at different quality levels.
  • End-user devices need to dynamically switch to the most appropriate quality level of the video stream according to the current network conditions, which helps maintain a smooth streaming experience even under poor network conditions.

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:

  • For general scenarios, use the default video codec type.
  • In the case of the same resolution and frame rate, if the bit rate needs to be reduced, use the H.265.
  • When your app needs to be applied as mini-programs, use the H.264.

Prerequisites

Before you implement the video codec feature, make sure you complete the following steps:

  • ZEGO Express SDK has been integrated into the project to implement basic real-time audio and video functions. For details, please refer to Quick start .
  • A project has been created in ZEGOCLOUD Console and applied for a valid AppID and AppSign. For details, please refer to Console - Project Information .

Enable scalable video coding (SVC)

To enable SVC before publishing a stream, do the following:

  1. Call the setVideoConfig method and set the codecID property of the ZegoVideoConfig accordingly.
  • To enable this feature, set the codecID property to ZegoVideoCodecID.SVC.
  • To disable this feature, set the codecID property to ZegoVideoCodecID.DEFAULT, ZegoVideoCodecID.VP8, or ZegoVideoCodecID.H265.
  1. Call the 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);

Enable hardware codec

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);

Set the video codec type

To set the video codec type, do the following:

  1. Call the setVideoConfig method and set the codecID property of the ZegoVideoConfig class.
  2. Call the 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);

FAQ

  1. 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.

  2. 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.

  3. What are the advantages and disadvantages of SVC?

Advantages Disadvantages
  • SVC can generate or extract different bitstreams at different quality levels as needed. To encode a video into multiple representations at different quality levels, it only needs to encode the video once with SVC, while it needs to perform encoding multiple times to achieve the same with ordinary encoding methods.
  • SVC is more flexible to use.
  • SVC makes video streaming more network adaptive.
  • SVC has a slightly lower compression efficiency: Under the same conditions, the compression efficiency of SVC is about 20% lower than that of ordinary encoding methods. That means, to achieve the same video quality (resolution and frame rate), the bitrate of the bitstream generated using SVC is 20% higher than that of ordinary encoding methods. The more layers in the encoded bitstream, the lower the compression efficiency. Currently, the ZEGO Express-Video SDK supports one basic layer and one enhancement layer.
  • SVC has a lower coding efficiency: Under the same conditions, SVC has a higher computational complexity than ordinary encoding methods, so the coding efficiency is about 10% lower than ordinary coding methods.
  • SVC does not support hardware encoding: SVC does not support hardware coding because it imposes a heavy computational burden on the CPU. But it supports hardware decoding.
  1. What are the differences between H.264 and H.265?
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.
Page Directory