Light HD
Light HD uses content-adaptive encoding and perceptual optimization algorithms to reduce video bitrate and file size while maintaining the same subjective quality, thereby lowering storage and bandwidth costs.
Features
Light HD uses intelligent encoding optimization algorithms to improve visual quality at the same bitrate, or to reduce the bitrate while maintaining the same clarity, effectively lowering bandwidth and storage costs. Compared with traditional transcoding, Light HD produces a lighter stream at higher clarity, which suits content delivery across multiple devices and scenarios and keeps playback smooth and in high definition.

Standard transcoding: Size: 4,359,295 B Bitrate: 2,858 kbps VMAF: 92.938 | Resolution: 1920x1080 | Light HD: Size: 2,803,244 B Bitrate: 1,838 kbps VMAF: 97.417 |
Transcode videos with Light HD
Prerequisites
Intelligent Media Management (IMM) and the video transcoding service are activated.
Light HD transcoding
Light HD transcoding supports only asynchronous processing through the OSS SDK for Java, Python, or Go.
Java
The OSS SDK for Java must be version 3.17.4 or later.
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.AsyncProcessObjectRequest;
import com.aliyun.oss.model.AsyncProcessObjectResult;
import com.aliyuncs.exceptions.ClientException;
import java.util.Base64;
public class Demo {
public static void main(String[] args) throws ClientException {
// Set yourEndpoint to the endpoint of the region where the bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify a general-purpose Alibaba Cloud region ID, such as cn-hangzhou.
String region = "cn-hangzhou";
// Obtain access credentials from environment variables. Before running this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the bucket name, for example, examplebucket.
String bucketName = "examplebucket";
// Specify the name of the output video file.
String targetKey = "dest.avi";
// Specify the name of the source video file.
String sourceKey = "src.mp4";
// Create an OSSClient instance.
// When the OSSClient instance is no longer needed, call the shutdown method to release resources.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Build the video processing style string and video transcoding parameters.
String style = String.format("video/convert,f_avi,vcodec_h265,videoslim_1,pixfmt_yuv420p,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1");
// Build the asynchronous processing instruction.
String bucketEncoded = Base64.getUrlEncoder().withoutPadding().encodeToString(bucketName.getBytes());
String targetEncoded = Base64.getUrlEncoder().withoutPadding().encodeToString(targetKey.getBytes());
String process = String.format("%s|sys/saveas,b_%s,o_%s", style, bucketEncoded, targetEncoded);
// Create an AsyncProcessObjectRequest object.
AsyncProcessObjectRequest request = new AsyncProcessObjectRequest(bucketName, sourceKey, process);
// Execute the asynchronous processing task.
AsyncProcessObjectResult response = ossClient.asyncProcessObject(request);
System.out.println("EventId: " + response.getEventId());
System.out.println("RequestId: " + response.getRequestId());
System.out.println("TaskId: " + response.getTaskId());
} finally {
// Shut down the OSSClient.
ossClient.shutdown();
}
}
}
Python
The OSS SDK for Python must be version 2.18.4 or later.
# -*- coding: utf-8 -*-
import base64
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
def main():
# Set the endpoint to the one for the region where the bucket is located. For example, for China (Hangzhou), set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
# Obtain access credentials from environment variables. Before running this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the bucket name.
bucket_name = 'examplebucket'
# Specify a general-purpose Alibaba Cloud region ID, for example, cn-hangzhou.
region = 'cn-hangzhou'
# Create a bucket instance.
bucket = oss2.Bucket(auth, endpoint, bucket_name, region=region)
# Specify the name of the source video file.
source_key = 'src.mp4'
# Specify the name of the output video file.
target_key = 'dest.avi'
# Build the video processing style string and video transcoding parameters.
style = 'video/convert,f_avi,vcodec_h265,videoslim_1,pixfmt_yuv420p,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1'
process = "{0}|sys/saveas,o_{1}".format(style,
oss2.compat.to_string(base64.urlsafe_b64encode(
oss2.compat.to_bytes(target_key))).replace('=', ''))
# Call the asynchronous stream processing API.
try:
# Execute the asynchronous processing task.
result = bucket.async_process_object(source_key, process)
print(f"EventId: {result.event_id}")
print(f"RequestId: {result.request_id}")
print(f"TaskId: {result.task_id}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()
Go
The OSS SDK for Go must be version 3.0.2 or later.
package main
import (
"encoding/base64"
"fmt"
"os"
"strings"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Obtain access credentials from environment variables. Before running this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Create an OSSClient instance.
// Set yourEndpoint to the endpoint of your bucket. For example, for China (Hangzhou), set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. For other regions, specify the actual endpoint.
client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the name of the bucket where the video is stored, for example, examplebucket.
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
// Specify the name of the output video file.
targetObject := "dest.avi"
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the name of the source video file.
sourceObject := "src.mp4"
// Build the video processing style string and video transcoding parameters.
style := "video/convert,f_avi,vcodec_h265,videoslim_1,pixfmt_yuv420p,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1"
process := fmt.Sprintf("%s|sys/saveas,b_%v,o_%v", style, strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(bucketName)), "="), strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(targetObject)), "="))
fmt.Printf("%#v\n", process)
rs, err := bucket.AsyncProcessObject(sourceObject, process)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
fmt.Printf("EventId:%s\n", rs.EventId)
fmt.Printf("RequestId:%s\n", rs.RequestId)
fmt.Printf("TaskId:%s\n", rs.TaskId)
}
Related APIs
For more information about the videoslim parameter, see video transcoding service. The following sections provide usage examples.
Transcode a video to Light HD in VBR mode
Transcoding details
Input
Video format: AVI
Video name: example.avi
Method: Light HD
Output
Video stream
Format: MP4
File name: outobjprefix.mp4
Codec: H.265
Resolution: 1920x1080
Frame rate: 30 fps
Bitrate: 2 Mbps
Audio stream
Codec: AAC
Bitrate: 100 kbps
Captions: Disabled
Output location: oss://outbucket/outobjprefix.mp4
Sample request
POST /example.avi?x-oss-async-process HTTP/1.1
Host: video-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: SignatureValue
// Transcode example.avi with Light HD. The output is an MP4 file with an H.265 video stream (1920x1080, 30 fps, 2 Mbps) and an AAC audio stream (100 kbps). The caption stream is disabled. The output file is saved to oss://outbucket/outobjprefix.mp4.
x-oss-async-process=video/convert,f_mp4,vcodec_h265,videoslim_1,pixfmt_yuv420p,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1|sys/saveas,b_b3V0YnVja2V0,o_b3V0b2JqcHJlZml4LnthdXRvZXh0fQTranscode a video to Light HD in CRF mode
Transcoding details
Input
Video format: AVI
Video name: example.avi
Settings
Transcoding range: Transcode a 60,000 ms segment of the input file, starting from the 1,000 ms mark.
Segmentation: Segment the video into HLS files at 30-second intervals.
Completion notification: Send an event to an MNS topic.
Output
Video stream
Format: HLS
Codec: H.264
CRF value: 23
Audio stream
Codec: MP3
Bitrate: 100 kbps
Output location
TS file: oss://outbucket/outobjprefix-%d.ts
M3U8 file: oss://outbucket/outobjprefix.m3u8
Sample request
POST /example.avi?x-oss-async-process HTTP/1.1
Host: video-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: SignatureValue
// Transcode a 60-second segment of example.avi, starting from the 1-second mark. Use Light HD with H.264 video (CRF 23) and MP3 audio (100 kbps). Segment the output into HLS files every 30 seconds. Save the output to the outbucket bucket with the prefix outobjprefix. Send a notification to the AudioConvert topic.
x-oss-async-process=video/convert,ss_1000,t_60000,f_ts,vcodec_h264,videoslim_1,pixfmt_yuv420p,crf_23,acodec_mp3,ab_100000/segment,f_hls,t_30000|sys/saveas,b_b3V0YnVja2V0,o_b3V0b2JqcHJlZml4LnthdXRvZXh0fQ/notify,topic_QXVkaW9Db252ZXJ0