Narrowband HD

更新时间:
复制 MD 格式

Narrowband HD uses content-adaptive encoding and perceptual optimization algorithms to reduce video bitrates and file sizes while maintaining the same subjective video quality. This reduces storage and bandwidth costs.

Features

Narrowband HD uses intelligent encoding optimization algorithms to improve the visual experience at the same bitrate. It can also significantly reduce the bitrate while maintaining video definition. This lowers bandwidth and storage costs. Compared to traditional transcoding, Narrowband HD delivers a lighter stream with higher definition. It is ideal for content delivery across various devices and scenarios and provides a smooth, high-definition playback experience.

Figure_3

Standard transcoding:

Size: 4,359,295 B Bitrate: 2,858 kbps VMAF: 92.938

Resolution: 1920x1080

Narrowband HD:

Size: 2,803,244 B

Bitrate: 1,838 kbps VMAF: 97.417

How to use

Prerequisites

Narrowband HD transcoding

Narrowband HD transcoding is supported only for asynchronous processing using the Java, Python, or Go SDK.

Java

The Java SDK 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 Python SDK 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 Go SDK 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, see the `videoslim` parameter description in video transcoding service. The following sections provide usage examples.

Transcode a video to Narrowband HD in VBR mode

Transcoding information

  • Before transcoding

    • Video format: AVI

    • Video name: example.avi

  • Processing method: Narrowband HD

  • After transcoding

    • Video information

      • Video format: MP4

      • Video name: outobjprefix.mp4

      • Video stream format: H.265

      • Video resolution: 1920x1080

      • Video frame rate: 30 fps

      • Video bitrate: 2 Mbps

    • Audio information

      • Audio stream format: AAC

      • Audio bitrate: 100 kbps

      • Caption stream: Disabled

    • File storage path: oss://outbucket/outobjprefix.mp4

Processing example

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
 
// Perform Narrowband HD transcoding on example.avi. 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_b3V0b2JqcHJlZml4LnthdXRvZXh0fQ

Transcode a video to Narrowband HD in CRF mode

Transcoding information

  • Before transcoding

    • Video format: AVI

    • Video name: example.avi

  • Processing method

    • Transcoding duration: Start Narrowband HD transcoding at 1,000 ms into the input media file and continue for 60,000 ms.

    • Segmentation method: Segment the video into HLS files at 30-second intervals.

    • Transcoding completion notification: Send an MNS message.

  • After transcoding

    • Video information

      • Video format: HLS

      • Video stream format: H.264

      • CRF value: 23

    • Audio information

      • Audio format: AAC

      • Audio bitrate: 100 kbps

    • File storage path

      • TS file: oss://outbucket/outobjprefix-%d.ts

      • M3U8 file: oss://outbucket/outobjprefix.m3u8

Processing example

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 Narrowband 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