Skip to content

Commit

Permalink
add:支持拼接任务
Browse files Browse the repository at this point in the history
  • Loading branch information
wanjiewu authored and jojoliang committed Aug 30, 2021
1 parent 4c0eb2d commit ee4f335
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
18 changes: 15 additions & 3 deletions ci_media.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
78 changes: 77 additions & 1 deletion example/CI/media_process/media_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -95,3 +166,8 @@ func main() {
log_status(err)
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail)
}

func main() {
InvokeConcatTask()
//InvokeTranscodeTask()
}
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit ee4f335

Please sign in to comment.