Browse Source

Merge pull request #145 from agin719/cos-v4-dev

Cos v4 dev
master
agin719 3 years ago
committed by GitHub
parent
commit
cc2aa8af93
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      ci_media.go
  2. 2
      cos.go
  3. 78
      example/CI/media_process/media_process.go

28
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"`
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 {

2
cos.go

@ -22,7 +22,7 @@ import (
const (
// Version current go sdk version
Version = "0.7.30"
Version = "0.7.31"
userAgent = "cos-go-sdk-v5/" + Version
contentTypeXML = "application/xml"
defaultServiceBaseURL = "http://service.cos.myqcloud.com"

78
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()
}
Loading…
Cancel
Save