You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

642 lines
23 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "fmt"
  6. "net/http"
  7. )
  8. type JobInput struct {
  9. Object string `xml:"Object,omitempty"`
  10. }
  11. type JobOutput struct {
  12. Region string `xml:"Region,omitempty"`
  13. Bucket string `xml:"Bucket,omitempty"`
  14. Object string `xml:"Object,omitempty"`
  15. SpriteObject string `xml:"SpriteObject,omitempty"`
  16. }
  17. type Container struct {
  18. Format string `xml:"Format"`
  19. }
  20. type Video struct {
  21. Codec string `xml:"Codec"`
  22. Width string `xml:"Width"`
  23. Height string `xml:"Height"`
  24. Fps string `xml:"Fps"`
  25. Remove string `xml:"Remove,omitempty"`
  26. Profile string `xml:"Profile"`
  27. Bitrate string `xml:"Bitrate"`
  28. Crf string `xml:"Crf"`
  29. Gop string `xml:"Gop"`
  30. Preset string `xml:"Preset"`
  31. Bufsize string `xml:"Bufsize"`
  32. Maxrate string `xml:"Maxrate"`
  33. HlsTsTime string `xml:"HlsTsTime"`
  34. Pixfmt string `xml:"Pixfmt"`
  35. LongShortMode string `xml:"LongShortMode"`
  36. }
  37. type TimeInterval struct {
  38. Start string `xml:"Start"`
  39. Duration string `xml:"Duration"`
  40. }
  41. type Audio struct {
  42. Codec string `xml:"Codec"`
  43. Samplerate string `xml:"Samplerate"`
  44. Bitrate string `xml:"Bitrate"`
  45. Channels string `xml:"Channels"`
  46. Remove string `xml:"Remove,omitempty"`
  47. }
  48. type TransConfig struct {
  49. AdjDarMethod string `xml:"AdjDarMethod"`
  50. IsCheckReso string `xml:"IsCheckReso"`
  51. ResoAdjMethod string `xml:"ResoAdjMethod"`
  52. IsCheckVideoBitrate string `xml:"IsCheckVideoBitrate"`
  53. VideoBitrateAdjMethod string `xml:"VideoBitrateAdjMethod"`
  54. IsCheckAudioBitrate string `xml:"IsCheckAudioBitrate"`
  55. AudioBitrateAdjMethod string `xml:"AudioBitrateAdjMethod"`
  56. }
  57. type Transcode struct {
  58. Container *Container `xml:"Container,omitempty"`
  59. Video *Video `xml:"Video,omitempty"`
  60. TimeInterval *TimeInterval `xml:"TimeInterval,omitempty"`
  61. Audio *Audio `xml:"Audio,omitempty"`
  62. TransConfig *TransConfig `xml:"TransConfig,omitempty"`
  63. }
  64. type Image struct {
  65. Url string `xml:"Url,omitempty"`
  66. Mode string `xml:"Mode,omitempty"`
  67. Width string `xml:"Width,omitempty"`
  68. Height string `xml:"Height,omitempty"`
  69. Transparency string `xml:"Transparency,omitempty"`
  70. Background string `xml:"Background,omitempty"`
  71. }
  72. type Text struct {
  73. FontSize string `xml:"FontSize,omitempty"`
  74. FontType string `xml:"FontType,omitempty"`
  75. FontColor string `xml:"FontColor,omitempty"`
  76. Transparency string `xml:"Transparency,omitempty"`
  77. Text string `xml:"Text,omitempty"`
  78. }
  79. type Watermark struct {
  80. Type string `xml:"Type,omitempty"`
  81. Pos string `xml:"Pos,omitempty"`
  82. LocMode string `xml:"LocMode,omitempty"`
  83. Dx string `xml:"Dx,omitempty"`
  84. Dy string `xml:"Dy,omitempty"`
  85. StartTime string `xml:"StartTime,omitempty"`
  86. EndTime string `xml:"EndTime,omitempty"`
  87. Image *Image `xml:"Image,omitempty"`
  88. Text *Text `xml:"Text,omitempty"`
  89. }
  90. type ConcatFragment struct {
  91. Url string `xml:"Url,omitempty"`
  92. StartTime string `xml:"StartTime,omitempty"`
  93. EndTime string `xml:"EndTime,omitempty"`
  94. }
  95. type ConcatTemplate struct {
  96. ConcatFragment []ConcatFragment `xml:"ConcatFragment,omitempty"`
  97. Audio *Audio `xml:"Audio,omitempty"`
  98. Video *Video `xml:"Video,omitempty"`
  99. Container *Container `xml:"Container,omitempty"`
  100. Index string `xml:"Index,omitempty"`
  101. }
  102. type SpriteSnapshotConfig struct {
  103. CellHeight string `xml:"CellHeight,omitempty"`
  104. CellWidth string `xml:"CellWidth,omitempty"`
  105. Color string `xml:"Color,omitempty"`
  106. Columns string `xml:"Columns,omitempty"`
  107. Lines string `xml:"Lines,omitempty"`
  108. Margin string `xml:"Margin,omitempty"`
  109. Padding string `xml:"Padding,omitempty"`
  110. }
  111. type Snapshot struct {
  112. Mode string `xml:"Mode,omitempty"`
  113. Start string `xml:"Start,omitempty"`
  114. TimeInterval string `xml:"TimeInterval,omitempty"`
  115. Count string `xml:"Count,omitempty"`
  116. Width string `xml:"Width,omitempty"`
  117. Height string `xml:"Height,omitempty"`
  118. SnapshotOutMode string `xml:"SnapshotOutMode,omitempty"`
  119. SpriteSnapshotConfig *SpriteSnapshotConfig `xml:"SpriteSnapshotConfig,omitempty"`
  120. }
  121. // 有意和转码区分,两种任务关注的参数不一样避免干扰
  122. type AnimationVideo struct {
  123. Codec string `xml:"Codec"`
  124. Width string `xml:"Width"`
  125. Height string `xml:"Height"`
  126. Fps string `xml:"Fps"`
  127. AnimateOnlyKeepKeyFrame string `xml:"AnimateOnlyKeepKeyFrame"`
  128. AnimateTimeIntervalOfFrame string `xml:"AnimateTimeIntervalOfFrame"`
  129. AnimateFramesPerSecond string `xml:"AnimateFramesPerSecond"`
  130. Quality string `xml:"Quality"`
  131. }
  132. type Animation struct {
  133. Container *Container `xml:"Container,omitempty"`
  134. Video *AnimationVideo `xml:"Video,omitempty"`
  135. TimeInterval *TimeInterval `xml:"TimeInterval,omitempty"`
  136. }
  137. type Segment struct {
  138. Format string `xml:"Format,omitempty"`
  139. Duration string `xml:"Duration,omitempty"`
  140. }
  141. type MediaProcessJobOperation struct {
  142. Tag string `xml:"Tag,omitempty"`
  143. Output *JobOutput `xml:"Output,omitempty"`
  144. Transcode *Transcode `xml:"Transcode,omitempty"`
  145. Watermark *Watermark `xml:"Watermark,omitempty"`
  146. TemplateId string `xml:"TemplateId,omitempty"`
  147. WatermarkTemplateId []string `xml:"WatermarkTemplateId,omitempty"`
  148. ConcatTemplate *ConcatTemplate `xml:"ConcatTemplate,omitempty"`
  149. Snapshot *Snapshot `xml:"Snapshot,omitempty"`
  150. Animation *Animation `xml:"Animation,omitempty"`
  151. Segment *Segment `xml:"Segment,omitempty"`
  152. }
  153. type CreateMediaJobsOptions struct {
  154. XMLName xml.Name `xml:"Request"`
  155. Tag string `xml:"Tag,omitempty"`
  156. Input *JobInput `xml:"Input,omitempty"`
  157. Operation *MediaProcessJobOperation `xml:"Operation,omitempty"`
  158. QueueId string `xml:"QueueId,omitempty"`
  159. CallBack string `xml:"CallBack,omitempty"`
  160. }
  161. type MediaProcessJobDetail struct {
  162. Code string `xml:"Code,omitempty"`
  163. Message string `xml:"Message,omitempty"`
  164. JobId string `xml:"JobId,omitempty"`
  165. Tag string `xml:"Tag,omitempty"`
  166. State string `xml:"State,omitempty"`
  167. CreationTime string `xml:"CreationTime,omitempty"`
  168. QueueId string `xml:"QueueId,omitempty"`
  169. Input *JobInput `xml:"Input,omitempty"`
  170. Operation *MediaProcessJobOperation `xml:"Operation,omitempty"`
  171. }
  172. type CreateMediaJobsResult struct {
  173. XMLName xml.Name `xml:"Response"`
  174. JobsDetail *MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
  175. }
  176. type CreateMultiMediaJobsOptions struct {
  177. XMLName xml.Name `xml:"Request"`
  178. Tag string `xml:"Tag,omitempty"`
  179. Input *JobInput `xml:"Input,omitempty"`
  180. Operation []MediaProcessJobOperation `xml:"Operation,omitempty"`
  181. QueueId string `xml:"QueueId,omitempty"`
  182. CallBack string `xml:"CallBack,omitempty"`
  183. }
  184. type CreateMultiMediaJobsResult struct {
  185. XMLName xml.Name `xml:"Response"`
  186. JobsDetail []MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
  187. }
  188. type MediaProcessJobsNotifyBody struct {
  189. XMLName xml.Name `xml:"Response"`
  190. EventName string `xml:"EventName"`
  191. JobsDetail struct {
  192. Code string `xml:"Code"`
  193. CreationTime string `xml:"CreationTime"`
  194. EndTime string `xml:"EndTime"`
  195. Input struct {
  196. BucketId string `xml:"BucketId"`
  197. Object string `xml:"Object"`
  198. Region string `xml:"Region"`
  199. } `xml:"Input"`
  200. JobId string `xml:"JobId"`
  201. Message string `xml:"Message"`
  202. Operation struct {
  203. MediaInfo struct {
  204. Format struct {
  205. Text string `xml:",chardata"`
  206. Bitrate string `xml:"Bitrate"`
  207. Duration string `xml:"Duration"`
  208. FormatLongName string `xml:"FormatLongName"`
  209. FormatName string `xml:"FormatName"`
  210. NumProgram string `xml:"NumProgram"`
  211. NumStream string `xml:"NumStream"`
  212. Size string `xml:"Size"`
  213. StartTime string `xml:"StartTime"`
  214. } `xml:"Format"`
  215. Stream struct {
  216. Audio []struct {
  217. Bitrate string `xml:"Bitrate"`
  218. Channel string `xml:"Channel"`
  219. ChannelLayout string `xml:"ChannelLayout"`
  220. CodecLongName string `xml:"CodecLongName"`
  221. CodecName string `xml:"CodecName"`
  222. CodecTag string `xml:"CodecTag"`
  223. CodecTagString string `xml:"CodecTagString"`
  224. CodecTimeBase string `xml:"CodecTimeBase"`
  225. Duration string `xml:"Duration"`
  226. Index string `xml:"Index"`
  227. Language string `xml:"Language"`
  228. SampleFmt string `xml:"SampleFmt"`
  229. SampleRate string `xml:"SampleRate"`
  230. StartTime string `xml:"StartTime"`
  231. Timebase string `xml:"Timebase"`
  232. } `xml:"Audio"`
  233. Subtitle string `xml:"Subtitle"`
  234. Video []struct {
  235. AvgFps string `xml:"AvgFps"`
  236. Bitrate string `xml:"Bitrate"`
  237. CodecLongName string `xml:"CodecLongName"`
  238. CodecName string `xml:"CodecName"`
  239. CodecTag string `xml:"CodecTag"`
  240. CodecTagString string `xml:"CodecTagString"`
  241. CodecTimeBase string `xml:"CodecTimeBase"`
  242. Dar string `xml:"Dar"`
  243. Duration string `xml:"Duration"`
  244. Fps string `xml:"Fps"`
  245. HasBFrame string `xml:"HasBFrame"`
  246. Height string `xml:"Height"`
  247. Index string `xml:"Index"`
  248. Language string `xml:"Language"`
  249. Level string `xml:"Level"`
  250. NumFrames string `xml:"NumFrames"`
  251. PixFormat string `xml:"PixFormat"`
  252. Profile string `xml:"Profile"`
  253. RefFrames string `xml:"RefFrames"`
  254. Rotation string `xml:"Rotation"`
  255. Sar string `xml:"Sar"`
  256. StartTime string `xml:"StartTime"`
  257. Timebase string `xml:"Timebase"`
  258. Width string `xml:"Width"`
  259. } `xml:"Video"`
  260. } `xml:"Stream"`
  261. } `xml:"MediaInfo"`
  262. MediaResult struct {
  263. OutputFile struct {
  264. Bucket string `xml:"Bucket"`
  265. ObjectName []string `xml:"ObjectName"`
  266. ObjectPrefix string `xml:"ObjectPrefix"`
  267. Region string `xml:"Region"`
  268. } `xml:"OutputFile"`
  269. } `xml:"MediaResult"`
  270. Output struct {
  271. Bucket string `xml:"Bucket"`
  272. Object string `xml:"Object"`
  273. Region string `xml:"Region"`
  274. } `xml:"Output"`
  275. TemplateId string `xml:"TemplateId"`
  276. TemplateName string `xml:"TemplateName"`
  277. } `xml:"Operation"`
  278. QueueId string `xml:"QueueId"`
  279. StartTime string `xml:"StartTime"`
  280. State string `xml:"State"`
  281. Tag string `xml:"Tag"`
  282. } `xml:"JobsDetail"`
  283. }
  284. type WorkflowExecutionNotifyBody struct {
  285. XMLName xml.Name `xml:"Response"`
  286. EventName string `xml:"EventName"`
  287. WorkflowExecution struct {
  288. RunId string `xml:"RunId"`
  289. BucketId string `xml:"BucketId"`
  290. Object string `xml:"Object"`
  291. CosHeaders []struct {
  292. Key string `xml:"Key"`
  293. Value string `xml:"Value"`
  294. } `xml:"CosHeaders"`
  295. WorkflowId string `xml:"WorkflowId"`
  296. WorkflowName string `xml:"WorkflowName"`
  297. CreateTime string `xml:"CreateTime"`
  298. State string `xml:"State"`
  299. Tasks []struct {
  300. Type string `xml:"Type"`
  301. CreateTime string `xml:"CreateTime"`
  302. EndTime string `xml:"EndTime"`
  303. State string `xml:"State"`
  304. JobId string `xml:"JobId"`
  305. Name string `xml:"Name"`
  306. TemplateId string `xml:"TemplateId"`
  307. TemplateName string `xml:"TemplateName"`
  308. TranscodeTemplateId string `xml:"TranscodeTemplateId,omitempty"`
  309. TranscodeTemplateName string `xml:"TranscodeTemplateName,omitempty"`
  310. HdrMode string `xml:"HdrMode,omitempty"`
  311. } `xml:"Tasks"`
  312. } `xml:"WorkflowExecution"`
  313. }
  314. func (s *CIService) CreateMultiMediaJobs(ctx context.Context, opt *CreateMultiMediaJobsOptions) (*CreateMultiMediaJobsResult, *Response, error) {
  315. var res CreateMultiMediaJobsResult
  316. sendOpt := sendOptions{
  317. baseURL: s.client.BaseURL.CIURL,
  318. uri: "/jobs",
  319. method: http.MethodPost,
  320. body: opt,
  321. result: &res,
  322. }
  323. resp, err := s.client.send(ctx, &sendOpt)
  324. return &res, resp, err
  325. }
  326. func (s *CIService) CreateMediaJobs(ctx context.Context, opt *CreateMediaJobsOptions) (*CreateMediaJobsResult, *Response, error) {
  327. var res CreateMediaJobsResult
  328. sendOpt := sendOptions{
  329. baseURL: s.client.BaseURL.CIURL,
  330. uri: "/jobs",
  331. method: http.MethodPost,
  332. body: opt,
  333. result: &res,
  334. }
  335. resp, err := s.client.send(ctx, &sendOpt)
  336. return &res, resp, err
  337. }
  338. type DescribeMediaProcessJobResult struct {
  339. XMLName xml.Name `xml:"Response"`
  340. JobsDetail *MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
  341. NonExistJobIds string `xml:"NonExistJobIds,omitempty"`
  342. }
  343. func (s *CIService) DescribeMediaJob(ctx context.Context, jobid string) (*DescribeMediaProcessJobResult, *Response, error) {
  344. var res DescribeMediaProcessJobResult
  345. sendOpt := sendOptions{
  346. baseURL: s.client.BaseURL.CIURL,
  347. uri: "/jobs/" + jobid,
  348. method: http.MethodGet,
  349. result: &res,
  350. }
  351. resp, err := s.client.send(ctx, &sendOpt)
  352. return &res, resp, err
  353. }
  354. type DescribeMediaJobsOptions struct {
  355. QueueId string `url:"queueId,omitempty"`
  356. Tag string `url:"tag,omitempty"`
  357. OrderByTime string `url:"orderByTime,omitempty"`
  358. NextToken string `url:"nextToken,omitempty"`
  359. Size int `url:"size,omitempty"`
  360. States string `url:"states,omitempty"`
  361. StartCreationTime string `url:"startCreationTime,omitempty"`
  362. EndCreationTime string `url:"endCreationTime,omitempty"`
  363. }
  364. type DescribeMediaJobsResult struct {
  365. XMLName xml.Name `xml:"Response"`
  366. JobsDetail []MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
  367. NextToken string `xml:"NextToken,omitempty"`
  368. }
  369. func (s *CIService) DescribeMediaJobs(ctx context.Context, opt *DescribeMediaJobsOptions) (*DescribeMediaJobsResult, *Response, error) {
  370. var res DescribeMediaJobsResult
  371. sendOpt := sendOptions{
  372. baseURL: s.client.BaseURL.CIURL,
  373. uri: "/jobs",
  374. optQuery: opt,
  375. method: http.MethodGet,
  376. result: &res,
  377. }
  378. resp, err := s.client.send(ctx, &sendOpt)
  379. return &res, resp, err
  380. }
  381. type DescribeMediaProcessQueuesOptions struct {
  382. QueueIds string `url:"queueIds,omitempty"`
  383. State string `url:"state,omitempty"`
  384. PageNumber int `url:"pageNumber,omitempty"`
  385. PageSize int `url:"pageSize,omitempty"`
  386. }
  387. type DescribeMediaProcessQueuesResult struct {
  388. XMLName xml.Name `xml:"Response"`
  389. RequestId string `xml:"RequestId,omitempty"`
  390. TotalCount int `xml:"TotalCount,omitempty"`
  391. PageNumber int `xml:"PageNumber,omitempty"`
  392. PageSize int `xml:"PageSize,omitempty"`
  393. QueueList []MediaProcessQueue `xml:"QueueList,omitempty"`
  394. NonExistPIDs []string `xml:"NonExistPIDs,omitempty"`
  395. }
  396. type MediaProcessQueue struct {
  397. QueueId string `xml:"QueueId,omitempty"`
  398. Name string `xml:"Name,omitempty"`
  399. State string `xml:"State,omitempty"`
  400. MaxSize int `xml:"MaxSize,omitempty"`
  401. MaxConcurrent int `xml:"MaxConcurrent,omitempty"`
  402. UpdateTime string `xml:"UpdateTime,omitempty"`
  403. CreateTime string `xml:"CreateTime,omitempty"`
  404. NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
  405. }
  406. type MediaProcessQueueNotifyConfig struct {
  407. Url string `xml:"Url,omitempty"`
  408. State string `xml:"State,omitempty"`
  409. Type string `xml:"Type,omitempty"`
  410. Event string `xml:"Event,omitempty"`
  411. }
  412. func (s *CIService) DescribeMediaProcessQueues(ctx context.Context, opt *DescribeMediaProcessQueuesOptions) (*DescribeMediaProcessQueuesResult, *Response, error) {
  413. var res DescribeMediaProcessQueuesResult
  414. sendOpt := sendOptions{
  415. baseURL: s.client.BaseURL.CIURL,
  416. uri: "/queue",
  417. optQuery: opt,
  418. method: http.MethodGet,
  419. result: &res,
  420. }
  421. resp, err := s.client.send(ctx, &sendOpt)
  422. return &res, resp, err
  423. }
  424. type UpdateMediaProcessQueueOptions struct {
  425. XMLName xml.Name `xml:"Request"`
  426. Name string `xml:"Name,omitempty"`
  427. QueueID string `xml:"QueueID,omitempty"`
  428. State string `xml:"State,omitempty"`
  429. NotifyConfig *MediaProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
  430. }
  431. type UpdateMediaProcessQueueResult struct {
  432. XMLName xml.Name `xml:"Response"`
  433. RequestId string `xml:"RequestId"`
  434. Queue *MediaProcessQueue `xml:"Queue"`
  435. }
  436. func (s *CIService) UpdateMediaProcessQueue(ctx context.Context, opt *UpdateMediaProcessQueueOptions) (*UpdateMediaProcessQueueResult, *Response, error) {
  437. var res UpdateMediaProcessQueueResult
  438. sendOpt := sendOptions{
  439. baseURL: s.client.BaseURL.CIURL,
  440. uri: "/queue/" + opt.QueueID,
  441. body: opt,
  442. method: http.MethodPut,
  443. result: &res,
  444. }
  445. resp, err := s.client.send(ctx, &sendOpt)
  446. return &res, resp, err
  447. }
  448. type DescribeMediaProcessBucketsOptions struct {
  449. Regions string `url:"regions,omitempty"`
  450. BucketNames string `url:"bucketNames,omitempty"`
  451. BucketName string `url:"bucketName,omitempty"`
  452. PageNumber int `url:"pageNumber,omitempty"`
  453. PageSize int `url:"pageSize,omitempty"`
  454. }
  455. type DescribeMediaProcessBucketsResult struct {
  456. XMLName xml.Name `xml:"Response"`
  457. RequestId string `xml:"RequestId,omitempty"`
  458. TotalCount int `xml:"TotalCount,omitempty"`
  459. PageNumber int `xml:"PageNumber,omitempty"`
  460. PageSize int `xml:"PageSize,omitempty"`
  461. MediaBucketList []MediaProcessBucket `xml:"MediaBucketList,omitempty"`
  462. }
  463. type MediaProcessBucket struct {
  464. BucketId string `xml:"BucketId,omitempty"`
  465. Region string `xml:"Region,omitempty"`
  466. CreateTime string `xml:"CreateTime,omitempty"`
  467. }
  468. // 媒体bucket接口 https://cloud.tencent.com/document/product/436/48988
  469. func (s *CIService) DescribeMediaProcessBuckets(ctx context.Context, opt *DescribeMediaProcessBucketsOptions) (*DescribeMediaProcessBucketsResult, *Response, error) {
  470. var res DescribeMediaProcessBucketsResult
  471. sendOpt := sendOptions{
  472. baseURL: s.client.BaseURL.CIURL,
  473. uri: "/mediabucket",
  474. optQuery: opt,
  475. method: http.MethodGet,
  476. result: &res,
  477. }
  478. resp, err := s.client.send(ctx, &sendOpt)
  479. return &res, resp, err
  480. }
  481. type GetMediaInfoResult struct {
  482. XMLName xml.Name `xml:"Response"`
  483. MediaInfo struct {
  484. Format struct {
  485. Bitrate float32 `xml:"Bitrate"`
  486. Duration float32 `xml:"Duration"`
  487. FormatLongName string `xml:"FormatLongName"`
  488. FormatName string `xml:"FormatName"`
  489. NumProgram int `xml:"NumProgram"`
  490. NumStream int `xml:"NumStream"`
  491. Size int `xml:"Size"`
  492. StartTime float32 `xml:"StartTime"`
  493. } `xml:"Format"`
  494. Stream struct {
  495. Audio []struct {
  496. Index int `xml:"Index"`
  497. CodecName string `xml:"CodecName"`
  498. CodecLongName string `xml:"CodecLongName"`
  499. CodecTimeBase string `xml:"CodecTimeBase"`
  500. CodecTagString string `xml:"CodecTagString"`
  501. CodecTag string `xml:"CodecTag"`
  502. SampleFmt string `xml:"SampleFmt"`
  503. SampleRate int `xml:"SampleRate"`
  504. Channel int `xml:"Channel"`
  505. ChannelLayout string `xml:"ChannelLayout"`
  506. Timebase string `xml:"Timebase"`
  507. StartTime float32 `xml:"StartTime"`
  508. Duration float32 `xml:"Duration"`
  509. Bitrate float32 `xml:"Bitrate"`
  510. Language string `xml:"Language"`
  511. } `xml:"Audio"`
  512. Subtitle struct {
  513. Index int `xml:"Index"`
  514. Language string `xml:"Language"`
  515. } `xml:"Subtitle"`
  516. Video struct {
  517. Index int `xml:"Index"`
  518. CodecName string `xml:"CodecName"`
  519. CodecLongName string `xml:"CodecLongName"`
  520. CodecTimeBase string `xml:"CodecTimeBase"`
  521. CodecTagString string `xml:"CodecTagString"`
  522. CodecTag string `xml:"CodecTag"`
  523. Profile string `xml:"Profile"`
  524. Height int `xml:"Height"`
  525. Width int `xml:"Width"`
  526. HasBFrame int `xml:"HasBFrame"`
  527. RefFrames int `xml:"RefFrames"`
  528. Sar string `xml:"Sar"`
  529. Dar string `xml:"Dar"`
  530. PixFormat string `xml:"PixFormat"`
  531. FieldOrder string `xml:"FieldOrder"`
  532. Level int `xml:"Level"`
  533. Fps float32 `xml:"Fps"`
  534. AvgFps string `xml:"AvgFps"`
  535. Timebase string `xml:"Timebase"`
  536. StartTime float32 `xml:"StartTime"`
  537. Duration float32 `xml:"Duration"`
  538. Bitrate float32 `xml:"Bitrate"`
  539. NumFrames int `xml:"NumFrames"`
  540. Language string `xml:"Language"`
  541. } `xml:"Video"`
  542. } `xml:"Stream"`
  543. } `xml:"MediaInfo"`
  544. }
  545. // 媒体信息接口 https://cloud.tencent.com/document/product/436/55672
  546. func (s *CIService) GetMediaInfo(ctx context.Context, name string, opt *ObjectGetOptions, id ...string) (*GetMediaInfoResult, *Response, error) {
  547. var u string
  548. if len(id) == 1 {
  549. u = fmt.Sprintf("/%s?versionId=%s&ci-process=videoinfo", encodeURIComponent(name), id[0])
  550. } else if len(id) == 0 {
  551. u = fmt.Sprintf("/%s?ci-process=videoinfo", encodeURIComponent(name))
  552. } else {
  553. return nil, nil, fmt.Errorf("wrong params")
  554. }
  555. var res GetMediaInfoResult
  556. sendOpt := sendOptions{
  557. baseURL: s.client.BaseURL.BucketURL,
  558. uri: u,
  559. method: http.MethodGet,
  560. optQuery: opt,
  561. optHeader: opt,
  562. result: &res,
  563. }
  564. resp, err := s.client.send(ctx, &sendOpt)
  565. return &res, resp, err
  566. }
  567. type GetSnapshotOptions struct {
  568. Time float32 `url:"time,omitempty"`
  569. Height int `url:"height,omitempty"`
  570. Width int `url:"width,omitempty"`
  571. Format string `url:"format,omitempty"`
  572. Rotate string `url:"rotate,omitempty"`
  573. Mode string `url:"mode,omitempty"`
  574. }
  575. // 媒体截图接口 https://cloud.tencent.com/document/product/436/55671
  576. func (s *CIService) GetSnapshot(ctx context.Context, name string, opt *GetSnapshotOptions, id ...string) (*Response, error) {
  577. var u string
  578. if len(id) == 1 {
  579. u = fmt.Sprintf("/%s?versionId=%s&ci-process=snapshot", encodeURIComponent(name), id[0])
  580. } else if len(id) == 0 {
  581. u = fmt.Sprintf("/%s?ci-process=snapshot", encodeURIComponent(name))
  582. } else {
  583. return nil, fmt.Errorf("wrong params")
  584. }
  585. sendOpt := sendOptions{
  586. baseURL: s.client.BaseURL.BucketURL,
  587. uri: u,
  588. method: http.MethodGet,
  589. optQuery: opt,
  590. disableCloseBody: true,
  591. }
  592. resp, err := s.client.send(ctx, &sendOpt)
  593. return resp, err
  594. }