@@ -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+
348414func main () {
349415 // InvokeSnapshotTask()
350416 // InvokeConcatTask()
351417 // InvokeTranscodeTask()
352418 // InvokeMultiTasks()
353- TaskNotifyCallback ()
354- WorkflowExecutionNotifyCallback ()
419+ // TaskNotifyCallback()
420+ // WorkflowExecutionNotifyCallback()
421+ InvokeSpriteSnapshotTask ()
355422}
0 commit comments