All Products
Search
Document Center

Transcoding template

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see InitVodClient.

Add a transcoding template group

For more information about the request and response parameters, see AddTranscodeTemplateGroup.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
    "encoding/json"
)

func MyAddTranscodeTemplateGroup(client *vod.Client) (response *vod.AddTranscodeTemplateGroupResponse, err error) {
    request := vod.CreateAddTranscodeTemplateGroupRequest()

    request.Name = "SampleTranscodeTemplateGroup"

    transcodeTemplateList := BuildTranscodeTemplateList()
    jsonTranscodeConfig, err := json.Marshal(transcodeTemplateList)
    if err ! = nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.TranscodeTemplateList = string(jsonTranscodeConfig)

    request.AcceptFormat = "JSON"

    return client.AddTranscodeTemplateGroup(request)
}

// Constructs the transcoding template configuration.
func BuildTranscodeTemplateList() (transcodeTemplateList []map[string]interface{}) {

    transcodeTemplate := map[string]interface{}{}

    // Sets the template name.
    transcodeTemplate["TemplateName"] = "MP4-for-Low-Definition"

    // Sets the definition.
    transcodeTemplate["Definition"] = "LD"

    // Specifies the video stream transcoding configuration.
    videoConfig := map[string]interface{}{"Width": 640, "Bitrate": 400, "Fps": 25, "Remove": false, "Codec": "H. 264", "Gop": "250"}
    transcodeTemplate["Video"] = videoConfig

    // Specifies the audio stream transcoding configuration.
    audioConfig := map[string]interface{}{"Codec": "AAC", "Bitrate": "64", "Channels": "2", "Samplerate": "32000"}
    transcodeTemplate["Audio"] = audioConfig

    // Specifies the encapsulation container.
    container := map[string]interface{}{"Format": "mp4"}
    transcodeTemplate["Container"] = container

    // Specifies the conditional transcoding configuration.
    condition := map[string]interface{}{"IsCheckReso": false, "IsCheckResoFail": false, "IsCheckVideoBitrate": false,
        "IsCheckVideoBitrateFail": false, "IsCheckAudioBitrate": false, "IsCheckAudioBitrateFail": false}
    transcodeTemplate["TransConfig"] = condition

    /*
    // Specifies the encryption configuration, which supports only HTTP Live Streaming (HLS).
    encryptSetting := map[string]interface{}{"EncryptType": "Private"}
    transcodeTemplate["EncryptSetting"] = encryptSetting
    */

    // Associates watermark IDs with transcoding template IDs.
    watermarkIdList := []string{"USER_DEFAULT_WATERMARK"}
    //watermarkIdList = append(watermarkIdList, "<WatermarkId>") 
    transcodeTemplate["WatermarkIds"] = watermarkIdList

    transcodeTemplateList = append(transcodeTemplateList, transcodeTemplate)

    return transcodeTemplateList
}


func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MyAddTranscodeTemplateGroup(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.TranscodeTemplateGroupId)
}

Modify a transcoding template group

For more information about the request and response parameters, see UpdateTranscodeTemplateGroup.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
    "encoding/json"
)

func MyUpdateTranscodeTemplateGroup(client *vod.Client) (response *vod.UpdateTranscodeTemplateGroupResponse, err error) {
    request := vod.CreateUpdateTranscodeTemplateGroupRequest()

    request.TranscodeTemplateGroupId = "<TranscodeTemplateGroupId>" 

    // (Optional) Modifies the name of the encoding template group.
    request.Name = "new-SampleTranscodeTemplateGroup"

    // (Optional) Modifies the configuration of the encoding template group.
    transcodeTemplateList := BuildNewTranscodeTemplateList()
    jsonTranscodeConfig, err := json.Marshal(transcodeTemplateList)
    if err ! = nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.TranscodeTemplateList = string(jsonTranscodeConfig)

    request.AcceptFormat = "JSON"

    return client.UpdateTranscodeTemplateGroup(request)
}

// Constructs the transcoding template configuration.
func BuildNewTranscodeTemplateList() (transcodeTemplateList []map[string]interface{}) {

    transcodeTemplate := map[string]interface{}{}

    // (Required) Sets the transcoding template ID.
    transcodeTemplate["TranscodeTemplateId"] = "<TranscodeTemplateId>" 

    // The following settings are optional.

    // Sets a new transcoding template name as required.
    transcodeTemplate["TemplateName"] = "new-MP4-for-High-Definition"

    // Specifies the video stream transcoding configuration.
    videoConfig := map[string]interface{}{"Width": 640, "Bitrate": 500, "Fps": 60, "Remove": false, "Codec": "H. 264", "Gop": "250"}
    transcodeTemplate["Video"] = videoConfig

    // Specifies the audio stream transcoding configuration.
    audioConfig := map[string]interface{}{"Codec": "AAC", "Bitrate": "128", "Channels": "2", "Samplerate": "32000"}
    transcodeTemplate["Audio"] = audioConfig

    // Specifies the encapsulation container.
    container := map[string]interface{}{"Format": "mp4"}
    transcodeTemplate["Container"] = container

    // Specifies the conditional transcoding configuration.
    condition := map[string]interface{}{"IsCheckReso": false, "IsCheckResoFail": false, "IsCheckVideoBitrate": false,
        "IsCheckVideoBitrateFail": false, "IsCheckAudioBitrate": false, "IsCheckAudioBitrateFail": false}
    transcodeTemplate["TransConfig"] = condition

    /*
    // Specifies the encryption configuration, which supports only HLS.
    encryptSetting := map[string]interface{}{"EncryptType": "Private"}
    transcodeTemplate["EncryptSetting"] = encryptSetting
    */

    // Associates watermark IDs with transcoding template IDs.
    watermarkIdList := []string{"USER_DEFAULT_WATERMARK"}
    //watermarkIdList = append(watermarkIdList, "<WatermarkId>")
    transcodeTemplate["WatermarkIds"] = watermarkIdList

    transcodeTemplateList = append(transcodeTemplateList, transcodeTemplate)

    return transcodeTemplateList
}


func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MyUpdateTranscodeTemplateGroup(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

Query a list of transcoding template groups

For more information about the request and response parameters, see ListTranscodeTemplateGroup.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyListTranscodeTemplateGroup(client *vod.Client) (response *vod.ListTranscodeTemplateGroupResponse, err error) {
    request := vod.CreateListTranscodeTemplateGroupRequest()

    request.AcceptFormat = "JSON"

    return client.ListTranscodeTemplateGroup(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MyListTranscodeTemplateGroup(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    for _, item := range response.TranscodeTemplateGroupList {
        fmt.Printf("%s: %s\n", item.TranscodeTemplateGroupId, item.Name)
    }
}

Query a transcoding template group

For more information about the request and response parameters, see GetTranscodeTemplateGroup.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyGetTranscodeTemplateGroup(client *vod.Client) (response *vod.GetTranscodeTemplateGroupResponse, err error) {
    request := vod.CreateGetTranscodeTemplateGroupRequest()
    request.TranscodeTemplateGroupId = "<TranscodeTemplateGroupId>"

    request.AcceptFormat = "JSON"

    return client.GetTranscodeTemplateGroup(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MyGetTranscodeTemplateGroup(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    for _, item := range response.TranscodeTemplateGroup.TranscodeTemplateList {
        fmt.Printf("%s: %s\n", item.TranscodeTemplateId, item.TemplateName)
    }
}

Set the default transcoding template group

For more information about the request and response parameters, see SetDefaultTranscodeTemplateGroup.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MySetDefaultTranscodeTemplateGroup(client *vod.Client) (response *vod.SetDefaultTranscodeTemplateGroupResponse, err error) {
    request := vod.CreateSetDefaultTranscodeTemplateGroupRequest()
    request.TranscodeTemplateGroupId = "<TranscodeTemplateGroupId>" 

    request.AcceptFormat = "JSON"

    return client.SetDefaultTranscodeTemplateGroup(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MySetDefaultTranscodeTemplateGroup(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

Delete a transcoding template group

For more information about the request and response parameters, see DeleteTranscodeTemplateGroup.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDeleteTranscodeTemplateGroup(client *vod.Client) (response *vod.DeleteTranscodeTemplateGroupResponse, err error) {
    request := vod.CreateDeleteTranscodeTemplateGroupRequest()
    request.TranscodeTemplateGroupId = "<TranscodeTemplateGroupId>" 

    request.AcceptFormat = "JSON"

    return client.DeleteTranscodeTemplateGroup(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MyDeleteTranscodeTemplateGroup(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}