From ee4f335957f295497adbcf81a8e34bf38ba5e106 Mon Sep 17 00:00:00 2001 From: wanjiewu Date: Mon, 30 Aug 2021 21:05:47 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=94=AF=E6=8C=81=E6=8B=BC=E6=8E=A5?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci_media.go | 18 +++++-- example/CI/media_process/media_process.go | 78 ++++++++++++++++++++++++++++++- go.sum | 2 + 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/ci_media.go b/ci_media.go index b9dfd90..2a00bab 100644 --- a/ci_media.go +++ b/ci_media.go @@ -25,7 +25,7 @@ type Video struct { Width string `xml:"Width"` Height string `xml:"Height"` Fps string `xml:"Fps"` - Remove string `xml:"Remove"` + Remove string `xml:"Remove,omitempty"` Profile string `xml:"Profile"` Bitrate string `xml:"Bitrate"` Crf string `xml:"Crf"` @@ -48,7 +48,7 @@ type Audio struct { Samplerate string `xml:"Samplerate"` Bitrate string `xml:"Bitrate"` Channels string `xml:"Channels"` - Remove string `xml:"Remove"` + Remove string `xml:"Remove,omitempty"` } type TransConfig struct { @@ -97,13 +97,25 @@ type Watermark struct { Image *Image `xml:"Image,omitempty"` Text *Text `xml:"Text,omitempty"` } - +type ConcatFragment struct { + Url string `xml:"Url,omitempty"` + StartTime string `xml:"StartTime,omitempty"` + EndTime string `xml:"EndTime,omitempty"` +} +type ConcatTemplate struct { + ConcatFragment []ConcatFragment `xml:"ConcatFragment,omitempty"` + Audio *Audio `xml:"Audio,omitempty"` + Video *Video `xml:"Video,omitempty"` + Container *Container `xml:"Container,omitempty"` + Index string `xml:"Index,omitempty"` +} type MediaProcessJobOperation struct { Output *JobOutput `xml:"Output,omitempty"` Transcode *Transcode `xml:"Transcode,omitempty"` Watermark *Watermark `xml:"Watermark,omitempty"` TemplateId string `xml:"TemplateId,omitempty"` WatermarkTemplateId []string `xml:"WatermarkTemplateId,omitempty"` + ConcatTemplate *ConcatTemplate `xml:"ConcatTemplate,omitempty"` } type CreateMediaJobsOptions struct { diff --git a/example/CI/media_process/media_process.go b/example/CI/media_process/media_process.go index c822a02..5fbd82c 100644 --- a/example/CI/media_process/media_process.go +++ b/example/CI/media_process/media_process.go @@ -30,7 +30,78 @@ func log_status(err error) { } } -func main() { +func InvokeConcatTask() { + u, _ := url.Parse("https://wwj-bj-1253960454.cos.ap-beijing.myqcloud.com") + cu, _ := url.Parse("https://wwj-bj-1253960454.ci.ap-beijing.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 + concatFragment := make([]cos.ConcatFragment, 0) + concatFragment = append(concatFragment, cos.ConcatFragment{ + Url: "https://wwj-bj-1253960454.cos.ap-beijing.myqcloud.com/input/117374C.mp4", + StartTime: "0", + EndTime: "10", + }) + concatFragment = append(concatFragment, cos.ConcatFragment{ + Url: "https://wwj-bj-1253960454.cos.ap-beijing.myqcloud.com/input/117374C.mp4", + StartTime: "20", + EndTime: "30", + }) + createJobOpt := &cos.CreateMediaJobsOptions{ + Tag: "Concat", + Operation: &cos.MediaProcessJobOperation{ + Output: &cos.JobOutput{ + Region: "ap-beijing", + Object: "output/go_117374C.mp4", + Bucket: "wwj-bj-1253960454", + }, + ConcatTemplate: &cos.ConcatTemplate{ + Container: &cos.Container{ + Format: "mp4", + }, + Video: &cos.Video{ + Codec: "H.264", + }, + Audio: &cos.Audio{ + Codec: "AAC", + }, + ConcatFragment:concatFragment, + }, + }, + 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 InvokeTranscodeTask() { 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} @@ -95,3 +166,8 @@ func main() { log_status(err) fmt.Printf("%+v\n", DescribeJobRes.JobsDetail) } + +func main() { + InvokeConcatTask() + //InvokeTranscodeTask() +} diff --git a/go.sum b/go.sum index 614a682..9a33a0e 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,9 @@ github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/mozillazg/go-httpheader v0.2.1 h1:geV7TrjbL8KXSyvghnFm+NyTux/hxwueTSrwhe88TQQ= github.com/mozillazg/go-httpheader v0.2.1/go.mod h1:jJ8xECTlalr6ValeXYdOF8fFUISeBAdw6E61aqQma60= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=