Skip to content

Commit 580b15a

Browse files
authored
Merge pull request #154 from agin719/cos-v4-dev
Cos v4 dev
2 parents be81237 + 2d3f005 commit 580b15a

File tree

2 files changed

+94
-15
lines changed

2 files changed

+94
-15
lines changed

ci_media.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ type JobInput struct {
1111
}
1212

1313
type JobOutput struct {
14-
Region string `xml:"Region,omitempty"`
15-
Bucket string `xml:"Bucket,omitempty"`
16-
Object string `xml:"Object,omitempty"`
14+
Region string `xml:"Region,omitempty"`
15+
Bucket string `xml:"Bucket,omitempty"`
16+
Object string `xml:"Object,omitempty"`
17+
SpriteObject string `xml:"SpriteObject,omitempty"`
1718
}
1819

1920
type Container struct {
@@ -110,13 +111,24 @@ type ConcatTemplate struct {
110111
Index string `xml:"Index,omitempty"`
111112
}
112113

114+
type SpriteSnapshotConfig struct {
115+
CellHeight string `xml:"CellHeight,omitempty"`
116+
CellWidth string `xml:"CellWidth,omitempty"`
117+
Color string `xml:"Color,omitempty"`
118+
Columns string `xml:"Columns,omitempty"`
119+
Lines string `xml:"Lines,omitempty"`
120+
Margin string `xml:"Margin,omitempty"`
121+
Padding string `xml:"Padding,omitempty"`
122+
}
113123
type Snapshot struct {
114-
Mode string `xml:"Mode,omitempty"`
115-
Start string `xml:"Start,omitempty"`
116-
TimeInterval string `xml:"TimeInterval,omitempty"`
117-
Count string `xml:"Count,omitempty"`
118-
Width string `xml:"Width,omitempty"`
119-
Height string `xml:"Height,omitempty"`
124+
Mode string `xml:"Mode,omitempty"`
125+
Start string `xml:"Start,omitempty"`
126+
TimeInterval string `xml:"TimeInterval,omitempty"`
127+
Count string `xml:"Count,omitempty"`
128+
Width string `xml:"Width,omitempty"`
129+
Height string `xml:"Height,omitempty"`
130+
SnapshotOutMode string `xml:"SnapshotOutMode,omitempty"`
131+
SpriteSnapshotConfig *SpriteSnapshotConfig `xml:"SpriteSnapshotConfig,omitempty"`
120132
}
121133

122134
// 有意和转码区分,两种任务关注的参数不一样避免干扰
@@ -265,10 +277,10 @@ type MediaProcessJobsNotifyBody struct {
265277
} `xml:"MediaInfo"`
266278
MediaResult struct {
267279
OutputFile struct {
268-
Bucket string `xml:"Bucket"`
280+
Bucket string `xml:"Bucket"`
269281
ObjectName []string `xml:"ObjectName"`
270-
ObjectPrefix string `xml:"ObjectPrefix"`
271-
Region string `xml:"Region"`
282+
ObjectPrefix string `xml:"ObjectPrefix"`
283+
Region string `xml:"Region"`
272284
} `xml:"OutputFile"`
273285
} `xml:"MediaResult"`
274286
Output struct {

example/CI/media_process/media_process.go

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func TaskNotifyCallback() {
334334
}
335335
}
336336

337-
func WorkflowExecutionNotifyCallback() {
337+
func WorkflowExecutionNotifyCallback() {
338338
workflowExecutionBody := "<Response><EventName>WorkflowFinish</EventName><WorkflowExecution><RunId>i70ae991a152911ecb184525400a8700f</RunId><BucketId></BucketId><Object>62ddbc1245.mp4</Object><CosHeaders><Key>x-cos-meta-id</Key><Value>62ddbc1245</Value></CosHeaders><CosHeaders><Key>Content-Type</Key><Value>video/mp4</Value></CosHeaders><WorkflowId>w29ba54d02b7340dd9fb44eb5beb786b9</WorkflowId><WorkflowName></WorkflowName><CreateTime>2021-09-14 15:00:26+0800</CreateTime><State>Success</State><Tasks><Type>Transcode</Type><CreateTime>2021-09-14 15:00:27+0800</CreateTime><EndTime>2021-09-14 15:00:42+0800</EndTime><State>Success</State><JobId>j70bab192152911ecab79bba409874f7f</JobId><Name>Transcode_1607323983818</Name><TemplateId>t088613dea8d564a9ba7e6b02cbd5de877</TemplateId><TemplateName>HLS-FHD</TemplateName></Tasks></WorkflowExecution></Response>"
339339
var body cos.WorkflowExecutionNotifyBody
340340
err := xml.Unmarshal([]byte(workflowExecutionBody), &body)
@@ -345,11 +345,78 @@ func WorkflowExecutionNotifyCallback() {
345345
}
346346
}
347347

348+
func InvokeSpriteSnapshotTask() {
349+
u, _ := url.Parse("https://wwj-cq-1253960454.cos.ap-chongqing.myqcloud.com")
350+
cu, _ := url.Parse("https://wwj-cq-1253960454.ci.ap-chongqing.myqcloud.com")
351+
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
352+
c := cos.NewClient(b, &http.Client{
353+
Transport: &cos.AuthorizationTransport{
354+
SecretID: os.Getenv("COS_SECRETID"),
355+
SecretKey: os.Getenv("COS_SECRETKEY"),
356+
Transport: &debug.DebugRequestTransport{
357+
RequestHeader: true,
358+
// Notice when put a large file and set need the request body, might happend out of memory error.
359+
RequestBody: true,
360+
ResponseHeader: true,
361+
ResponseBody: true,
362+
},
363+
},
364+
})
365+
// DescribeMediaProcessQueues
366+
DescribeQueueOpt := &cos.DescribeMediaProcessQueuesOptions{
367+
QueueIds: "",
368+
PageNumber: 1,
369+
PageSize: 2,
370+
}
371+
DescribeQueueRes, _, err := c.CI.DescribeMediaProcessQueues(context.Background(), DescribeQueueOpt)
372+
log_status(err)
373+
fmt.Printf("%+v\n", DescribeQueueRes)
374+
// CreateMediaJobs
375+
createJobOpt := &cos.CreateMediaJobsOptions{
376+
Tag: "Snapshot",
377+
Input: &cos.JobInput{
378+
Object: "input/117374C.mp4",
379+
},
380+
Operation: &cos.MediaProcessJobOperation{
381+
Output: &cos.JobOutput{
382+
Region: "ap-chongqing",
383+
Object: "output/abc-${Number}.jpg",
384+
Bucket: "wwj-cq-1253960454",
385+
SpriteObject: "output/sprite-${Number}.jpg",
386+
},
387+
Snapshot: &cos.Snapshot{
388+
Mode: "Interval",
389+
Start: "0",
390+
Count: "100",
391+
SnapshotOutMode: "SnapshotAndSprite", // OnlySnapshot OnlySprite
392+
SpriteSnapshotConfig: &cos.SpriteSnapshotConfig{
393+
CellHeight: "128",
394+
CellWidth: "128",
395+
Color: "Black",
396+
Columns: "3",
397+
Lines: "10",
398+
Margin: "2",
399+
},
400+
},
401+
},
402+
QueueId: DescribeQueueRes.QueueList[0].QueueId,
403+
}
404+
createJobRes, _, err := c.CI.CreateMediaJobs(context.Background(), createJobOpt)
405+
log_status(err)
406+
fmt.Printf("%+v\n", createJobRes.JobsDetail)
407+
408+
// DescribeMediaJobs
409+
DescribeJobRes, _, err := c.CI.DescribeMediaJob(context.Background(), createJobRes.JobsDetail.JobId)
410+
log_status(err)
411+
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail)
412+
}
413+
348414
func main() {
349415
// InvokeSnapshotTask()
350416
// InvokeConcatTask()
351417
// InvokeTranscodeTask()
352418
// InvokeMultiTasks()
353-
TaskNotifyCallback()
354-
WorkflowExecutionNotifyCallback()
419+
// TaskNotifyCallback()
420+
// WorkflowExecutionNotifyCallback()
421+
InvokeSpriteSnapshotTask()
355422
}

0 commit comments

Comments
 (0)