Transcoding-Job转码任务
更新时间:2023-04-24
Transcoding Job(任务)是音视频转码中最基本的执行单元,每个任务将一个原始的音视频资源转码成目标规格的音视频资源。因此,任务和转码的目标是一一对应的,也就是说如果用户需要将一个原始多媒体文件转换成三种目标规格,比如从AVI格式转码成FLV/MP4/HLS格式,那么用户将会需要创建三个任务。
创建Transcoding Job
用户在创建转码任务时,需要为转码任务指定所属的Pipeline、所需应用的Preset以及原始音视频资源的BOS Key以及目标音视频资源BOS Key。
如下代码创建一个Job, 并获取新创建的jobID:
pipelineName := "go_sdk_test"
sourceKey := "test.mp4"
targetKey := "test-result.mp4"
presetName := "test_preset"
jobResponse, err := MEDIA_CLIENT.CreateJob(pipelineName, sourceKey, targetKey, presetName)
if err != nil {
fmt.Printf("create job error: %+v\n", err)
return
}
fmt.Println("create job success jobId:", jobResponse.JobId)
如下代码创建一个支持视频合并、去水印、加水印(Job上而不是Preset上指定watermarkId)的Job, 并获取新创建的jobID:
args := &api.CreateJobArgs{}
args.PipelineName = "go_sdk_test"
source := &api.Source{Clips: &[]api.SourceClip{{
SourceKey: "01.mp4",
EnableDelogo: false,
DurationInMillisecond: 6656,
StartTimeInSecond: 2}}}
args.Source = source
target := &api.Target{}
targetKey := "clips_playback_watermark_delogo_crop2.mp4"
watermarkId := "wmk-xxxx"
target.TargetKey = targetKey
watermarkIdSlice := append(target.WatermarkIds, watermarkId)
target.WatermarkIds = watermarkIdSlice
presetName := "go_test_customize_audio_video"
target.PresetName = presetName
delogoArea := &api.Area{}
delogoArea.X = 10
delogoArea.Y = 10
delogoArea.Width = 30
delogoArea.Height = 40
target.DelogoArea = delogoArea
args.Target = target
jobResponse, err := MEDIA_CLIENT.CreateJobCustomize(args)
if err != nil {
fmt.Printf("create job error: %+v\n", err)
return
}
fmt.Println("create job success jobId:", jobResponse.JobId)
列出指定Pipeline的所有Transcoding Job
如下代码通过指定pipelineName查询该Pipeline下的所有Job:
pipelineName := "test"
listTranscodingJobsResponse, err := MEDIA_CLIENT.ListTranscodingJobs(pipelineName)
if err != nil {
fmt.Printf("list job error: %+v\n", err)
return
}
fmt.Printf("list job success : %+v\n", listTranscodingJobsResponse)
查询指定的Transcoding Job信息
可以通过如下代码通过jobId读取某个Job:
jobId := "job-xxxxxxxxx"
getTranscodingJobResponse, err := MEDIA_CLIENT.GetTranscodingJob(jobId)
if err != nil {
fmt.Printf("get job error: %+v\n", err)
return
}
fmt.Printf("get job success : %+v\n", getTranscodingJobResponse)