Introduction

HLS package refers to the process in which multi-subtitle, multi-track and multi-bitstream are integrated into a Master Playlist file. The process includes creating HLS package workflow and calling AddMedia interface to specify video and the ID of the HLS package workflow for video processing.

  1. When you use AddMediaWorkflow interface to add workflow, pay attention to the following objects:
    • Topology

      Topology refers to the business processing procedure, Directed Acyclic Graph (DAG).

    • Activity

      Activity refers to the processing nodes which constitute the topology. While creating HLS package workflow, pay attention to the following activities:

      • PackageConfig

        Specify HLS package configuration, and configure the output location for the Master Playlist file

        .

        • The front node allows: Start.

        • The back node allows: SubtitleGroup, AudioGroup, and Transcode (only video).

      • SubtitleGroup

        Specify the subtitle group ID

        .

        • The front node allows: PackageConfig.

        • The back node allows: Transcode (only subtitle).

      • AudioGroup

        Specify the audio group ID

        .

        • The front node allows: PackageConfig.

        • The back node allows: Transcode (only audio).

      • Transcode

        Extract video streams/audio stream/subtitle stream.

        .

        • The front node allows: PackageConfig, SubtitleGroup, and AudioGroup.

        • The back node allows: GenerateMasterPlayList.

      • GenerateMasterPlayList

        HLS package generation activity specifies multi-ratestream configuration, audio group and subtitle group

        .

        • The front node allows: Transcode.

        • The back node allows: Report.

    • Dependencies

      Dependencies refer to the edges of the topology, indicating the dependency between activities.

  2. When you use the AddMedia interface to add media, pay attention to the following aspects:
    • Specify Media workflow ID.

    • If subtitle extraction exists, you can configure in the way that the subtitle file address overwrites the WebVTTSubtitleURL parameter in the Transcode activity, and only subtitle files of WebVTT are supported.

    • Set the Workflow triggering mode as NotInAuto.

Scenarios

The mxf format of the source file, also supports such formats as mp4, flv and m3u8(ts), extracts three audio tracks, two video streams and two groups of WebVTT subtitles from the source file, and then combine and package into a Master Playlist:

Configure HLS package output location and name of Master Playlist.
  • Configure Bucket.

  • Configure Location.

  • Configure the name of Master Playlist.

  • The activity is defined as follows:
    
    {
    "Parameters" : {
    "Output" : "{\"Bucket\": \"processedmediafile\",\"Location\": \"oss-cn-hangzhou\",\"MasterPlayListName\": \"{MediaId}/{RunId}/hls/master.m3u8\"}"
    },
    "Type" : "PackageConfig"
    }
Audio group
  • Configure the audio group ID, wherein two audio streams belongs to the same audio group.

  • The activity is defined as follows:
    
    {
    "Parameters" : {
    "GroupId" : "audios"
    },
    "Type" : "AudioGroup"
    }
    • GroupId: Specify the audio group Id as audios.

    • Type: Specify the type as AudioGroup activity.

Audio extraction
  • Extract audio streams from mxf source file, and the video streams must be removed.

  • Output audio parameters:

    • Codec: AAC

    • SampleRate:48000 Hz

    • Format:Stereo

  • The activity is defined as follows:
    
    {
    "Name" : "audio-extract-1",
    "Parameters" : {
    "Outputs" : "[{\"TemplateId\":\"S00000001-100020\",\"AudioStreamMap\":\"0:a:0\",\"Video\":{\"Remove\":\"true\"}}]",
    "ExtXMedia" : "{\"URI\": \"sd/audio-en.m3u8\",\"Name\": \"audio-en\",\"Language\": \"en-US\"}"
    }
    • Preset static templates ID: S00000001-100020 indicates that the audio output is m3u8(ts), and the audio bitrate configured in the preset templates is 80kbps.

    • AudioStreamMap: Audio stream sequence number. For more information, see Output.

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

    • ExtXMedia defines Media Playlist, and URI specifies the name of Media Playlist.

    • Type is configured as Transcode, which is transcode activity.

Video extraction
  • Extract video streams from the mxf source file, and the audio streams must be removed.

  • The activity is defined as follows:
    
    {
    "Name" : "video-extract",
    "Parameters" : {
    "Outputs" : "[{\"TemplateId\":\"1fe5393bdb7b2b883f0a0fc91e81344a\",\"Audio\":{\"Remove\":\"true\"}}]",
    "MultiBitrateVideoStream" : "{\"URI\": \"sd/video1.m3u8\"}"
    },
    "Type" : "Transcode"
    }
    • Custom transcoding template ID: 1fe5393bdb7b2b883f0a0fc91e81344a, you can log on to the MPS console, and configure the video transcoding parameter in Settings > Transcoding Templates:

      • Codec:H. 264

      • Resolution:384x216

      • Profile:Main

      • Bitrate:240 Kbps

      • Fps:25

      • PixelFormat:YUV420P Max GOP size:1 segment length (4 seconds)

      • Output format: m-3u8

    • Remove audio streams from the output. For more information Audio.

    • MultiBitrateVideoStream defines the multi-bitrate video streams in Master Playlist, and URI specifies the name of Media Playlist.

    • Type is configured as Transcode, which is transcode activity.

Subtitle group
  • Configure subtitle group ID, wherein two subtitle streams belong to the same subtitle group.

  • The activity is defined as follows:

    
    {
    "Parameters" : {
    "GroupId" : "subtitles"
    },
    "Type" : "SubtitleGroup"
    }
    • GroupId: Specify the audio group Id as subtitles.

    • Type: Specify the type as SubtitleGroup activity.

Subtitle extraction
  • Upload subtitles in the WebVtt format to OSS.

  • The activity is defined as follows:

    
    {
    "Name" : "subtitle-extract-1",
    "Parameters" : {
    "WebVTTSubtitleURL" : "http://mts-video.oss-cn-hangzhou.aliyun-inc.com/ShawshankRedemption.vtt",
    "ExtXMedia" : "{\"URI\": \"zh/subtitle1-cn.m3u8\",\"Name\": \"subtitle-cn\",\"Language\": \"cn\"}"
    },
    "Type" : "Transcode"
    }
    • WebVTTSubtitleURL specified the subtitle address. The subtitle address is overwritten dynamically while calling AddMedia For more information about this parameter, see OverrideParams.

    • ExtXMedia defines Media Playlist, and URI specifies the name of Media Playlist.

    • Type is configured as Transcode, which is transcode activity.

Master Playlist output
  • By means of audio, video and subtitle extraction, all the resources after extraction conversion are packaged into a Master Playlist.

  • The activity is defined as follows:
    
    {
    "Parameters" : {
    "MasterPlayList" : "{\"MultiBitrateVideoStreams\": [{\"RefActivityName\": \"video-extract\",\"ExtXStreamInfo\": {\"BandWidth\": \"1110000\",\"Audio\": \"audios\",\"Subtitles\": \"subtitles\"}}]}"
    },
    "Type" : "GenerateMasterPlayList"
    }
    • MasterPlayList defines Master Playlist.

    • MultiBitrateVideoStreams refers to multi-bitrate video streams group.

    • RefActivityName specifies the activity name of video streams.

    • ExtXStreamInfo defines the attributes of the multi-bitrate video streams, Audio specifies the audio group, and Subtitles specifies the subtitle group.

    • Type is set as GenerateMasterPlayList, that is generating Master Playlist activity.

Topology:

Complete scenario example shown in topology:

{
"Activities" : {
"package-node" : {
"Name" : "package-node",
"Parameters" : {
"Output" : "{\"Bucket\": \"processedmediafile\",\"Location\": \"oss-cn-hangzhou\",\"MasterPlayListName\": \"{MediaId}/{RunId}/hls/master.m3u8\"}"
},
"Type" : "PackageConfig"
},
"audioGroupNode" : {
"Name" : "audioGroupNode",
"Parameters" : {
"GroupId" : "audios"
},
"Type" : "AudioGroup"
},
"subtitleGroupNode" : {
"Name" : "subtitleGroupNode",
"Parameters" : {
"GroupId" : "subtitles"
},
"Type" : "SubtitleGroup"
},
"video-extract-1" : {
"Name" : "video-extract-1",
"Parameters" : {
"Outputs" : "[{\"TemplateId\":\"1fe5393bdb7b2b883f0a0fc91e81344a\",\"Audio\":{\"Remove\":\"true\"}}]",
"MultiBitrateVideoStream" : "{\"URI\": \"sd/video1.m3u8\"}"
},
"Type" : "Transcode"
},
"video-extract-2" : {
"Name" : "video-extract-1",
"Parameters" : {
"Outputs" : "[{\"TemplateId\":\"1fe5393bdb7b2b883f0a0fc91e81344b\",\"Audio\":{\"Remove\":\"true\"}}]",
"MultiBitrateVideoStream" : "{\"URI\": \"sd/video2.m3u8\"}"
},
"Type" : "Transcode"
},
"audio-extract-1" : {
"Name" : "audio-extract-1",
"Parameters" : {
"Outputs" : "[{\"TemplateId\":\"S00000001-100020\",\"AudioStreamMap\":\"0:a:0\"}]",
"ExtXMedia" : "{\"URI\": \"sd/audio-en-1.m3u8\",\"Name\": \"audio-en\",\"Language\": \"en-US\"}"
},
"Type" : "Transcode"
},
"audio-extract-2" : {
"Name" : "audio-extract-2",
"Parameters" : {
"Outputs" : "[{\"TemplateId\":\"S00000001-100020\",\"AudioStreamMap\":\"0:a:1\"}]",
"ExtXMedia" : "{\"URI\": \"sd/audio-cn.m3u8\",\"Name\": \"audio-cn\",\"Language\": \"cn\"}"
},
"Type" : "Transcode"
},
"audio-extract-3" : {
"Name" : "audio-extract-3",
"Parameters" : {
"Outputs" : "[{\"TemplateId\":\"S00000001-100020\",\"AudioStreamMap\":\"0:a:2\"}]",
"ExtXMedia" : "{\"URI\": \"sd/audio-de.m3u8\",\"Name\": \"audio-de\",\"Language\": \"de\"}"
},
"Type" : "Transcode"
},
"subtitle-extract-1" : {
"Name" : "subtitle-extract-1",
"Parameters" : {
"WebVTTSubtitleURL" : "http://mts-video-daily-bucket.oss-test.aliyun-inc.com/1.vtt",
"ExtXMedia" : "{\"URI\": \"zh/subtitle1-cn.m3u8\",\"Name\": \"subtitle-cn\",\"Language\": \"cn\"}"
},
"Type" : "Transcode"
},
"subtitle-extract-2" : {
"Name" : "subtitle-extract-2",
"Parameters" : {
"WebVTTSubtitleURL" : "http://mts-video.oss-cn-hangzhou.aliyun-inc.com/ShawshankRedemption.vtt",
"ExtXMedia" : "{\"URI\": \"zh/subtitle1-en.m3u8\",\"Name\": \"subtitle-en\",\"Language\": \"en-US\"}"
},
"Type" : "Transcode"
},
"masterPlayListGenerate" : {
"Name" : "masterPlayListGenerate",
"Parameters" : {
"MasterPlayList" : "{\"MultiBitrateVideoStreams\": [{\"RefActivityName\": \"video-extract-1\",\"ExtXStreamInfo\": {\"BandWidth\": \"1110000\",\"Audio\": \"audios\",\"Subtitles\": \"subtitles\"}}, {\"RefActivityName\": \"video-extract-2\",\"ExtXStreamInfo\": {\"BandWidth\": \"5000000\",\"Audio\": \"audios\",\"Subtitles\":\"subtitles\"}}]}"
},
"Type" : "GenerateMasterPlayList"
},
"activityEnd" : {
"Name" : "activityEnd",
"Parameters" : {
"PublishType" : "Manual"
},
"Type" : "Report"
},
"activityStart" : {
"Name" : "activityStart",
"Parameters" : {
"PipelineId" : "900ededca77641ecbecd4f44cc3a2965",
"Role" : "AliyunMTSDefaultRole",
"InputFile" : "{\"Bucket\":\"videouploaded\",\"Location\":\"oss-cn-hangzhou\",\"ObjectPrefix\":\"uploaded/\"}"
},
"Type" : "Start"
}
},
"Dependencies" : {
"video-extract-1" : [ "masterPlayListGenerate" ],
"video-extract-2" : [ "masterPlayListGenerate" ],
"audio-extract-1" : [ "masterPlayListGenerate" ],
"audio-extract-2" : [ "masterPlayListGenerate" ],
"audio-extract-3" : [ "masterPlayListGenerate" ],
"subtitle-extract-1" : [ "masterPlayListGenerate" ],
"subtitle-extract-2" : [ "masterPlayListGenerate" ],
"package-node" : [ "video-extract-1", "video-extract-2","subtitleGroupNode", "audioGroupNode" ],
"audioGroupNode" : [ "audio-extract-1", "audio-extract-2","audio-extract-3"],
"subtitleGroupNode" : [ "subtitle-extract-1", "subtitle-extract-2" ],
"masterPlayListGenerate" : [ "activityEnd" ],
"activityEnd" : [ ],
"activityStart" : [ "package-node" ]
}
}

Code example

  1. Create HLS package workflow

    Create workflow-Java

    Create workflow-Python

    Create workflow-PHP

  2. Add media

    Add media-Java

    Add media-Python

    Add media-PHP