Skip to content

Commit b4c4a90

Browse files
author
wanjiewu
committed
add:支持md5和进度
1 parent 5bc6c66 commit b4c4a90

File tree

2 files changed

+120
-72
lines changed

2 files changed

+120
-72
lines changed

ci_media.go

Lines changed: 88 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,93 @@ type SuperResolution struct {
216216
EnableScaleUp string `xml:"EnableScaleUp,omitempty"`
217217
}
218218

219+
type MediaResult struct {
220+
OutputFile struct {
221+
Bucket string `xml:"Bucket,omitempty"`
222+
Md5Info []struct {
223+
Md5 string `xml:"Md5,omitempty"`
224+
ObjectName string `xml:"ObjectName,omitempty"`
225+
} `xml:"Md5Info,omitempty"`
226+
ObjectName []string `xml:"ObjectName,omitempty"`
227+
ObjectPrefix string `xml:"ObjectPrefix,omitempty"`
228+
Region string `xml:"Region,omitempty"`
229+
SpriteOutputFile struct {
230+
Bucket string `xml:"Bucket,omitempty"`
231+
Md5Info []struct {
232+
Md5 string `xml:"Md5,omitempty"`
233+
ObjectName string `xml:"ObjectName,omitempty"`
234+
} `xml:"Md5Info,omitempty"`
235+
ObjectName []string `xml:"ObjectName,omitempty"`
236+
ObjectPrefix string `xml:"ObjectPrefix,omitempty"`
237+
Region string `xml:"Region,omitempty"`
238+
} `xml:"SpriteOutputFile,omitempty"`
239+
} `xml:"OutputFile,omitempty"`
240+
}
241+
242+
type MediaInfo struct {
243+
Format struct {
244+
Bitrate string `xml:"Bitrate"`
245+
Duration string `xml:"Duration"`
246+
FormatLongName string `xml:"FormatLongName"`
247+
FormatName string `xml:"FormatName"`
248+
NumProgram string `xml:"NumProgram"`
249+
NumStream string `xml:"NumStream"`
250+
Size string `xml:"Size"`
251+
StartTime string `xml:"StartTime"`
252+
} `xml:"Format"`
253+
Stream struct {
254+
Audio []struct {
255+
Bitrate string `xml:"Bitrate"`
256+
Channel string `xml:"Channel"`
257+
ChannelLayout string `xml:"ChannelLayout"`
258+
CodecLongName string `xml:"CodecLongName"`
259+
CodecName string `xml:"CodecName"`
260+
CodecTag string `xml:"CodecTag"`
261+
CodecTagString string `xml:"CodecTagString"`
262+
CodecTimeBase string `xml:"CodecTimeBase"`
263+
Duration string `xml:"Duration"`
264+
Index string `xml:"Index"`
265+
Language string `xml:"Language"`
266+
SampleFmt string `xml:"SampleFmt"`
267+
SampleRate string `xml:"SampleRate"`
268+
StartTime string `xml:"StartTime"`
269+
Timebase string `xml:"Timebase"`
270+
} `xml:"Audio"`
271+
Subtitle string `xml:"Subtitle"`
272+
Video []struct {
273+
AvgFps string `xml:"AvgFps"`
274+
Bitrate string `xml:"Bitrate"`
275+
CodecLongName string `xml:"CodecLongName"`
276+
CodecName string `xml:"CodecName"`
277+
CodecTag string `xml:"CodecTag"`
278+
CodecTagString string `xml:"CodecTagString"`
279+
CodecTimeBase string `xml:"CodecTimeBase"`
280+
Dar string `xml:"Dar"`
281+
Duration string `xml:"Duration"`
282+
Fps string `xml:"Fps"`
283+
HasBFrame string `xml:"HasBFrame"`
284+
Height string `xml:"Height"`
285+
Index string `xml:"Index"`
286+
Language string `xml:"Language"`
287+
Level string `xml:"Level"`
288+
NumFrames string `xml:"NumFrames"`
289+
PixFormat string `xml:"PixFormat"`
290+
Profile string `xml:"Profile"`
291+
RefFrames string `xml:"RefFrames"`
292+
Rotation string `xml:"Rotation"`
293+
Sar string `xml:"Sar"`
294+
StartTime string `xml:"StartTime"`
295+
Timebase string `xml:"Timebase"`
296+
Width string `xml:"Width"`
297+
} `xml:"Video"`
298+
} `xml:"Stream"`
299+
}
300+
219301
type MediaProcessJobOperation struct {
220302
Tag string `xml:"Tag,omitempty"`
221303
Output *JobOutput `xml:"Output,omitempty"`
304+
MediaResult *MediaResult `xml:"MediaResult,omitempty"`
305+
MediaInfo *MediaInfo `xml:"MediaInfo,omitempty"`
222306
Transcode *Transcode `xml:"Transcode,omitempty"`
223307
Watermark []Watermark `xml:"Watermark,omitempty"`
224308
TemplateId string `xml:"TemplateId,omitempty"`
@@ -249,6 +333,7 @@ type MediaProcessJobDetail struct {
249333
Message string `xml:"Message,omitempty"`
250334
JobId string `xml:"JobId,omitempty"`
251335
Tag string `xml:"Tag,omitempty"`
336+
Progress string `xml:"Progress,omitempty"`
252337
State string `xml:"State,omitempty"`
253338
CreationTime string `xml:"CreationTime,omitempty"`
254339
QueueId string `xml:"QueueId,omitempty"`
@@ -290,74 +375,9 @@ type MediaProcessJobsNotifyBody struct {
290375
JobId string `xml:"JobId"`
291376
Message string `xml:"Message"`
292377
Operation struct {
293-
MediaInfo struct {
294-
Format struct {
295-
Text string `xml:",chardata"`
296-
Bitrate string `xml:"Bitrate"`
297-
Duration string `xml:"Duration"`
298-
FormatLongName string `xml:"FormatLongName"`
299-
FormatName string `xml:"FormatName"`
300-
NumProgram string `xml:"NumProgram"`
301-
NumStream string `xml:"NumStream"`
302-
Size string `xml:"Size"`
303-
StartTime string `xml:"StartTime"`
304-
} `xml:"Format"`
305-
Stream struct {
306-
Audio []struct {
307-
Bitrate string `xml:"Bitrate"`
308-
Channel string `xml:"Channel"`
309-
ChannelLayout string `xml:"ChannelLayout"`
310-
CodecLongName string `xml:"CodecLongName"`
311-
CodecName string `xml:"CodecName"`
312-
CodecTag string `xml:"CodecTag"`
313-
CodecTagString string `xml:"CodecTagString"`
314-
CodecTimeBase string `xml:"CodecTimeBase"`
315-
Duration string `xml:"Duration"`
316-
Index string `xml:"Index"`
317-
Language string `xml:"Language"`
318-
SampleFmt string `xml:"SampleFmt"`
319-
SampleRate string `xml:"SampleRate"`
320-
StartTime string `xml:"StartTime"`
321-
Timebase string `xml:"Timebase"`
322-
} `xml:"Audio"`
323-
Subtitle string `xml:"Subtitle"`
324-
Video []struct {
325-
AvgFps string `xml:"AvgFps"`
326-
Bitrate string `xml:"Bitrate"`
327-
CodecLongName string `xml:"CodecLongName"`
328-
CodecName string `xml:"CodecName"`
329-
CodecTag string `xml:"CodecTag"`
330-
CodecTagString string `xml:"CodecTagString"`
331-
CodecTimeBase string `xml:"CodecTimeBase"`
332-
Dar string `xml:"Dar"`
333-
Duration string `xml:"Duration"`
334-
Fps string `xml:"Fps"`
335-
HasBFrame string `xml:"HasBFrame"`
336-
Height string `xml:"Height"`
337-
Index string `xml:"Index"`
338-
Language string `xml:"Language"`
339-
Level string `xml:"Level"`
340-
NumFrames string `xml:"NumFrames"`
341-
PixFormat string `xml:"PixFormat"`
342-
Profile string `xml:"Profile"`
343-
RefFrames string `xml:"RefFrames"`
344-
Rotation string `xml:"Rotation"`
345-
Sar string `xml:"Sar"`
346-
StartTime string `xml:"StartTime"`
347-
Timebase string `xml:"Timebase"`
348-
Width string `xml:"Width"`
349-
} `xml:"Video"`
350-
} `xml:"Stream"`
351-
} `xml:"MediaInfo"`
352-
MediaResult struct {
353-
OutputFile struct {
354-
Bucket string `xml:"Bucket"`
355-
ObjectName []string `xml:"ObjectName"`
356-
ObjectPrefix string `xml:"ObjectPrefix"`
357-
Region string `xml:"Region"`
358-
} `xml:"OutputFile"`
359-
} `xml:"MediaResult"`
360-
Output struct {
378+
MediaInfo *MediaInfo `xml:"MediaInfo"`
379+
MediaResult *MediaResult `xml:"MediaResult"`
380+
Output struct {
361381
Bucket string `xml:"Bucket"`
362382
Object string `xml:"Object"`
363383
Region string `xml:"Region"`

example/CI/media_process/media_process.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,15 @@ func InvokeMultiJobs() {
325325
}
326326

327327
func JobNotifyCallback() {
328-
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>"
328+
taskBody := "<Response><JobsDetail><Code>Success</Code><CreationTime>2022-02-09T11:25:43+0800</CreationTime><EndTime>2022-02-09T11:25:47+0800</EndTime><Input><BucketId>wwj-cq-1253960454</BucketId><Object>input/117374C.mp4</Object><Region>ap-chongqing</Region></Input><JobId>jf6717076895711ecafdd594be6cca70c</JobId><Message/><Operation><MediaInfo><Format><Bitrate>215.817000</Bitrate><Duration>96.931000</Duration><FormatLongName>QuickTime / MOV</FormatLongName><FormatName>mov,mp4,m4a,3gp,3g2,mj2</FormatName><NumProgram>0</NumProgram><NumStream>1</NumStream><Size>2614921</Size><StartTime>0.000000</StartTime></Format><Stream><Audio/><Subtitle/><Video><AvgFps>29.970030</AvgFps><Bitrate>212.875000</Bitrate><CodecLongName>H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10</CodecLongName><CodecName>h264</CodecName><CodecTag>0x31637661</CodecTag><CodecTagString>avc1</CodecTagString><CodecTimeBase>1/30000</CodecTimeBase><Dar>16:9</Dar><Duration>96.930167</Duration><Fps>29.970030</Fps><HasBFrame>2</HasBFrame><Height>400</Height><Index>0</Index><Language>und</Language><Level>30</Level><NumFrames>2905</NumFrames><PixFormat>yuv420p</PixFormat><Profile>High</Profile><RefFrames>1</RefFrames><Rotation>0.000000</Rotation><Sar>640:639</Sar><StartTime>0.000000</StartTime><Timebase>1/30000</Timebase><Width>710</Width></Video></Stream></MediaInfo><MediaResult><OutputFile><Bucket>wwj-cq-1253960454</Bucket><Md5Info><Md5>38f0b40c78562f819421137541043f09</Md5><ObjectName>output/go_117374C.mp4</ObjectName></Md5Info><ObjectName>output/go_117374C.mp4</ObjectName><ObjectPrefix/><Region>ap-chongqing</Region><SpriteOutputFile><Bucket/><Md5Info/><ObjectName/><ObjectPrefix/><Region/></SpriteOutputFile></OutputFile></MediaResult><Output><Bucket>wwj-cq-1253960454</Bucket><Object>output/go_117374C.mp4</Object><Region>ap-chongqing</Region></Output><Transcode><Audio><Bitrate/><Channels/><Codec>AAC</Codec><KeepTwoTracks>false</KeepTwoTracks><Profile/><Remove>false</Remove><SampleFormat/><Samplerate>44100</Samplerate><SwitchTrack>false</SwitchTrack></Audio><Container><Format>mp4</Format></Container><TimeInterval><Duration/><Start>10</Start></TimeInterval><TransConfig><AdjDarMethod/><AudioBitrateAdjMethod/><DeleteMetadata>false</DeleteMetadata><IsCheckAudioBitrate>false</IsCheckAudioBitrate><IsCheckReso>false</IsCheckReso><IsCheckVideoBitrate>false</IsCheckVideoBitrate><IsHdr2Sdr>false</IsHdr2Sdr><IsStreamCopy>false</IsStreamCopy><ResoAdjMethod/><VideoBitrateAdjMethod/></TransConfig><Video><AnimateFramesPerSecond/><AnimateOnlyKeepKeyFrame>false</AnimateOnlyKeepKeyFrame><AnimateTimeIntervalOfFrame/><Bitrate/><Bufsize/><Codec>H.264</Codec><Crf>25</Crf><Crop/><Fps/><Gop/><Height/><Interlaced>false</Interlaced><LongShortMode>false</LongShortMode><Maxrate/><Pad/><Pixfmt/><Preset>medium</Preset><Profile>high</Profile><Quality/><Remove>false</Remove><ScanMode/><SliceTime>5</SliceTime><Width/></Video></Transcode></Operation><Progress>100</Progress><QueueId>paaf4fce5521a40888a3034a5de80f6ca</QueueId><StartTime>2022-02-09T11:25:43+0800</StartTime><State>Success</State><Tag>Transcode</Tag></JobsDetail></Response>"
329329
var body cos.MediaProcessJobsNotifyBody
330330
err := xml.Unmarshal([]byte(taskBody), &body)
331331
if err != nil {
332332
fmt.Println(fmt.Sprintf("err:%v", err))
333333
} else {
334-
fmt.Println(fmt.Sprintf("body:%v", body))
334+
fmt.Println(fmt.Sprintf("body:%+v", body))
335+
fmt.Println(fmt.Sprintf("mediaInfo:%+v", body.JobsDetail.Operation.MediaInfo))
336+
fmt.Println(fmt.Sprintf("mediaResult:%+v", body.JobsDetail.Operation.MediaResult))
335337
}
336338
}
337339

@@ -1013,6 +1015,31 @@ func DescribeASRJob() {
10131015
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail[0].Operation.SpeechRecognitionResult)
10141016
}
10151017

1018+
func DescribeJob() {
1019+
u, _ := url.Parse("https://wwj-cq-1253960454.cos.ap-chongqing.myqcloud.com")
1020+
cu, _ := url.Parse("https://wwj-cq-1253960454.ci.ap-chongqing.myqcloud.com")
1021+
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
1022+
c := cos.NewClient(b, &http.Client{
1023+
Transport: &cos.AuthorizationTransport{
1024+
SecretID: os.Getenv("COS_SECRETID"),
1025+
SecretKey: os.Getenv("COS_SECRETKEY"),
1026+
Transport: &debug.DebugRequestTransport{
1027+
RequestHeader: true,
1028+
// Notice when put a large file and set need the request body, might happend out of memory error.
1029+
RequestBody: true,
1030+
ResponseHeader: true,
1031+
ResponseBody: true,
1032+
},
1033+
},
1034+
})
1035+
// DescribeMediaJobs
1036+
DescribeJobRes, _, err := c.CI.DescribeMediaJob(context.Background(), "jf6717076895711ecafdd594be6cca70c")
1037+
log_status(err)
1038+
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail)
1039+
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail.Operation.MediaInfo)
1040+
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail.Operation.MediaResult)
1041+
}
1042+
10161043
func main() {
10171044
// InvokeSnapshotJob()
10181045
// InvokeConcatJob()
@@ -1032,6 +1059,7 @@ func main() {
10321059
// TriggerWorkflow()
10331060
// DescribeWorkflowExecutions()
10341061
// DescribeMultiWorkflowExecution()
1035-
//InvokeASRJob()
1036-
DescribeASRJob()
1062+
// InvokeASRJob()
1063+
// DescribeASRJob()
1064+
DescribeJob()
10371065
}

0 commit comments

Comments
 (0)