All Products
Search
Document Center

ApsaraVideo Media Processing:Perform DASH packaging

Last Updated:Mar 12, 2024

Dynamic Adaptive Streaming Over HTTP (DASH) packaging allows you to generate a master playlist for multiple video streams at different bitrates, caption streams, and audio streams. This way, a client can request the most suitable clip for playback based on the network conditions. This greatly improves the video quality during network jitters. This topic describes how to create a DASH packaging workflow. Then, you can specify the ID of the DASH packaging workflow when you call the AddMedia operation to use the workflow to process videos.

Usage notes

You can create a DASH packaging workflow only by calling an API operation. You cannot create a DASH packaging workflow in the ApsaraVideo Media Processing (MPS) console. However, you can view and use the created DASH packaging workflow in the MPS console. For more information, see AddMediaWorkflow.

Procedure

  1. Create a DASH packaging workflow. When you create a DASH packaging workflow, take note of the objects described in the following table. For more information about the API operation that is used to create a workflow, see AddMediaWorkflow.

    Note

    You need to create only one workflow if you want to perform DASH packaging multiple times.

    Object

    Description

    Topology

    The business process that is defined by using a directed acyclic graph (DAG).

    Activity

    The nodes that constitute the topology. When you create a DASH packaging workflow, pay attention to the activities described in the following table.

    Dependencies

    The edges in the topology. The edges indicate the dependencies among activities.

    Table 1. DASH packaging activities

    Activity

    Description

    Dependency

    PackageConfig

    Specifies the location for storing the output master playlist.

    • Supported parent node: Start

    • Supported child nodes: SubtitleGroup, AudioGroup, and VideoGroup

    SubtitleGroup

    Specifies the ID and language of each caption group.

    • Supported parent node: PackageConfig

    • Supported child node: Transcode for caption streams only

    AudioGroup

    Specifies the ID and language of each audio group.

    • Supported parent node: PackageConfig

    • Supported child node: Transcode for audio streams only

    VideoGroup

    Specifies the ID of each video group.

    • Supported parent node: PackageConfig

    • Supported child node: Transcode for video streams only

    Transcode

    Extracts video, audio, or caption streams.

    • Supported parent nodes: SubtitleGroup, AudioGroup, and VideoGroup

    • Supported child node: GenerateMasterPlayList

    GenerateMasterPlayList

    Generates a master playlist.

    • Supported parent node: Transcode

    • Supported child node: Report

  2. Call the AddMedia operation to trigger the DASH packaging workflow. Take note of the following items:

    • You must specify the ID of the DASH packaging workflow when you call the AddMedia operation.

    • For caption stream extraction, you can configure the OverrideParams parameter to overwrite the URL of the default caption file specified in the Transcode node. Example: {"subtitleTransNode":{"InputConfig":{"Format":"stl","InputFile":{"URL":"http://example-bucket-****.oss-cn-hangzhou.aliyuncs.com/package/subtitle/CENG.stl"}}}}. In this example, sutitleTransNode is the node that is used to extract caption streams.

    • Set the TriggerMode parameter of the workflow to NotInAuto.

Scenario

In this example, two video streams and three audio streams are extracted from a source file in the MXF format. The source file can also be in the MP4, FLV, M3U8, or TS format. Then, two WebVTT caption streams are extracted, and a master playlist is generated for the video streams, audio streams, and caption streams.

Configure the output location and the name of the master playlist.

  • Specify the Object Storage Service (OSS) bucket in which the master playlist file is to be stored.

  • Specify the location of the master playlist.

  • Specify the name of the master playlist.

  • Sample code:

    
    {
    "Parameters" : {
    "Output" : "{\"Bucket\": \"exampleBucket****\",\"Location\": \"oss-cn-hangzhou\",\"MasterPlayListName\": \"{MediaId}/{RunId}/dash/master.mpd\"}"
    },
    "Type" : "PackageConfig"
    }
    • Output: the output location and name of the master playlist. For more information, see Methods supported for media workflows.

    • Type: the activity type. In this example, this value is set to PackageConfig.

Sample code:


"audio-cn-group" : {
"Name" : "audio-cn-group",
"Parameters" : {
"AdaptationSet" : "{\"Lang\":\"chinese\",\"Group\":\"AudioGroupChinese\"}"
},
"Type" : "AudioGroup"
}
  • Group: the ID of the audio group. In this example, the value is set to AudioGroupChinese.

  • Type: the activity type. In this example, the value is set to AudioGroup.

Extract audio streams.

  • To extract audio streams from the MXF source file, you must remove the video streams.

  • The following sample code defines the Transcode activity for extracting the audio streams:

    
    "audioCNTransNode" : {
    "Name" : "audioCNTransNode",
    "Parameters" : {
    "Outputs" : "[{\"TemplateId\":\"d053297fc44f9DashTempla****\",\"AudioStreamMap\":\"0:a:0\",\"Video\":{\"Remove\":\"true\"}}]",
    "Representation" : "{\"Id\":\"chinese128k\",\"URI\":\"audiocn/cn-abc.mpd\"}"
    },
    "Type" : "Transcode"
    }
    • URI: the location of the extracted audio stream.

    • AudioStreamMap: the sequence number of the audio stream. For more information, see Output.

    • Remove video streams from the output. For more information, see Parameter details.

    • Type: the activity type. In this example, the value is set to Transcode.

Group video streams.


"video-group" : {
"Name" : "video-group",
"Parameters" : {
"AdaptationSet" : "{\"Group\":\"VideoGroup\"}"
},
"Type" : "VideoGroup"
}

Extract video streams.

  • To extract video streams from the MXF source file, you must remove the audio streams.

  • Sample code:

    
    "videoTransSD" : {
    "Name" : "videoTransSD",
    "Parameters" : {
    "Outputs" : "[{\"TemplateId\":\"d861b90f6c0aed8f81095e5c5b85****\",\"Audio\":{\"Remove\":\"true\"}}]",
    "Representation" : "{\"Id\":\"476pSD\",\"URI\":\"videoSD/****.mpd\"}"
    },
    "Type" : "Transcode"
    } 
    • In this example, the ID of the custom transcoding template is d861b90f6c0aed8f81095e5c5b857cba. You can call the corresponding API operation to create a transcoding template. The container format is MPD.

    • Remove: specifies whether to remove the audio streams from the output. For more information, see Parameter details.

    • URI: the name and location of the extracted video stream.

    • Type: the activity type. In this example, the value is set to Transcode.

Group caption streams.

  • Specify the ID of the caption group.

  • Sample code:

    
    "subtitle-cn-group" : {
    "Name" : "subtitle-cn-group",
    "Parameters" : {
    "AdaptationSet" : "{\"Lang\":\"Chinese\", \"Group\":\"SubtitleENGroup\"}"
    },
    "Type" : "SubtitleGroup"
    }
    • Group: the name of the caption group. In this example, the value is set to SubtitleENGroup.

    • Lang: the language of the caption group.

    • Type: the activity type. In this example, the value is set to SubtitleGroup.

Extract caption streams.

  • Upload captions in the STL, TTML, or WebVTT format to OSS.

  • Sample code:

    
    "subtitleCNNode" : {
    "Name" : "subtitleCNNode",
    "Parameters" : {
    "InputConfig" : "{\"Format\":\"vtt\",\"InputFile\":{\"URL\":\"http://exampleBucket****.oss-cn-hangzhou.aliyuncs.com/test/Audio-SiHD.chs.vtt\"}}",
    "Representation" : "{\"Id\":\"subtitle-chinese\", \"URI\":\"subtitle/cn-xx.vtt\"}"
    },
    "Type" : "Transcode"
    }
    • InputConfig: the URL of the caption file. The URL can be overwritten by configuring the OverrideParams parameter when you call the AddMedia operation.

    • URI: the location of the extracted caption stream.

    • Type: the activity type. In this example, the value is set to Transcode.

Generate the master playlist.

  • Generate a master playlist for all the extracted audio, video, and caption streams.

  • Sample code:

    
    {
    "Parameters" : {
    },
    "Type" : "GenerateMasterPlayList"
    }
    • Type: the activity type. In this example, the value is set to GenerateMasterPlayList.

The following sample code describes the topology of the entire scenario:


{
"Activities": {
"act-package": {
"Name": "act-package",
"Parameters": {
"Output": "{\"Bucket\": \"outputbucketname\",\"Location\": \"oss-cn-hangzhou\",\"MasterPlayListName\": \"dashpackage/{MediaId}/{RunId}/master.mpd\"}",
"Protocol": "dash"
},
"Type": "PackageConfig"
},
"video-group": {
"Name": "video-group",
"Parameters": {
"AdaptationSet": "{\"Group\":\"VideoGroup\"}"
},
"Type": "VideoGroup"
},
"audio-en-group": {
"Name": "audio-en-group",
"Parameters": {
"AdaptationSet": "{\"Lang\":\"english\", \"Group\":\"AudioGroupEnglish\"}"
},
"Type": "AudioGroup"
},
"audio-cn-group": {
"Name": "audio-cn-group",
"Parameters": {
"AdaptationSet": "{\"Lang\":\"chinese\", \"Group\":\"AudioGroupChinese\"}"
},
"Type": "AudioGroup"
},
"subtitle-en-group": {
"Name": "subtitle-en-group",
"Parameters": {
"AdaptationSet": "{\"Lang\":\"english\", \"Group\":\"SubtitleENGroup\"}"
},
"Type": "SubtitleGroup"
},
"subtitle-cn-group": {
"Name": "subtitle-cn-group",
"Parameters": {
"AdaptationSet": "{\"Lang\":\"chinese\", \"Group\":\"SubtitleCNGroup\"}"
},
"Type": "SubtitleGroup"
},
"videoTransLD": {
"Name": "videoTransLD",
"Parameters": {
"Outputs": "[{\"TemplateId\":\"d053297fc44f9dd6becd4a98d1c42f50\",\"Audio\":{\"Remove\":\"true\"}}]",
"Representation": "{\"Id\":\"270pLD\", \"URI\":\"videoLD/xx.mpd\"}"
},
"Type": "Transcode"
},
"videoTransSD": {
"Name": "videoTransSD",
"Parameters": {
"Outputs": "[{\"TemplateId\":\"d861b90f6c0aed8f81095e5c5b85****\",\"Audio\":{\"Remove\":\"true\"}}]",
"Representation": "{\"Id\":\"480pSD\", \"URI\":\"videoSD/****.mpd\"}"
},
"Type": "Transcode"
},
"videoTransHD": {
"Name": "videoTransHD",
"Parameters": {
"Outputs": "[{\"TemplateId\":\"117b3ae88efbc97df372cfd9a0e1****\",\"Audio\":{\"Remove\":\"true\"}}]",
"Representation": "{\"Id\":\"720pHD\", \"URI\":\"videoHD/****.mpd\"}"
},
"Type": "Transcode"
},
"audioCNTransNode": {
"Name": "audioCNTransNode",
"Parameters": {
"Outputs": "[{\"TemplateId\":\"d053297fc44f9dd6becd4a98d1c4****\",\"AudioStreamMap\":\"0:a:0\",\"Video\":{\"Remove\":\"true\"}}]",
"Representation": "{\"Id\":\"chinese128k\", \"URI\":\"audiocn/cn-abc.mpd\"}"
},
"Type": "Transcode"
},
"audioENTransNode": {
"Name": "audioENTransNode",
"Parameters": {
"Outputs": "[{\"TemplateId\":\"d053297fc44f9dd6becd4a98d1c4****\",\"AudioStreamMap\":\"0:a:1\",\"Video\":{\"Remove\":\"true\"}}]",
"Representation": "{\"Id\":\"english128k\", \"URI\":\"audioen/en-abc.mpd\"}"
},
"Type": "Transcode"
},
"subtitleENNode": {
"Name": "subtitleENNode",
"Parameters": {
"InputConfig": "{\"Format\":\"vtt\",\"InputFile\":{\"URL\":\"http://exampleBucket****.oss-cn-hangzhou.aliyuncs.com/dashpackage/subtitle/Subtitle****.EN.vtt\"}}",
"Representation": "{\"Id\":\"subtitle-english\", \"URI\":\"subtitle/en-****.vtt\"}"
},
"Type": "Transcode"
},
"subtitleCNNode": {
"Name": "subtitleCNNode",
"Parameters": {
"InputConfig": "{\"Format\":\"vtt\",\"InputFile\":{\"URL\":\"http://exampleBucket****.oss-cn-hangzhou.aliyuncs.com/dashpackage/subtitle/Subtitle.CN.vtt\"}}",
"Representation": "{\"Id\":\"subtitle-chinese\", \"URI\":\"subtitle/cn-****.vtt\"}"
},
"Type": "Transcode"
},
"act-report": {
"Name": "act-report",
"Parameters": {
"PublishType": "Auto"
},
"Type": "Report"
},
"act-start": {
"Name": "act-start",
"Parameters": {
"PipelineId": "cc7fcef2562e4abc9332d491f933****",
"InputFile": "{\"Bucket\":\"exampleBucket****\",\"Location\":\"oss-cn-hangzhou\",\"ObjectPrefix\":\"package/dash/\"}"
},
"Type": "Start"
},
"generateMasterPlayListAct": {
"Name": "generateMasterPlayListAct",
"Parameters": {},
"Type": "GenerateMasterPlayList"
}
},
"Dependencies": {
"audio-en-group": ["audioENTransNode"],
"video-group": ["videoTransLD", "videoTransSD", "videoTransHD"],
"audio-cn-group": ["audioCNTransNode"],
"audioCNTransNode": ["generateMasterPlayListAct"],
"subtitleENNode": ["generateMasterPlayListAct"],
"act-package": ["audio-en-group", "audio-cn-group", "subtitle-cn-group", "subtitle-en-group", "video-group"],
"act-report": [],
"videoTransSD": ["generateMasterPlayListAct"],
"videoTransHD": ["generateMasterPlayListAct"],
"subtitle-en-group": ["subtitleENNode"],
"subtitle-cn-group": ["subtitleCNNode"],
"subtitleCNNode": ["generateMasterPlayListAct"],
"act-start": ["act-package"],
"videoTransLD": ["generateMasterPlayListAct"],
"generateMasterPlayListAct": ["act-report"],
"audioENTransNode": ["generateMasterPlayListAct"]
}
}

Sample code

  1. Create a DASH packaging workflow.

  2. Add a media file.