Video editing and production

Updated at:

By reading this article, you can learn the sample code for creating an intelligent media service clip composition task by calling the OpenAPI of the server SDK.

Usage notes

When you create a production job, use one of the following parameters: `Timeline`, `TemplateId`, or `ProjectId`.

Sample code

Perform online debugging in the Alibaba Cloud OpenAPI Developer Portal.

package main

import (
    "fmt"
    openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
    ice "github.com/alibabacloud-go/ice-20201109/v2/client"
    "github.com/aliyun/credentials-go/credentials"
    "github.com/alibabacloud-go/tea/tea"
)

func main() {

    // An Alibaba Cloud account AccessKey has full access to all API operations. Use a Resource Access Management (RAM) user for API calls or daily O&M.
    // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. For information about how to configure them, see the Alibaba Cloud documentation.
    credential, _err := credentials.NewCredential(nil)
    if _err != nil {
      panic(_err)
    }
    iceClient, _err := ice.NewClient(&openapi.Config{
      Credential: credential,
      Endpoint: tea.String("ice.cn-shanghai.aliyuncs.com"),
    })

    // To hard-code the AccessKey ID and AccessKey secret, use the following code. Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey leak and compromise the security of all resources in your account.
    // config := new(openapi.Config)
    // config.SetAccessKeyId("<accessKeyId>").
    //     SetAccessKeySecret("<accessKeySecret>").
    //     SetRegionId("<regionId>").
    //     SetEndpoint("<endpoint>")
    // iceClient, _err := ice.NewClient(config)

    if _err != nil {
      panic(_err)
    }

    // Create a production job using a timeline.
    timeLine := "{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaId\":\"****9b4d7cf14dc7b83b0e801cbe****\"},{\"MediaId\":\"****9b4d7cf14dc7b83b0e801cbe****\"},{\"MediaId\":\"****1656bca4474999c961a6d2a2****\"}]}]}"
    outputMediaConfig := "{\"mediaURL\":\"http://ice-editing.oss-cn-hangzhou.aliyuncs.com/ice/\",\"type\":\"unkown\"}"
    projectMetadata := "{\"coverURL\":\"http://****/mediaid.jpg\",\"description\":\"description\",\"title\":\"title\"}"
    submitMediaProducingJobRequest := ice.SubmitMediaProducingJobRequest{
        Timeline:          &timeLine,
        OutputMediaConfig: &outputMediaConfig,
        ProjectMetadata:   &projectMetadata,
    }
    submitMediaProducingJobResult, err := iceClient.SubmitMediaProducingJob(&submitMediaProducingJobRequest)
    fmt.Println(submitMediaProducingJobResult, err)

    // Create a production job using a template.
    templateId := "IceSys_VideoMerge"
    clipsParam := "{\"VideoArray\":[\"****g105512043f49f697f74258u****\",\"****f82788e810116a45109f2ebb****\",\"****f267f44f4964e6c998dee89i****\",]}"
    submitMediaProducingJobRequest1 := ice.SubmitMediaProducingJobRequest{
        TemplateId:      &templateId,
        ClipsParam:      &clipsParam,
        ProjectMetadata: &projectMetadata,
    }
    submitMediaProducingJobResult1, err := iceClient.SubmitMediaProducingJob(&submitMediaProducingJobRequest1)
    fmt.Println(submitMediaProducingJobResult1, err)

    // Create a production job using a project.
    projectId := "****9b4d7cf14dc7b83b0e801cbe****"
    submitMediaProducingJobRequest2 := ice.SubmitMediaProducingJobRequest{
        ProjectId:       &projectId,
        ProjectMetadata: &projectMetadata,
    }
    submitMediaProducingJobResult2, err := iceClient.SubmitMediaProducingJob(&submitMediaProducingJobRequest2)
    fmt.Println(submitMediaProducingJobResult2, err)

    // Get a single production job.
    jobId := "****967f44f4964e6c998dee8e****"
    getMediaProducingJobRequest := ice.GetMediaProducingJobRequest{
        JobId: &jobId,
    }
    getMediaProducingJobResult, err := iceClient.GetMediaProducingJob(&getMediaProducingJobRequest)
    fmt.Println(getMediaProducingJobResult, err)
}

Related API operations