Submit and query transcoding jobs by using the Intelligent Media Services (IMS) server SDK for Go.
Prerequisites
Before you run the sample code, complete the following steps:
-
Install the required Go SDK packages:
go get github.com/alibabacloud-go/darabonba-openapi/v2/client go get github.com/alibabacloud-go/ice-20201109/v2/client go get github.com/aliyun/credentials-go/credentials go get github.com/alibabacloud-go/tea/tea -
Configure credentials. Set your AccessKey ID and AccessKey secret as environment variables. For details, see Manage Go access credentials.
Usage notes
To submit a transcoding job, configure the following parameters:
| Parameter | Required | Description |
|---|---|---|
InputGroup |
Yes | The input media, specified by media ID and type. The input media region must match the service region. |
OutputGroup |
Yes | The output media and transcoding configuration, including the output media ID, type, and template ID. The output media region must match the service region. |
Name |
No | The name of the transcoding job. |
TemplateId |
Yes | The ID of the transcoding template. Obtain this from the transcoding template management page in the IMS console. |
After you submit a job, use the returned ParentJobId to query the job status and details.
Note
Supported regions:
VOD media processing: China (Shanghai), China (Beijing), and China (Shenzhen)
Real-time media processing: China (Shanghai)
Sample code
Debug this API operation in the Alibaba Cloud OpenAPI 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 AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use an AccessKey pair of a RAM user to call API operations or perform routine O&M.
// In this example, the AccessKey ID and the AccessKey secret are obtained from the environment variables. For more information, visit https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-go-access-credentials?spm=a2c63.p38356.help-menu-262060.d_1_9_1_2.16c2662axiCNKz.
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 your AccessKey ID and AccessKey secret, use the following code. We recommend that you do not save the AccessKey ID and the AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of resources within your account may be compromised.
// config := new(openapi.Config)
// config.SetAccessKeyId("<accessKeyId>").
// SetAccessKeySecret("<accessKeySecret>").
// SetRegionId("<regionId>").
// SetEndpoint("<endpoint>")
// iceClient, _err := ice.NewClient(config)
if _err != nil {
panic(_err)
}
// Submit a transcoding job.
jobName := "sdk_sample_snapshot_job"
inputType := "Media"
inputMedia := "3945e42d-1823498****"
outputType := "Media"
outputMedia := "3945e42d-1823498****"
templateId := "as8ee42d-1823498****"
request := &ice.SubmitTranscodeJobRequest{
Name: &jobName,
// Input information
InputGroup: []*ice.SubmitTranscodeJobRequestInputGroup{&ice.SubmitTranscodeJobRequestInputGroup{
Type: &inputType,
Media: &inputMedia,
}},
// Output information
OutputGroup: []*ice.SubmitTranscodeJobRequestOutputGroup{&ice.SubmitTranscodeJobRequestOutputGroup{
Output: &ice.SubmitTranscodeJobRequestOutputGroupOutput{
Type: &outputType,
Media: &outputMedia,
},
ProcessConfig: &ice.SubmitTranscodeJobRequestOutputGroupProcessConfig{
Transcode: &ice.SubmitTranscodeJobRequestOutputGroupProcessConfigTranscode{
TemplateId: &templateId,
},
},
}},
}
response, err := iceClient.SubmitTranscodeJob(request)
fmt.Println(response, err)
// Retrieve the job ID and query the information about the transcoding job.
jobId := response.Body.TranscodeParentJob.ParentJobId
queryRequest := &ice.GetTranscodeJobRequest{
ParentJobId: jobId,
}
queryResponse, err := iceClient.GetTranscodeJob(queryRequest)
fmt.Println(queryResponse, err)
}
What the code does
-
Initialize the client -- Creates an IMS client using credentials from environment variables. The endpoint
ice.cn-shanghai.aliyuncs.comtargets the China (Shanghai) region. -
Submit a transcoding job -- Calls
SubmitTranscodeJobwith:-
InputGroup: Specifies the source media by ID and type. -
OutputGroup: Specifies the output media and the transcoding template to apply.
-
-
Query the job -- Retrieves the
ParentJobIdfrom the submission response and callsGetTranscodeJobto check job status and details.