add:支持媒体处理任务接口
This commit is contained in:
304
ci_media.go
Normal file
304
ci_media.go
Normal file
@@ -0,0 +1,304 @@
|
|||||||
|
package cos
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/xml"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type JobInput struct {
|
||||||
|
Object string `xml:"Object,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type JobOutput struct {
|
||||||
|
Region string `xml:"Region,omitempty"`
|
||||||
|
Bucket string `xml:"Bucket,omitempty"`
|
||||||
|
Object string `xml:"Object,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Container struct {
|
||||||
|
Format string `xml:"Format"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Video struct {
|
||||||
|
Codec string `xml:"Codec"`
|
||||||
|
Width string `xml:"Width"`
|
||||||
|
Height string `xml:"Height"`
|
||||||
|
Fps string `xml:"Fps"`
|
||||||
|
Remove string `xml:"Remove"`
|
||||||
|
Profile string `xml:"Profile"`
|
||||||
|
Bitrate string `xml:"Bitrate"`
|
||||||
|
Crf string `xml:"Crf"`
|
||||||
|
Gop string `xml:"Gop"`
|
||||||
|
Preset string `xml:"Preset"`
|
||||||
|
Bufsize string `xml:"Bufsize"`
|
||||||
|
Maxrate string `xml:"Maxrate"`
|
||||||
|
HlsTsTime string `xml:"HlsTsTime"`
|
||||||
|
Pixfmt string `xml:"Pixfmt"`
|
||||||
|
LongShortMode string `xml:"LongShortMode"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TimeInterval struct {
|
||||||
|
Start string `xml:"Start"`
|
||||||
|
Duration string `xml:"Duration"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Audio struct {
|
||||||
|
Codec string `xml:"Codec"`
|
||||||
|
Samplerate string `xml:"Samplerate"`
|
||||||
|
Bitrate string `xml:"Bitrate"`
|
||||||
|
Channels string `xml:"Channels"`
|
||||||
|
Remove string `xml:"Remove"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TransConfig struct {
|
||||||
|
AdjDarMethod string `xml:"AdjDarMethod"`
|
||||||
|
IsCheckReso string `xml:"IsCheckReso"`
|
||||||
|
ResoAdjMethod string `xml:"ResoAdjMethod"`
|
||||||
|
IsCheckVideoBitrate string `xml:"IsCheckVideoBitrate"`
|
||||||
|
VideoBitrateAdjMethod string `xml:"VideoBitrateAdjMethod"`
|
||||||
|
IsCheckAudioBitrate string `xml:"IsCheckAudioBitrate"`
|
||||||
|
AudioBitrateAdjMethod string `xml:"AudioBitrateAdjMethod"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Transcode struct {
|
||||||
|
Container *Container `xml:"Container,omitempty"`
|
||||||
|
Video *Video `xml:"Video,omitempty"`
|
||||||
|
TimeInterval *TimeInterval `xml:"TimeInterval,omitempty"`
|
||||||
|
Audio *Audio `xml:"Audio,omitempty"`
|
||||||
|
TransConfig *TransConfig `xml:"TransConfig,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Image struct {
|
||||||
|
Url string `xml:"Url,omitempty"`
|
||||||
|
Mode string `xml:"Mode,omitempty"`
|
||||||
|
Width string `xml:"Width,omitempty"`
|
||||||
|
Height string `xml:"Height,omitempty"`
|
||||||
|
Transparency string `xml:"Transparency,omitempty"`
|
||||||
|
Background string `xml:"Background,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type Text struct {
|
||||||
|
FontSize string `xml:"FontSize,omitempty"`
|
||||||
|
FontType string `xml:"FontType,omitempty"`
|
||||||
|
FontColor string `xml:"FontColor,omitempty"`
|
||||||
|
Transparency string `xml:"Transparency,omitempty"`
|
||||||
|
Text string `xml:"Text,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Watermark struct {
|
||||||
|
Type string `xml:"Type,omitempty"`
|
||||||
|
Pos string `xml:"Pos,omitempty"`
|
||||||
|
LocMode string `xml:"LocMode,omitempty"`
|
||||||
|
Dx string `xml:"Dx,omitempty"`
|
||||||
|
Dy string `xml:"Dy,omitempty"`
|
||||||
|
StartTime string `xml:"StartTime,omitempty"`
|
||||||
|
EndTime string `xml:"EndTime,omitempty"`
|
||||||
|
Image *Image `xml:"Image,omitempty"`
|
||||||
|
Text *Text `xml:"Text,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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateMediaJobsOptions struct {
|
||||||
|
XMLName xml.Name `xml:"Request"`
|
||||||
|
Tag string `xml:"Tag,omitempty"`
|
||||||
|
Input *JobInput `xml:"Input,omitempty"`
|
||||||
|
Operation *MediaProcessJobOperation `xml:"Operation,omitempty"`
|
||||||
|
QueueId string `xml:"QueueId,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MediaProcessJobDetail struct {
|
||||||
|
Code string `xml:"Code,omitempty"`
|
||||||
|
Message string `xml:"Message,omitempty"`
|
||||||
|
JobId string `xml:"JobId,omitempty"`
|
||||||
|
Tag string `xml:"Tag,omitempty"`
|
||||||
|
State string `xml:"State,omitempty"`
|
||||||
|
CreationTime string `xml:"CreationTime,omitempty"`
|
||||||
|
QueueId string `xml:"QueueId,omitempty"`
|
||||||
|
Input *JobInput `xml:"Input,omitempty"`
|
||||||
|
Operation *MediaProcessJobOperation `xml:"Operation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateMediaJobsResult struct {
|
||||||
|
XMLName xml.Name `xml:"Response"`
|
||||||
|
JobsDetail MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CIService) CreateMediaJobs(ctx context.Context, opt *CreateMediaJobsOptions) (*CreateMediaJobsResult, *Response, error) {
|
||||||
|
var res CreateMediaJobsResult
|
||||||
|
sendOpt := sendOptions{
|
||||||
|
baseURL: s.client.BaseURL.CIURL,
|
||||||
|
uri: "/jobs",
|
||||||
|
method: http.MethodPost,
|
||||||
|
body: opt,
|
||||||
|
result: &res,
|
||||||
|
}
|
||||||
|
resp, err := s.client.send(ctx, &sendOpt)
|
||||||
|
return &res, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type DescribeMediaProcessJobResult struct {
|
||||||
|
XMLName xml.Name `xml:"Response"`
|
||||||
|
JobsDetail *MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
|
||||||
|
NonExistJobIds string `xml:"NonExistJobIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CIService) DescribeMediaJobs(ctx context.Context, jobid string) (*DescribeMediaProcessJobResult, *Response, error) {
|
||||||
|
var res DescribeMediaProcessJobResult
|
||||||
|
sendOpt := sendOptions{
|
||||||
|
baseURL: s.client.BaseURL.CIURL,
|
||||||
|
uri: "/jobs/" + jobid,
|
||||||
|
method: http.MethodGet,
|
||||||
|
result: &res,
|
||||||
|
}
|
||||||
|
resp, err := s.client.send(ctx, &sendOpt)
|
||||||
|
return &res, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type DescribeMediaProcessJobsOptions struct {
|
||||||
|
QueueId string `url:"queueId,omitempty"`
|
||||||
|
Tag string `url:"tag,omitempty"`
|
||||||
|
OrderByTime string `url:"orderByTime,omitempty"`
|
||||||
|
NextToken string `url:"nextToken,omitempty"`
|
||||||
|
Size int `url:"size,omitempty"`
|
||||||
|
States string `url:"states,omitempty"`
|
||||||
|
StartCreationTime string `url:"startCreationTime,omitempty"`
|
||||||
|
EndCreationTime string `url:"endCreationTime,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DescribeMediaProcessJobsResult struct {
|
||||||
|
XMLName xml.Name `xml:"Response"`
|
||||||
|
JobsDetail []DocProcessJobDetail `xml:"JobsDetail,omitempty"`
|
||||||
|
NextToken string `xml:"NextToken,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CIService) DescribeMediaProcessJobs(ctx context.Context, opt *DescribeMediaProcessJobsOptions) (*DescribeMediaProcessJobsResult, *Response, error) {
|
||||||
|
var res DescribeMediaProcessJobsResult
|
||||||
|
sendOpt := sendOptions{
|
||||||
|
baseURL: s.client.BaseURL.CIURL,
|
||||||
|
uri: "/jobs",
|
||||||
|
optQuery: opt,
|
||||||
|
method: http.MethodGet,
|
||||||
|
result: &res,
|
||||||
|
}
|
||||||
|
resp, err := s.client.send(ctx, &sendOpt)
|
||||||
|
return &res, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type DescribeMediaProcessQueuesOptions struct {
|
||||||
|
QueueIds string `url:"queueIds,omitempty"`
|
||||||
|
State string `url:"state,omitempty"`
|
||||||
|
PageNumber int `url:"pageNumber,omitempty"`
|
||||||
|
PageSize int `url:"pageSize,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DescribeMediaProcessQueuesResult struct {
|
||||||
|
XMLName xml.Name `xml:"Response"`
|
||||||
|
RequestId string `xml:"RequestId,omitempty"`
|
||||||
|
TotalCount int `xml:"TotalCount,omitempty"`
|
||||||
|
PageNumber int `xml:"PageNumber,omitempty"`
|
||||||
|
PageSize int `xml:"PageSize,omitempty"`
|
||||||
|
QueueList []MediaProcessQueue `xml:"QueueList,omitempty"`
|
||||||
|
NonExistPIDs []string `xml:"NonExistPIDs,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MediaProcessQueue struct {
|
||||||
|
QueueId string `xml:"QueueId,omitempty"`
|
||||||
|
Name string `xml:"Name,omitempty"`
|
||||||
|
State string `xml:"State,omitempty"`
|
||||||
|
MaxSize int `xml:"MaxSize,omitempty"`
|
||||||
|
MaxConcurrent int `xml:"MaxConcurrent,omitempty"`
|
||||||
|
UpdateTime string `xml:"UpdateTime,omitempty"`
|
||||||
|
CreateTime string `xml:"CreateTime,omitempty"`
|
||||||
|
NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MediaProcessQueueNotifyConfig struct {
|
||||||
|
Url string `xml:"Url,omitempty"`
|
||||||
|
State string `xml:"State,omitempty"`
|
||||||
|
Type string `xml:"Type,omitempty"`
|
||||||
|
Event string `xml:"Event,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CIService) DescribeMediaProcessQueues(ctx context.Context, opt *DescribeMediaProcessQueuesOptions) (*DescribeMediaProcessQueuesResult, *Response, error) {
|
||||||
|
var res DescribeMediaProcessQueuesResult
|
||||||
|
sendOpt := sendOptions{
|
||||||
|
baseURL: s.client.BaseURL.CIURL,
|
||||||
|
uri: "/queue",
|
||||||
|
optQuery: opt,
|
||||||
|
method: http.MethodGet,
|
||||||
|
result: &res,
|
||||||
|
}
|
||||||
|
resp, err := s.client.send(ctx, &sendOpt)
|
||||||
|
return &res, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateMediaProcessQueueOptions struct {
|
||||||
|
XMLName xml.Name `xml:"Request"`
|
||||||
|
Name string `xml:"Name,omitempty"`
|
||||||
|
QueueID string `xml:"QueueID,omitempty"`
|
||||||
|
State string `xml:"State,omitempty"`
|
||||||
|
NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateMediaProcessQueueResult struct {
|
||||||
|
XMLName xml.Name `xml:"Response"`
|
||||||
|
RequestId string `xml:"RequestId"`
|
||||||
|
Queue *MediaProcessQueue `xml:"Queue"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CIService) UpdateMediaProcessQueue(ctx context.Context, opt *UpdateMediaProcessQueueOptions) (*UpdateMediaProcessQueueResult, *Response, error) {
|
||||||
|
var res UpdateMediaProcessQueueResult
|
||||||
|
sendOpt := sendOptions{
|
||||||
|
baseURL: s.client.BaseURL.CIURL,
|
||||||
|
uri: "/queue/" + opt.QueueID,
|
||||||
|
body: opt,
|
||||||
|
method: http.MethodPut,
|
||||||
|
result: &res,
|
||||||
|
}
|
||||||
|
resp, err := s.client.send(ctx, &sendOpt)
|
||||||
|
return &res, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type DescribeMediaProcessBucketsOptions struct {
|
||||||
|
Regions string `url:"regions,omitempty"`
|
||||||
|
BucketNames string `url:"bucketNames,omitempty"`
|
||||||
|
BucketName string `url:"bucketName,omitempty"`
|
||||||
|
PageNumber int `url:"pageNumber,omitempty"`
|
||||||
|
PageSize int `url:"pageSize,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DescribeMediaProcessBucketsResult struct {
|
||||||
|
XMLName xml.Name `xml:"Response"`
|
||||||
|
RequestId string `xml:"RequestId,omitempty"`
|
||||||
|
TotalCount int `xml:"TotalCount,omitempty"`
|
||||||
|
PageNumber int `xml:"PageNumber,omitempty"`
|
||||||
|
PageSize int `xml:"PageSize,omitempty"`
|
||||||
|
MediaBucketList []MediaProcessBucket `xml:"MediaBucketList,omitempty"`
|
||||||
|
}
|
||||||
|
type MediaProcessBucket struct {
|
||||||
|
BucketId string `xml:"BucketId,omitempty"`
|
||||||
|
Region string `xml:"Region,omitempty"`
|
||||||
|
CreateTime string `xml:"CreateTime,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CIService) DescribeMediaProcessBuckets(ctx context.Context, opt *DescribeMediaProcessBucketsOptions) (*DescribeMediaProcessBucketsResult, *Response, error) {
|
||||||
|
var res DescribeMediaProcessBucketsResult
|
||||||
|
sendOpt := sendOptions{
|
||||||
|
baseURL: s.client.BaseURL.CIURL,
|
||||||
|
uri: "/mediabucket",
|
||||||
|
optQuery: opt,
|
||||||
|
method: http.MethodGet,
|
||||||
|
result: &res,
|
||||||
|
}
|
||||||
|
resp, err := s.client.send(ctx, &sendOpt)
|
||||||
|
return &res, resp, err
|
||||||
|
}
|
||||||
98
example/media_process/media_process.go
Normal file
98
example/media_process/media_process.go
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/tencentyun/cos-go-sdk-v5"
|
||||||
|
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
func log_status(err error) {
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if cos.IsNotFoundError(err) {
|
||||||
|
// WARN
|
||||||
|
fmt.Println("WARN: Resource is not existed")
|
||||||
|
} else if e, ok := cos.IsCOSError(err); ok {
|
||||||
|
fmt.Printf("ERROR: Code: %v\n", e.Code)
|
||||||
|
fmt.Printf("ERROR: Message: %v\n", e.Message)
|
||||||
|
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
|
||||||
|
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
|
||||||
|
// ERROR
|
||||||
|
} else {
|
||||||
|
fmt.Printf("ERROR: %v\n", err)
|
||||||
|
// ERROR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
fmt.Printf("%+v\n", os.Getenv("COS_SECRETID"))
|
||||||
|
// 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: "Transcode",
|
||||||
|
Input: &cos.JobInput{
|
||||||
|
Object: "input/117374C.mp4",
|
||||||
|
},
|
||||||
|
Operation: &cos.MediaProcessJobOperation{
|
||||||
|
Output: &cos.JobOutput{
|
||||||
|
Region: "ap-chongqing",
|
||||||
|
Object: "output/go_117374C.mp4",
|
||||||
|
Bucket: "wwj-cq-1253960454",
|
||||||
|
},
|
||||||
|
Transcode: &cos.Transcode{
|
||||||
|
Container: &cos.Container{
|
||||||
|
Format: "mp4",
|
||||||
|
},
|
||||||
|
Video: &cos.Video{
|
||||||
|
Codec: "H.264",
|
||||||
|
},
|
||||||
|
Audio: &cos.Audio{
|
||||||
|
Codec: "AAC",
|
||||||
|
},
|
||||||
|
TimeInterval: &cos.TimeInterval{
|
||||||
|
Start: "10",
|
||||||
|
Duration: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
QueueId: "paaf4fce5521a40888a3034a5de80f6ca",
|
||||||
|
}
|
||||||
|
createJobRes, _, err := c.CI.CreateMediaJobs(context.Background(), createJobOpt)
|
||||||
|
log_status(err)
|
||||||
|
fmt.Printf("%+v\n", createJobRes.JobsDetail)
|
||||||
|
|
||||||
|
// DescribeMediaJobs
|
||||||
|
DescribeJobRes, _, err := c.CI.DescribeMediaJobs(context.Background(), createJobRes.JobsDetail.JobId)
|
||||||
|
log_status(err)
|
||||||
|
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user