Browse Source

Merge pull request #153 from agin719/cos-v4-dev

Cos v4 dev
master
agin719 3 years ago
committed by GitHub
parent
commit
5acf7d6c9e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 128
      ci_media.go
  2. 27
      example/CI/media_process/media_process.go

128
ci_media.go

@ -189,6 +189,134 @@ type CreateMultiMediaJobsResult struct {
JobsDetail []MediaProcessJobDetail `xml:"JobsDetail,omitempty"` JobsDetail []MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
} }
type MediaProcessJobsNotifyBody struct {
XMLName xml.Name `xml:"Response"`
EventName string `xml:"EventName"`
JobsDetail struct {
Code string `xml:"Code"`
CreationTime string `xml:"CreationTime"`
EndTime string `xml:"EndTime"`
Input struct {
BucketId string `xml:"BucketId"`
Object string `xml:"Object"`
Region string `xml:"Region"`
} `xml:"Input"`
JobId string `xml:"JobId"`
Message string `xml:"Message"`
Operation struct {
MediaInfo struct {
Format struct {
Text string `xml:",chardata"`
Bitrate string `xml:"Bitrate"`
Duration string `xml:"Duration"`
FormatLongName string `xml:"FormatLongName"`
FormatName string `xml:"FormatName"`
NumProgram string `xml:"NumProgram"`
NumStream string `xml:"NumStream"`
Size string `xml:"Size"`
StartTime string `xml:"StartTime"`
} `xml:"Format"`
Stream struct {
Audio []struct {
Bitrate string `xml:"Bitrate"`
Channel string `xml:"Channel"`
ChannelLayout string `xml:"ChannelLayout"`
CodecLongName string `xml:"CodecLongName"`
CodecName string `xml:"CodecName"`
CodecTag string `xml:"CodecTag"`
CodecTagString string `xml:"CodecTagString"`
CodecTimeBase string `xml:"CodecTimeBase"`
Duration string `xml:"Duration"`
Index string `xml:"Index"`
Language string `xml:"Language"`
SampleFmt string `xml:"SampleFmt"`
SampleRate string `xml:"SampleRate"`
StartTime string `xml:"StartTime"`
Timebase string `xml:"Timebase"`
} `xml:"Audio"`
Subtitle string `xml:"Subtitle"`
Video []struct {
AvgFps string `xml:"AvgFps"`
Bitrate string `xml:"Bitrate"`
CodecLongName string `xml:"CodecLongName"`
CodecName string `xml:"CodecName"`
CodecTag string `xml:"CodecTag"`
CodecTagString string `xml:"CodecTagString"`
CodecTimeBase string `xml:"CodecTimeBase"`
Dar string `xml:"Dar"`
Duration string `xml:"Duration"`
Fps string `xml:"Fps"`
HasBFrame string `xml:"HasBFrame"`
Height string `xml:"Height"`
Index string `xml:"Index"`
Language string `xml:"Language"`
Level string `xml:"Level"`
NumFrames string `xml:"NumFrames"`
PixFormat string `xml:"PixFormat"`
Profile string `xml:"Profile"`
RefFrames string `xml:"RefFrames"`
Rotation string `xml:"Rotation"`
Sar string `xml:"Sar"`
StartTime string `xml:"StartTime"`
Timebase string `xml:"Timebase"`
Width string `xml:"Width"`
} `xml:"Video"`
} `xml:"Stream"`
} `xml:"MediaInfo"`
MediaResult struct {
OutputFile struct {
Bucket string `xml:"Bucket"`
ObjectName string `xml:"ObjectName"`
ObjectPrefix string `xml:"ObjectPrefix"`
Region string `xml:"Region"`
} `xml:"OutputFile"`
} `xml:"MediaResult"`
Output struct {
Bucket string `xml:"Bucket"`
Object string `xml:"Object"`
Region string `xml:"Region"`
} `xml:"Output"`
TemplateId string `xml:"TemplateId"`
TemplateName string `xml:"TemplateName"`
} `xml:"Operation"`
QueueId string `xml:"QueueId"`
StartTime string `xml:"StartTime"`
State string `xml:"State"`
Tag string `xml:"Tag"`
} `xml:"JobsDetail"`
}
type WorkflowExecutionNotifyBody struct {
XMLName xml.Name `xml:"Response"`
EventName string `xml:"EventName"`
WorkflowExecution struct {
RunId string `xml:"RunId"`
BucketId string `xml:"BucketId"`
Object string `xml:"Object"`
CosHeaders []struct {
Key string `xml:"Key"`
Value string `xml:"Value"`
} `xml:"CosHeaders"`
WorkflowId string `xml:"WorkflowId"`
WorkflowName string `xml:"WorkflowName"`
CreateTime string `xml:"CreateTime"`
State string `xml:"State"`
Tasks []struct {
Type string `xml:"Type"`
CreateTime string `xml:"CreateTime"`
EndTime string `xml:"EndTime"`
State string `xml:"State"`
JobId string `xml:"JobId"`
Name string `xml:"Name"`
TemplateId string `xml:"TemplateId"`
TemplateName string `xml:"TemplateName"`
TranscodeTemplateId string `xml:"TranscodeTemplateId,omitempty"`
TranscodeTemplateName string `xml:"TranscodeTemplateName,omitempty"`
HdrMode string `xml:"HdrMode,omitempty"`
} `xml:"Tasks"`
} `xml:"WorkflowExecution"`
}
func (s *CIService) CreateMultiMediaJobs(ctx context.Context, opt *CreateMultiMediaJobsOptions) (*CreateMultiMediaJobsResult, *Response, error) { func (s *CIService) CreateMultiMediaJobs(ctx context.Context, opt *CreateMultiMediaJobsOptions) (*CreateMultiMediaJobsResult, *Response, error) {
var res CreateMultiMediaJobsResult var res CreateMultiMediaJobsResult
sendOpt := sendOptions{ sendOpt := sendOptions{

27
example/CI/media_process/media_process.go

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"encoding/xml"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
@ -322,9 +323,33 @@ func InvokeMultiTasks() {
} }
} }
func TaskNotifyCallback() {
taskBody := "<Response><EventName>TaskFinish</EventName><JobsDetail><Code>Success</Code><CreationTime>2021-09-14T14:38:59+0800</CreationTime><EndTime>2021-09-14T14:39:59+0800</EndTime><Input><BucketId></BucketId><Object>e28ef88b61ed41b7a6ea76a8147f4f9e</Object><Region>ap-guangzhou</Region></Input><JobId>j7123e78c152611ec9e8c1ba6632b91a8</JobId><Message/><Operation><MediaInfo><Format><Bitrate>3775.738000</Bitrate><Duration>143.732000</Duration><FormatLongName>QuickTime / MOV</FormatLongName><FormatName>mov,mp4,m4a,3gp,3g2,mj2</FormatName><NumProgram>0</NumProgram><NumStream>2</NumStream><Size>67836813</Size><StartTime>0.000000</StartTime></Format><Stream><Audio><Bitrate>125.049000</Bitrate><Channel>2</Channel><ChannelLayout>stereo</ChannelLayout><CodecLongName>AAC (Advanced Audio Coding)</CodecLongName><CodecName>aac</CodecName><CodecTag>0x6134706d</CodecTag><CodecTagString>mp4a</CodecTagString><CodecTimeBase>1/44100</CodecTimeBase><Duration>143.730998</Duration><Index>1</Index><Language>und</Language><SampleFmt>fltp</SampleFmt><SampleRate>44100</SampleRate><StartTime>0.000000</StartTime><Timebase>1/44100</Timebase></Audio><Subtitle/><Video><AvgFps>25/1</AvgFps><Bitrate>3645.417000</Bitrate><CodecLongName>H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10</CodecLongName><CodecName>h264</CodecName><CodecTag>0x31637661</CodecTag><CodecTagString>avc1</CodecTagString><CodecTimeBase>1/12800</CodecTimeBase><Dar>9:16</Dar><Duration>143.680000</Duration><Fps>25.500000</Fps><HasBFrame>2</HasBFrame><Height>3412</Height><Index>0</Index><Language>und</Language><Level>51</Level><NumFrames>3592</NumFrames><PixFormat>yuv420p</PixFormat><Profile>High</Profile><RefFrames>1</RefFrames><Rotation>0.000000</Rotation><Sar>2559:2560</Sar><StartTime>0.000000</StartTime><Timebase>1/12800</Timebase><Width>1920</Width></Video></Stream></MediaInfo><MediaResult><OutputFile><Bucket></Bucket><ObjectName>f89f22f7a8be4f478434da58eb11d7da.mp4</ObjectName><ObjectPrefix/><Region>ap-guangzhou</Region></OutputFile></MediaResult><Output><Bucket></Bucket><Object>f89f22f7a8be4f478434da58eb11d7da.mp4</Object><Region>ap-guangzhou</Region></Output><TemplateId>t064fb9214850f49aaac44b5561a7b0b3b</TemplateId><TemplateName>MP4-FHD</TemplateName></Operation><QueueId>p6f358a37bf9442ad8f859db055cd0edb</QueueId><StartTime>2021-09-14T14:38:59+0800</StartTime><State>Success</State><Tag>Transcode</Tag></JobsDetail></Response>"
var body cos.MediaProcessJobsNotifyBody
err := xml.Unmarshal([]byte(taskBody), &body)
if err != nil {
fmt.Println(fmt.Sprintf("err:%v", err))
} else {
fmt.Println(fmt.Sprintf("body:%v", body))
}
}
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)
if err != nil {
fmt.Println(fmt.Sprintf("err:%v", err))
} else {
fmt.Println(fmt.Sprintf("body:%v", body))
}
}
func main() { func main() {
// InvokeSnapshotTask() // InvokeSnapshotTask()
// InvokeConcatTask() // InvokeConcatTask()
// InvokeTranscodeTask() // InvokeTranscodeTask()
InvokeMultiTasks()
// InvokeMultiTasks()
TaskNotifyCallback()
WorkflowExecutionNotifyCallback()
} }
Loading…
Cancel
Save