How to package content for DASH

更新时间:
复制 MD 格式

DASH (Dynamic Adaptive Streaming over HTTP) packaging generates a Master Playlist file from video streams that contain multiple captions, audio tracks, and bitrates. During playback, a client can dynamically select the optimal video segment based on its network conditions. This process improves video quality when bandwidth fluctuates. This topic describes how to create a DASH packaging workflow and process a video by calling the AddMedia API operation.

Usage notes

You can create DASH packaging workflows only by calling an API operation, not in the console. After a workflow is created, you can view and use it in the console. For more information, see Add a media workflow.

Procedure

  1. When you create a workflow, note the following activities. For more information about the API operation for creating a workflow, see Add a media workflow.

    Note

    You only need to set up the workflow once. You can then use it for multiple packaging jobs.

    Object

    Description

    Topology

    The topology is a customizable Directed Acyclic Graph (DAG) that defines the business processing flow.

    Activity

    An activity is a processing node in the topology. For information about the activities to note when you create a DASH packaging workflow, see the activity description table below.

    Dependencies

    A dependency is an edge in the topology that specifies the relationship between activities.

    Table 1. Activity descriptions

    Activity

    Description

    Dependencies

    PackageConfig activity

    Specifies the DASH packaging configuration and sets the output location for the Master Playlist file.

    • Allowed preceding node: Start.

    • Allowed following nodes: SubtitleGroup, AudioGroup, and VideoGroup.

    SubtitleGroup activity

    Specifies the caption group ID and language.

    • Allowed preceding node: PackageConfig.

    • Allowed following node: Transcode (captions only).

    AudioGroup activity

    Specifies the audio group ID and language.

    • Allowed preceding node: PackageConfig.

    • Allowed following node: Transcode (audio only).

    VideoGroup activity

    Specifies the video group ID.

    • Allowed preceding node: PackageConfig.

    • Allowed following node: Transcode (video only).

    Transcode activity

    Extracts video, audio, and caption streams.

    • Allowed preceding nodes: SubtitleGroup, AudioGroup, and VideoGroup.

    • Allowed following node: GenerateMasterPlayList.

    GenerateMasterPlayList activity

    You can package and generate the activity.

    • Allowed preceding node: Transcode.

    • Allowed following node: Report.

  2. Call the AddMedia API operation and note the following points:

    • Specify the media workflow ID.

    • To extract captions, set the OverrideParams parameter to overwrite the subtitle file address in the Transcode activity for captions. For example: {"subtitleTransNode":{"InputConfig":{"Format":"stl","InputFile":{"URL":"http://example-bucket-****.oss-cn-hangzhou.aliyuncs.com/package/subtitle/CENG.stl"}}}}. In this example, subtitleTransNode is the caption extraction node defined in the workflow.

    • Set the workflow trigger mode to NotInAuto.

Scenario

This scenario uses a source file in MXF format, or another format such as MP4, FLV, or M3U8(TS). Three audio tracks, two video streams, and two WebVTT caption tracks are extracted from the source file. These tracks and streams are then packaged into a single Master Playlist.

Set the location and name of the output Master Playlist for DASH packaging.

  • You can set the bucket.

  • You can set the location.

  • You can set the name of the Master Playlist.

  • The activity is defined as follows:

    
    {
    "Parameters" : {
    "Output" : "{\"Bucket\": \"exampleBucket****\",\"Location\": \"oss-cn-hangzhou\",\"MasterPlayListName\": \"{MediaId}/{RunId}/dash/master.mpd\"}"
    },
    "Type" : "PackageConfig"
    }

Activity definition:


"audio-cn-group" : {
"Name" : "audio-cn-group",
"Parameters" : {
"AdaptationSet" : "{\"Lang\":\"chinese\",\"Group\":\"AudioGroupChinese\"}"
},
"Type" : "AudioGroup"
}
  • Group: Specifies the audio group ID. For example, AudioGroupChinese.

  • Type: Specifies that the activity type is AudioGroup.

You can extract the audio track.

  • Extracts the audio stream from the MXF source file and removes the video stream.

  • Parameters for the output audio stream.

    Activity definition:

    
    "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 destination URI for the extracted audio stream.

    • AudioStreamMap: The audio stream selector. For more information, see Output details.

    • Removes the video stream from the output. For more information, see Parameter details.

    • Set Type to Transcode to indicate a transcoding activity.

Video group


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

You can retrieve the video.

  • Extracts the video stream from the MXF source file and removes the audio stream.

  • Activity definition:

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

    • Removes the audio stream from the output. For more information, see Parameter details.

    • URI: The name and storage address of the extracted video stream.

    • Set Type to Transcode to indicate a transcoding activity.

Group of captions.

  • Set the caption group ID.

  • Activity definition

    
    "subtitle-cn-group" : {
    "Name" : "subtitle-cn-group",
    "Parameters" : {
    "AdaptationSet" : "{\"Lang\":\"Chinese\", \"Group\":\"SubtitleENGroup\"}"
    },
    "Type" : "SubtitleGroup"
    }
    • Group: Specifies the name of the audio group. Set this parameter to SubtitleENGroup.

    • Lang: The language of the caption group.

    • Type: The activity type, which must be SubtitleGroup.

You can fetch captions.

  • You can upload captions in STL, TTML, or WebVTT format to OSS.

  • Activity definition:

    
    "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 specifies the caption address. This address can be dynamically overwritten by the OverrideParams parameter when you call the AddMedia API operation.

    • URI: The name and output folder for the extracted caption stream.

    • You can set Type to Transcode, which indicates a transcoding activity.

Master Playlist Output.

  • Packages all extracted and transformed audio, video, and caption resources into a single Master Playlist.

  • Activity definition:

    
    {
    "Parameters" : {
    },
    "Type" : "GenerateMasterPlayList"
    }
    • Set Type to GenerateMasterPlayList, which specifies that the activity generates the Master Playlist.

The following figure shows the topology diagram:拓扑图

The following is the topology for the complete example 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 media.