Adaptive bitrate streaming

更新时间:
复制 MD 格式

Adaptive bitrate streaming packages specified audio and video streams into a single adaptive stream file. This allows a player to automatically select the optimal stream for playback based on the user's network bandwidth. This topic describes how to transcode a video to generate an adaptive bitrate stream.

What is adaptive bitrate streaming?

Adaptive bitrate streaming packages multiple audio and video streams into a single adaptive stream file. This file contains information such as the bitrate and resolution of each stream. Compared with traditional single-bitrate playback, an adaptive bitrate file allows the player to select the most suitable stream for the current network conditions and device, improving the viewing experience.

Note

The most widely used output formats for adaptive bitrate streaming are HLS and DASH. ApsaraVideo VOD currently supports generating adaptive bitrate streams only in HLS format.

Demonstration

In playback preview mode, ApsaraVideo Player supports switching between definitions. Click the settings icon in the lower-right corner of the player to open the definition selection panel. The panel provides three options: standard definition, high definition, and Auto (high definition). In this example, Auto (high definition) is selected.

Template types

ApsaraVideo VOD provides two types of adaptive bitrate streaming templates: video stream packaging templates and subtitle packaging templates. For more information, see Transcoding templates.

Note

Subtitle packaging templates cannot be created or used independently. They must be used with a video packaging template.

  • Video stream packaging template

    • A video packaging template is used to package transcoded video output into HLS format and build the stream information into an adaptive bitrate file. This enables the player to select and switch between resolutions.

  • Subtitle packaging template

    • A subtitle packaging template is used to build information from multi-language subtitle files into the adaptive bitrate file. This enables the player to select and switch between subtitle languages.

    Note
    • Only the VTT format is supported for subtitle files.

    • To dynamically replace the subtitle files in a template during subtitle packaging, call the SubmitTranscodeJobs operation to override the parameters.

How to use

Console

Step 1: Create a template group

You must first create an adaptive bitrate transcoding template group for your transcoding jobs.

For more information, see Transcoding templates.

Step 2 (Optional): Create and associate a workflow

You can arrange various media processing tasks, such as transcoding, content review, and snapshotting, into a specific sequence within a workflow. When you trigger the workflow during or after a media upload, the workflow automatically processes the media file according to the predefined task sequence.

You can create a workflow, add a media transcoding node to it, and associate the node with the adaptive bitrate transcoding template group created in the previous step. For more information, see Manage workflows.

Step 3: Initiate transcoding

To transcode your video, use the transcoding template group or workflow created in the previous steps.

During upload

  1. Log on to the ApsaraVideo VOD console.

  2. In the left-side navigation pane, choose Media Files > Audio/video, and then click Upload audio/video.

  3. Click Add audio/video, configure parameters such as the upload method and storage location, and then select Use Transcoding Template Group or Use Workflow. Specify the adaptive bitrate transcoding template group or workflow you created.

    For more information about supported formats and parameter settings, see Upload media files in the console.

  4. After you add the audio and video files to upload, click Upload.

After upload

This operation is typically used to re-transcode existing videos, apply standard encryption, or override watermark parameters.

  1. Log on to the ApsaraVideo VOD console.

  2. In the left-side navigation pane, choose Media Files > Audio/video.

  3. On the Audio/Video page, find the audio or video file to transcode and click Processing in the Actions column.

  4. Select Use Transcoding Template Group or Use Workflow and specify the adaptive bitrate transcoding template group or workflow. In the Media Processing dialog box that appears, set Processing Type to Use transcoding template group and set Transcoding Template Group to Multi-bitrate packaging.

  5. Click OK.

Step 4: View results

After a transcoding job starts, use one of the following methods to check its status and retrieve the playback URLs of the transcoded videos. You can use these playback URLs with ApsaraVideo Player or a third-party player.

Important

If you do not configure an accelerated domain name in ApsaraVideo VOD, you incur charges for outbound traffic when playing or downloading videos from their playback URLs. For more information, see Billing of outbound traffic.

Method 1: Console

  1. Log on to the ApsaraVideo VOD console.

  2. In the left-side navigation pane, choose Media Files > Audio/video.

  3. On the Audio/Video page, check the status of the transcoded media file.

    A status of Normal indicates that transcoding was completed successfully. For the definitions of other statuses, see Status: video status.

  4. Click Manage in the Actions column of the transcoded media file and go to the Video URL tab.

    A successfully transcoded video generates one adaptive stream, multiple transcoded streams, and their corresponding playback URLs.

    After transcoding is complete, the table on the Video URL tab displays the original file (MP4) and the three generated output streams: standard definition, high definition (in m3u8 format), and Adaptive. The table shows the definition, format, resolution, bitrate, URL, and size for each stream.

Method 2: Event notifications

ApsaraVideo VOD supports event notifications through HTTP/HTTPS callbacks and MNS messages. By configuring event notifications, you will be promptly notified when a media file is processed, for example, when an upload or transcoding is complete. You can obtain the status of transcoding jobs and the playback URLs of transcoded videos from the callback results. For configuration instructions, see Event notifications.

The following events are related to transcoding:

API

Usage

For information about how to call API operations, see ApsaraVideo VOD API overview. We recommend that you use OpenAPI Explorer, an online API debugging tool provided by Alibaba Cloud. You can use OpenAPI Explorer to run ApsaraVideo VOD API operations directly without calculating signatures. After a request succeeds, OpenAPI Explorer automatically generates sample code for the SDKs.

Step 1: Create an adaptive bitrate template group

You must first create an adaptive bitrate transcoding template group for your transcoding jobs.

  1. Call the AddTranscodeTemplateGroup operation and use the TranscodeTemplate parameter to configure the packaging template.

    Only the specific parameters for packaging templates are described here. For more information about all parameters, see TranscodeTemplate: Transcoding template configuration.

    View the packaging template parameters

    Video packaging parameters

    API parameter

    Console parameter

    Description

    PackageType

    Packaging type

    The packaging type of the adaptive bitrate stream. The output can be in HLS or DASH format. Valid values: HLSPackage (HLS packaging) and DASHPackage (DASH packaging).

    Note

    Currently, only HLSPackage is supported.

    BandWidth

    Bandwidth threshold

    The bandwidth threshold that the player uses to select a stream for playback based on the current network bandwidth. Unit: bps.

    Note

    This is a parameter for video packaging templates.

    Subtitle packaging parameters

    Parameter

    Console parameter

    Description

    Language

    Language

    The subtitle language, such as ja (Japanese) and en-US (English). The value must follow the RFC 5646 specification.

    Note

    This is a parameter for subtitle packaging templates.

    Name

    Display name

    The display name for the subtitle language in the player, such as Chinese or English.

    Format

    Subtitle format

    The file extension of the subtitle file. For HLS packaging, only the VTT format is supported.

    Example: subtitle.vtt

    SubtitleUrlList

    Subtitle URL

    The full OSS URL of the subtitle file, which must be stored in the ApsaraVideo VOD system bucket. CDN domain names and HTTPS URLs are not supported.

    Example: http://example-bucket-****.oss-cn-shanghai.aliyuncs.com/subtitles/4dba87c2-a787-42cd-8328-2369aeb8****-cn.vtt

    Note

    This is a parameter for subtitle packaging templates.

Step 2: (Optional) Create and associate a workflow

You can arrange various media processing tasks, such as transcoding, content review, and snapshotting, into a specific sequence within a workflow. When you trigger the workflow during or after a media upload, the media file is automatically processed according to the predefined task sequence.

Currently, workflows can be created only in the ApsaraVideo VOD console. For more information, see Manage workflows.

Step 3: Initiate transcoding

To transcode your video, use the transcoding template group or workflow created in the previous steps.

During upload

Note

The CreateUploadVideo operation is used only to obtain upload URLs and credentials and to create basic media asset information. It does not upload files. You must implement your own upload logic. For a complete example of uploading media files by calling API operations, see Upload media files by using the ApsaraVideo VOD API.

  1. When calling the CreateUploadVideo or UploadMediaByURL operation to upload a media file, specify the transcoding template group ID in the TemplateGroupId parameter, or specify the ID of a workflow that contains a transcoding node in the WorkflowId parameter. After the upload is complete, ApsaraVideo VOD automatically initiates transcoding based on the specified template group or workflow.

After upload

This operation is typically used to re-transcode existing videos, apply standard encryption, or override watermark parameters.

  1. Call the SubmitTranscodeJobs operation and specify the transcoding template group ID in the TemplateGroupId parameter. Alternatively, call the SubmitWorkflowJob operation and specify the ID of a workflow that contains a transcoding node in the WorkflowId parameter. After you manually initiate the job, ApsaraVideo VOD immediately starts transcoding the media file based on your settings.

Step 4: View results

After a transcoding job starts, use one of the following methods to check its status and retrieve the playback URLs of the transcoded videos. You can use these playback URLs with ApsaraVideo Player or a third-party player.

Important

If you do not configure an accelerated domain name in ApsaraVideo VOD, you incur charges for outbound traffic when playing or downloading videos from their playback URLs. For more information, see Billing of outbound traffic.

Method 1: API query

Calling the SubmitTranscodeJobs operation to submit a transcoding job returns a transcoding task ID (TranscodeTaskId). You can then call the GetTranscodeTask operation to query the job status and the playback URLs of the output videos.

Method 2: Event notifications

ApsaraVideo VOD supports event notifications through HTTP/HTTPS callbacks and MNS messages. By configuring event notifications, you will be promptly notified when a media file is processed, for example, when an upload or transcoding is complete. You can obtain the status of transcoding jobs and the playback URLs of transcoded videos from the callback results. For configuration instructions, see Event notifications.

The following events are related to transcoding:

Next steps

After you configure the player for adaptive bitrate streaming, provide the generated adaptive stream to the player for playback. The player can then automatically switch between video definitions based on network conditions, or allow users to manually switch definitions and subtitles.

To learn how to configure this feature in the ApsaraVideo Player SDK, see the following topics: