Browse Source

Merge branch 'dev-SpriteSnapshot' into 'master' (merge request !9)

add:支持雪碧图任务
master
jojoliang 3 years ago
parent
commit
2d3f005bbf
  1. 36
      ci_media.go
  2. 73
      example/CI/media_process/media_process.go

36
ci_media.go

@ -11,9 +11,10 @@ type JobInput struct {
}
type JobOutput struct {
Region string `xml:"Region,omitempty"`
Bucket string `xml:"Bucket,omitempty"`
Object string `xml:"Object,omitempty"`
Region string `xml:"Region,omitempty"`
Bucket string `xml:"Bucket,omitempty"`
Object string `xml:"Object,omitempty"`
SpriteObject string `xml:"SpriteObject,omitempty"`
}
type Container struct {
@ -110,13 +111,24 @@ type ConcatTemplate struct {
Index string `xml:"Index,omitempty"`
}
type SpriteSnapshotConfig struct {
CellHeight string `xml:"CellHeight,omitempty"`
CellWidth string `xml:"CellWidth,omitempty"`
Color string `xml:"Color,omitempty"`
Columns string `xml:"Columns,omitempty"`
Lines string `xml:"Lines,omitempty"`
Margin string `xml:"Margin,omitempty"`
Padding string `xml:"Padding,omitempty"`
}
type Snapshot struct {
Mode string `xml:"Mode,omitempty"`
Start string `xml:"Start,omitempty"`
TimeInterval string `xml:"TimeInterval,omitempty"`
Count string `xml:"Count,omitempty"`
Width string `xml:"Width,omitempty"`
Height string `xml:"Height,omitempty"`
Mode string `xml:"Mode,omitempty"`
Start string `xml:"Start,omitempty"`
TimeInterval string `xml:"TimeInterval,omitempty"`
Count string `xml:"Count,omitempty"`
Width string `xml:"Width,omitempty"`
Height string `xml:"Height,omitempty"`
SnapshotOutMode string `xml:"SnapshotOutMode,omitempty"`
SpriteSnapshotConfig *SpriteSnapshotConfig `xml:"SpriteSnapshotConfig,omitempty"`
}
// 有意和转码区分,两种任务关注的参数不一样避免干扰
@ -265,10 +277,10 @@ type MediaProcessJobsNotifyBody struct {
} `xml:"MediaInfo"`
MediaResult struct {
OutputFile struct {
Bucket string `xml:"Bucket"`
Bucket string `xml:"Bucket"`
ObjectName []string `xml:"ObjectName"`
ObjectPrefix string `xml:"ObjectPrefix"`
Region string `xml:"Region"`
ObjectPrefix string `xml:"ObjectPrefix"`
Region string `xml:"Region"`
} `xml:"OutputFile"`
} `xml:"MediaResult"`
Output struct {

73
example/CI/media_process/media_process.go

@ -334,7 +334,7 @@ func TaskNotifyCallback() {
}
}
func WorkflowExecutionNotifyCallback() {
func WorkflowExecutionNotifyCallback() {
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>"
var body cos.WorkflowExecutionNotifyBody
err := xml.Unmarshal([]byte(workflowExecutionBody), &body)
@ -345,11 +345,78 @@ func WorkflowExecutionNotifyCallback() {
}
}
func InvokeSpriteSnapshotTask() {
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,
},
},
})
// 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: "Snapshot",
Input: &cos.JobInput{
Object: "input/117374C.mp4",
},
Operation: &cos.MediaProcessJobOperation{
Output: &cos.JobOutput{
Region: "ap-chongqing",
Object: "output/abc-${Number}.jpg",
Bucket: "wwj-cq-1253960454",
SpriteObject: "output/sprite-${Number}.jpg",
},
Snapshot: &cos.Snapshot{
Mode: "Interval",
Start: "0",
Count: "100",
SnapshotOutMode: "SnapshotAndSprite", // OnlySnapshot OnlySprite
SpriteSnapshotConfig: &cos.SpriteSnapshotConfig{
CellHeight: "128",
CellWidth: "128",
Color: "Black",
Columns: "3",
Lines: "10",
Margin: "2",
},
},
},
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 main() {
// InvokeSnapshotTask()
// InvokeConcatTask()
// InvokeTranscodeTask()
// InvokeMultiTasks()
TaskNotifyCallback()
WorkflowExecutionNotifyCallback()
// TaskNotifyCallback()
// WorkflowExecutionNotifyCallback()
InvokeSpriteSnapshotTask()
}
Loading…
Cancel
Save