diff --git a/ci_media.go b/ci_media.go index e44f3f5..7744abf 100644 --- a/ci_media.go +++ b/ci_media.go @@ -11,9 +11,10 @@ type JobInput struct { } type JobOutput struct { - Region string `xml:"Region,omitempty"` - Bucket string `xml:"Bucket,omitempty"` - Object string `xml:"Object,omitempty"` + Region string `xml:"Region,omitempty"` + Bucket string `xml:"Bucket,omitempty"` + Object string `xml:"Object,omitempty"` + SpriteObject string `xml:"SpriteObject,omitempty"` } type Container struct { @@ -110,13 +111,24 @@ type ConcatTemplate struct { Index string `xml:"Index,omitempty"` } +type SpriteSnapshotConfig struct { + CellHeight string `xml:"CellHeight,omitempty"` + CellWidth string `xml:"CellWidth,omitempty"` + Color string `xml:"Color,omitempty"` + Columns string `xml:"Columns,omitempty"` + Lines string `xml:"Lines,omitempty"` + Margin string `xml:"Margin,omitempty"` + Padding string `xml:"Padding,omitempty"` +} type Snapshot struct { - Mode string `xml:"Mode,omitempty"` - Start string `xml:"Start,omitempty"` - TimeInterval string `xml:"TimeInterval,omitempty"` - Count string `xml:"Count,omitempty"` - Width string `xml:"Width,omitempty"` - Height string `xml:"Height,omitempty"` + Mode string `xml:"Mode,omitempty"` + Start string `xml:"Start,omitempty"` + TimeInterval string `xml:"TimeInterval,omitempty"` + Count string `xml:"Count,omitempty"` + Width string `xml:"Width,omitempty"` + Height string `xml:"Height,omitempty"` + SnapshotOutMode string `xml:"SnapshotOutMode,omitempty"` + SpriteSnapshotConfig *SpriteSnapshotConfig `xml:"SpriteSnapshotConfig,omitempty"` } // 有意和转码区分,两种任务关注的参数不一样避免干扰 @@ -265,10 +277,10 @@ type MediaProcessJobsNotifyBody struct { } `xml:"MediaInfo"` MediaResult struct { OutputFile struct { - Bucket string `xml:"Bucket"` + Bucket string `xml:"Bucket"` ObjectName []string `xml:"ObjectName"` - ObjectPrefix string `xml:"ObjectPrefix"` - Region string `xml:"Region"` + ObjectPrefix string `xml:"ObjectPrefix"` + Region string `xml:"Region"` } `xml:"OutputFile"` } `xml:"MediaResult"` Output struct { diff --git a/example/CI/media_process/media_process.go b/example/CI/media_process/media_process.go index bf2ae7c..27ccde4 100644 --- a/example/CI/media_process/media_process.go +++ b/example/CI/media_process/media_process.go @@ -334,7 +334,7 @@ func TaskNotifyCallback() { } } -func WorkflowExecutionNotifyCallback() { +func WorkflowExecutionNotifyCallback() { workflowExecutionBody := "WorkflowFinishi70ae991a152911ecb184525400a8700f62ddbc1245.mp4x-cos-meta-id62ddbc1245Content-Typevideo/mp4w29ba54d02b7340dd9fb44eb5beb786b92021-09-14 15:00:26+0800SuccessTranscode2021-09-14 15:00:27+08002021-09-14 15:00:42+0800Successj70bab192152911ecab79bba409874f7fTranscode_1607323983818t088613dea8d564a9ba7e6b02cbd5de877HLS-FHD" var body cos.WorkflowExecutionNotifyBody err := xml.Unmarshal([]byte(workflowExecutionBody), &body) @@ -345,11 +345,78 @@ func WorkflowExecutionNotifyCallback() { } } +func InvokeSpriteSnapshotTask() { + u, _ := url.Parse("https://wwj-cq-1253960454.cos.ap-chongqing.myqcloud.com") + cu, _ := url.Parse("https://wwj-cq-1253960454.ci.ap-chongqing.myqcloud.com") + b := &cos.BaseURL{BucketURL: u, CIURL: cu} + c := cos.NewClient(b, &http.Client{ + Transport: &cos.AuthorizationTransport{ + SecretID: os.Getenv("COS_SECRETID"), + SecretKey: os.Getenv("COS_SECRETKEY"), + Transport: &debug.DebugRequestTransport{ + RequestHeader: true, + // Notice when put a large file and set need the request body, might happend out of memory error. + RequestBody: true, + ResponseHeader: true, + ResponseBody: true, + }, + }, + }) + // DescribeMediaProcessQueues + DescribeQueueOpt := &cos.DescribeMediaProcessQueuesOptions{ + QueueIds: "", + PageNumber: 1, + PageSize: 2, + } + DescribeQueueRes, _, err := c.CI.DescribeMediaProcessQueues(context.Background(), DescribeQueueOpt) + log_status(err) + fmt.Printf("%+v\n", DescribeQueueRes) + // CreateMediaJobs + createJobOpt := &cos.CreateMediaJobsOptions{ + Tag: "Snapshot", + Input: &cos.JobInput{ + Object: "input/117374C.mp4", + }, + Operation: &cos.MediaProcessJobOperation{ + Output: &cos.JobOutput{ + Region: "ap-chongqing", + Object: "output/abc-${Number}.jpg", + Bucket: "wwj-cq-1253960454", + SpriteObject: "output/sprite-${Number}.jpg", + }, + Snapshot: &cos.Snapshot{ + Mode: "Interval", + Start: "0", + Count: "100", + SnapshotOutMode: "SnapshotAndSprite", // OnlySnapshot OnlySprite + SpriteSnapshotConfig: &cos.SpriteSnapshotConfig{ + CellHeight: "128", + CellWidth: "128", + Color: "Black", + Columns: "3", + Lines: "10", + Margin: "2", + }, + }, + }, + QueueId: DescribeQueueRes.QueueList[0].QueueId, + } + createJobRes, _, err := c.CI.CreateMediaJobs(context.Background(), createJobOpt) + log_status(err) + fmt.Printf("%+v\n", createJobRes.JobsDetail) + + // DescribeMediaJobs + DescribeJobRes, _, err := c.CI.DescribeMediaJob(context.Background(), createJobRes.JobsDetail.JobId) + log_status(err) + fmt.Printf("%+v\n", DescribeJobRes.JobsDetail) +} + func main() { // InvokeSnapshotTask() // InvokeConcatTask() // InvokeTranscodeTask() // InvokeMultiTasks() - TaskNotifyCallback() - WorkflowExecutionNotifyCallback() + // TaskNotifyCallback() + // WorkflowExecutionNotifyCallback() + InvokeSpriteSnapshotTask() }