Thumbnail-Job缩略图任务
更新时间:2023-04-23
缩略图是图片、视频经压缩方式处理后的小图。因其小巧,加载速度非常快,故用于快速浏览。缩略图任务可用于为BOS中的多媒体资源创建缩略图。
创建Thumbnail Job
通过pipeline,BOS Key以及其他配置信息为指定媒体生成缩略图,并获取返回的缩略图任务jobId。可以参考如下代码:
pipelineName := "go_test"
sourcekey := "01.mp4"
target := &api.ThumbnailTarget{}
target.Format = "jpg"
target.SizingPolicy = "keep"
capture := &api.ThumbnailCapture{}
capture.Mode = "manual"
capture.StartTimeInSecond = 0.0
capture.EndTimeInSecond = 5.0
capture.IntervalInSecond = 1.0
createJobResponse, err := MEDIA_CLIENT.CreateThumbnailJob(pipelineName, sourcekey, TargetOp(target), CaptureOp(capture))
if err != nil {
fmt.Printf("create thumbanil job error: %+v\n", err)
return
}
fmt.Println("create thumbanil job success jobId: ", createJobResponse.JobId)
创建去水印的缩略图,可以参考如下代码:
pipelineName := "go_test"
sourcekey := "01.mp4"
target := &api.ThumbnailTarget{}
target.KeyPrefix = "taget_key_prefix_test_delogo3"
delogo := &api.Area{}
delogo.X = 20
delogo.Y = 20
delogo.Height = 50
delogo.Width = 80
createJobResponse, err := MEDIA_CLIENT.CreateThumbnailJob(pipelineName, sourcekey, TargetOp(target), DelogoAreaOp(delogo))
if err != nil {
fmt.Printf("create thumbanil job error: %+v\n", err)
return
}
fmt.Println("create thumbanil job success jobId: ", createJobResponse.JobId)
创建去水印、去黑边的缩略图,可以参考如下代码:
pipelineName := "go_test"
sourcekey := "01.mp4"
target := &api.ThumbnailTarget{}
target.KeyPrefix = "taget_key_prefix_test_delogo_crop"
delogo := &api.Area{}
delogo.X = 20
delogo.Y = 20
delogo.Height = 50
delogo.Width = 80
crop := &api.Area{}
crop.X = 120
crop.Y = 120
crop.Height = 100
crop.Width = 80
createJobResponse, err := MEDIA_CLIENT.CreateThumbnailJob(pipelineName, sourcekey,
TargetOp(target), DelogoAreaOp(delogo), CropOp(crop))
if err != nil {
fmt.Printf("create thumbanil job error: %+v\n", err)
return
}
fmt.Println("create thumbanil job success jobId: ", createJobResponse.JobId)
创建去水印缩略图任务,其中指定了缩略图格式为jpg、尺寸为与原视频保持一致(keep),抽帧模式(SizingPolicy)为split,根据指定的起止时间和张数截取缩略图,FrameNumber则指定了缩略图张数,代码如下:
pipelineName := "go_test"
sourcekey := "01.mp4"
target := &api.ThumbnailTarget{}
target.Format = "jpg"
target.SizingPolicy = "keep"
capture := &api.ThumbnailCapture{}
capture.Mode = "split"
capture.FrameNumber = 30
delogo := &api.Area{}
delogo.X = 20
delogo.Y = 20
delogo.Height = 50
delogo.Width = 80
createJobResponse, err := MEDIA_CLIENT.CreateThumbnailJob(pipelineName, sourcekey,
TargetOp(target), CaptureOp(capture), DelogoAreaOp(delogo))
if err != nil {
fmt.Printf("create thumbanil job error: %+v\n", err)
return
}
fmt.Println("create thumbanil job success jobId: ", createJobResponse.JobId)
如果只想创建一个简单的缩略图任务可以参考如下代码:
pipelineName := "go_test"
sourcekey := "01.mp4"
createJobResponse, err := MEDIA_CLIENT.CreateThumbnailJob(pipelineName, sourcekey)
if err != nil {
fmt.Printf("create thumbanil job error: %+v\n", err)
return
}
fmt.Println("create thumbanil job success jobId: ", createJobResponse.JobId)
查询指定Thumbnail Job
如果需要获取一个已创建的缩略图任务的信息,可以参考如下代码:
jobId := "job-xxxxxxx"
jobResponse, err := MEDIA_CLIENT.GetThumbanilJob(jobId)
if err != nil {
fmt.Printf("get thumbanil job error: %+v\n", err)
return
}
fmt.Printf("get thumbanil job success job: %+v\n", jobResponse)
查询指定队列的Thumbnail Jobs
如果需要获取一个队列里的全部缩略图任务的信息,可以参考如下代码:
pipelineName := "go_sdk_test"
listThumbnailJobsResponse, err := MEDIA_CLIENT.ListThumbnailJobs(pipelineName)
if err != nil {
fmt.Printf("list thumbanil job error: %+v\n", err)
return
}
for _, job := range listThumbnailJobsResponse.Thumbnails {
fmt.Printf("list thumbanil job success : %+v\n", job)
}