From 6b85e7b9e72f223fab3eb9d5b1eea4b61bf7740c Mon Sep 17 00:00:00 2001 From: flynnzzhang Date: Fri, 8 Oct 2021 17:30:30 +0800 Subject: [PATCH] =?UTF-8?q?ci=20=E5=88=86=E6=AE=B5=E4=BB=BB=E5=8A=A1struct?= =?UTF-8?q?=20demo=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci_media.go | 6 ++++ example/CI/media_process/media_process.go | 58 ++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/ci_media.go b/ci_media.go index 7744abf..48b572a 100644 --- a/ci_media.go +++ b/ci_media.go @@ -149,6 +149,11 @@ type Animation struct { TimeInterval *TimeInterval `xml:"TimeInterval,omitempty"` } +type Segment struct { + Format string `xml:"Format,omitempty"` + Duration string `xml:"Duration,omitempty"` +} + type MediaProcessJobOperation struct { Tag string `xml:"Tag,omitempty"` Output *JobOutput `xml:"Output,omitempty"` @@ -159,6 +164,7 @@ type MediaProcessJobOperation struct { ConcatTemplate *ConcatTemplate `xml:"ConcatTemplate,omitempty"` Snapshot *Snapshot `xml:"Snapshot,omitempty"` Animation *Animation `xml:"Animation,omitempty"` + Segment *Segment `xml:"Segment,omitempty"` } type CreateMediaJobsOptions struct { diff --git a/example/CI/media_process/media_process.go b/example/CI/media_process/media_process.go index 27ccde4..e84da97 100644 --- a/example/CI/media_process/media_process.go +++ b/example/CI/media_process/media_process.go @@ -411,6 +411,61 @@ func InvokeSpriteSnapshotTask() { fmt.Printf("%+v\n", DescribeJobRes.JobsDetail) } +func InvokeSegmentTask() { + 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: "Segment", + Input: &cos.JobInput{ + Object: "input/117374C.mp4", + }, + Operation: &cos.MediaProcessJobOperation{ + Output: &cos.JobOutput{ + Region: "ap-chongqing", + Object: "output/abc-${Number}.mp4", + Bucket: "wwj-cq-1253960454", + }, + Segment: &cos.Segment{ + Format: "mp4", + Duration: "10", + }, + }, + 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() @@ -418,5 +473,6 @@ func main() { // InvokeMultiTasks() // TaskNotifyCallback() // WorkflowExecutionNotifyCallback() - InvokeSpriteSnapshotTask() + // InvokeSpriteSnapshotTask() + InvokeSegmentTask() }