Skip to content

Commit 8bee89d

Browse files
committed
Merge branch 'livetranscode' into 'master' (merge request !94)
livetranscode
2 parents 151f6e5 + 8e69739 commit 8bee89d

File tree

5 files changed

+584
-40
lines changed

5 files changed

+584
-40
lines changed

ci_media.go

Lines changed: 190 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cos
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
67
"encoding/xml"
@@ -9,11 +10,17 @@ import (
910
"net/http"
1011
"sort"
1112
"strings"
13+
"time"
1214

1315
"github.com/clbanning/mxj"
1416
"github.com/mitchellh/mapstructure"
1517
)
1618

19+
type VodInfo struct {
20+
FileId string `xml:"FileId,omitempty"`
21+
SubAppId string `xml:"SubAppId,omitempty"`
22+
}
23+
1724
// JobInput TODO
1825
type JobInput struct {
1926
Object string `xml:"Object,omitempty"`
@@ -24,7 +31,8 @@ type JobInput struct {
2431
Key string `xml:"Key"`
2532
Value string `xml:"Value"`
2633
} `xml:"CosHeaders"`
27-
Url string `xml:"Url,omitempty"`
34+
Url string `xml:"Url,omitempty"`
35+
Vod *VodInfo `xml:"Vod,omitempty"`
2836
}
2937

3038
// StreamExtract TODO
@@ -1473,6 +1481,10 @@ func (s *CIService) CreatePlayKey(ctx context.Context) (*PlayKeyResult, *Respons
14731481
return &res, resp, err
14741482
}
14751483

1484+
func (s *CIService) CreateMediaPlayKey(ctx context.Context) (*PlayKeyResult, *Response, error) {
1485+
return s.CreatePlayKey(ctx)
1486+
}
1487+
14761488
func (s *CIService) GetPlayKey(ctx context.Context) (*PlayKeyResult, *Response, error) {
14771489
var res PlayKeyResult
14781490
sendOpt := sendOptions{
@@ -1485,6 +1497,36 @@ func (s *CIService) GetPlayKey(ctx context.Context) (*PlayKeyResult, *Response,
14851497
return &res, resp, err
14861498
}
14871499

1500+
func (s *CIService) DescribeMediaPlayKey(ctx context.Context) (*PlayKeyResult, *Response, error) {
1501+
var res PlayKeyResult
1502+
sendOpt := sendOptions{
1503+
baseURL: s.client.BaseURL.CIURL,
1504+
uri: "/playKey",
1505+
method: http.MethodGet,
1506+
result: &res,
1507+
}
1508+
resp, err := s.client.send(ctx, &sendOpt)
1509+
return &res, resp, err
1510+
}
1511+
1512+
type UpdateMediaPlayKeyOptions struct {
1513+
MasterPlayKey string `url:"masterPlayKey,omitempty"`
1514+
BackupPlayKey string `url:"backupPlayKey,omitempty"`
1515+
}
1516+
1517+
func (s *CIService) UpdateMediaPlayKey(ctx context.Context, opt *UpdateMediaPlayKeyOptions) (*PlayKeyResult, *Response, error) {
1518+
var res PlayKeyResult
1519+
sendOpt := sendOptions{
1520+
baseURL: s.client.BaseURL.CIURL,
1521+
uri: "/playKey",
1522+
method: http.MethodPut,
1523+
optQuery: opt,
1524+
result: &res,
1525+
}
1526+
resp, err := s.client.send(ctx, &sendOpt)
1527+
return &res, resp, err
1528+
}
1529+
14881530
// GenerateMediaInfoOptions TODO
14891531
type GenerateMediaInfoOptions struct {
14901532
XMLName xml.Name `xml:"Request"`
@@ -1506,6 +1548,80 @@ func (s *CIService) GenerateMediaInfo(ctx context.Context, opt *GenerateMediaInf
15061548
return &res, resp, err
15071549
}
15081550

1551+
// GenerateMediaInfoOptions TODO
1552+
type GenerateAVInfoOptions struct {
1553+
XMLName xml.Name `xml:"Request"`
1554+
Input *JobInput `xml:"Input,omitempty"`
1555+
OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"`
1556+
}
1557+
type GetAVInfoResult struct {
1558+
Format struct {
1559+
BitRate string `json:"bit_rate"`
1560+
Duration string `json:"duration"`
1561+
FormatLongName string `json:"format_long_name"`
1562+
FormatName string `json:"format_name"`
1563+
NbPrograms int `json:"nb_programs"`
1564+
NbStreams int `json:"nb_streams"`
1565+
Size string `json:"size"`
1566+
StartTime string `json:"start_time"`
1567+
} `json:"format"`
1568+
Streams []struct {
1569+
AvgFrameRate string `json:"avg_frame_rate,omitempty"`
1570+
BitRate string `json:"bit_rate"`
1571+
CodecLongName string `json:"codec_long_name"`
1572+
CodecName string `json:"codec_name"`
1573+
CodecTag string `json:"codec_tag"`
1574+
CodecTagString string `json:"codec_tag_string"`
1575+
CodecTimeBase string `json:"codec_time_base"`
1576+
CodecType string `json:"codec_type"`
1577+
ColorPrimaries string `json:"color_primaries,omitempty"`
1578+
ColorRange string `json:"color_range,omitempty"`
1579+
ColorTransfer string `json:"color_transfer,omitempty"`
1580+
CreationTime time.Time `json:"creation_time"`
1581+
DisplayAspectRatio string `json:"display_aspect_ratio,omitempty"`
1582+
Duration string `json:"duration"`
1583+
FiledOrder string `json:"filed_order,omitempty"`
1584+
HasBFrames string `json:"has_b_frames,omitempty"`
1585+
Height int `json:"height,omitempty"`
1586+
Index int `json:"index"`
1587+
Language string `json:"language"`
1588+
Level int `json:"level,omitempty"`
1589+
NbFrames string `json:"nb_frames,omitempty"`
1590+
PixFmt string `json:"pix_fmt,omitempty"`
1591+
Profile string `json:"profile,omitempty"`
1592+
RFrameRate string `json:"r_frame_rate,omitempty"`
1593+
Refs int `json:"refs,omitempty"`
1594+
Rotation string `json:"rotation,omitempty"`
1595+
SampleAspectRatio string `json:"sample_aspect_ratio,omitempty"`
1596+
StartTime string `json:"start_time"`
1597+
Timebase string `json:"timebase"`
1598+
Width int `json:"width,omitempty"`
1599+
ChannelLayout string `json:"channel_layout,omitempty"`
1600+
Channels int `json:"channels,omitempty"`
1601+
SampleFmt string `json:"sample_fmt,omitempty"`
1602+
SampleRate string `json:"sample_rate,omitempty"`
1603+
} `json:"streams"`
1604+
}
1605+
1606+
// GenerateMediaInfo TODO
1607+
// 生成媒体信息接口,支持大文件,耗时较大请求
1608+
func (s *CIService) GenerateAVInfo(ctx context.Context, opt *GenerateAVInfoOptions) (*GetAVInfoResult, *Response, error) {
1609+
var buf bytes.Buffer
1610+
var res GetAVInfoResult
1611+
sendOpt := sendOptions{
1612+
baseURL: s.client.BaseURL.CIURL,
1613+
uri: "/avinfo",
1614+
method: http.MethodPost,
1615+
body: opt,
1616+
result: &buf,
1617+
}
1618+
resp, err := s.client.send(ctx, &sendOpt)
1619+
if buf.Len() > 0 {
1620+
err = json.Unmarshal(buf.Bytes(), &res)
1621+
}
1622+
return &res, resp, err
1623+
}
1624+
15091625
// GetSnapshotOptions TODO
15101626
type GetSnapshotOptions struct {
15111627
Time float32 `url:"time,omitempty"`
@@ -1572,6 +1688,19 @@ func (s *CIService) PostSnapshot(ctx context.Context, opt *PostSnapshotOptions)
15721688
return &res, resp, err
15731689
}
15741690

1691+
// PostCISnapshot
1692+
func (s *CIService) PostCISnapshot(ctx context.Context, opt *PostSnapshotOptions) (*Response, error) {
1693+
sendOpt := sendOptions{
1694+
baseURL: s.client.BaseURL.CIURL,
1695+
uri: "/cisnapshot",
1696+
body: opt,
1697+
method: http.MethodPost,
1698+
disableCloseBody: true,
1699+
}
1700+
resp, err := s.client.send(ctx, &sendOpt)
1701+
return resp, err
1702+
}
1703+
15751704
// GetPrivateM3U8Options TODO
15761705
type GetPrivateM3U8Options struct {
15771706
Expires int `url:"expires"`
@@ -3909,3 +4038,63 @@ type ImageOCRTextWordPolygon struct {
39094038
Y int `xml:"Y,omitempty"`
39104039
} `xml:"RightBottom,omitempty"`
39114040
}
4041+
4042+
type LiveTanscodeVideo struct {
4043+
Codec string `xml:"Codec"`
4044+
Width string `xml:"Width,omitempty"`
4045+
Height string `xml:"Height,omitempty"`
4046+
Fps string `xml:"Fps,omitempty"`
4047+
Bitrate string `xml:"Bitrate,omitempty"`
4048+
Gop string `xml:"Gop,omitempty"`
4049+
Maxrate string `xml:"Maxrate,omitempty"`
4050+
}
4051+
4052+
type LiveTanscodeTransConfig struct {
4053+
InitialClipNum string `xml:"InitialClipNum,omitempty"`
4054+
CosTag string `xml:"CosTag,omitempty"`
4055+
HlsEncrypt *HlsEncrypt `xml:"HlsEncrypt,omitempty"`
4056+
}
4057+
4058+
type LiveTanscode struct {
4059+
Container *Container `xml:"Container,omitempty"`
4060+
Video *LiveTanscodeVideo `xml:"Video,omitempty"`
4061+
// TimeInterval *TimeInterval `xml:"TimeInterval,omitempty"`
4062+
// Audio *Audio `xml:"Audio,omitempty"`
4063+
TransConfig *LiveTanscodeTransConfig `xml:"TransConfig,omitempty"`
4064+
}
4065+
4066+
type GeneratePlayListJobOperation struct {
4067+
Tag string `xml:"Tag,omitempty"`
4068+
Output *JobOutput `xml:"Output,omitempty"`
4069+
MediaResult *MediaResult `xml:"MediaResult,omitempty"`
4070+
MediaInfo *MediaInfo `xml:"MediaInfo,omitempty"`
4071+
Transcode *LiveTanscode `xml:"Transcode,omitempty"`
4072+
UserData string `xml:"UserData,omitempty"`
4073+
JobLevel int `xml:"JobLevel,omitempty"`
4074+
}
4075+
4076+
type CreateGeneratePlayListJobOptions struct {
4077+
XMLName xml.Name `xml:"Request"`
4078+
Tag string `xml:"Tag,omitempty"`
4079+
Input *JobInput `xml:"Input,omitempty"`
4080+
Operation *GeneratePlayListJobOperation `xml:"Operation,omitempty"`
4081+
QueueId string `xml:"QueueId,omitempty"`
4082+
QueueType string `xml:"QueueType,omitempty"`
4083+
CallBackFormat string `xml:"CallBackFormat,omitempty"`
4084+
CallBackType string `xml:"CallBackType,omitempty"`
4085+
CallBack string `xml:"CallBack,omitempty"`
4086+
CallBackMqConfig *NotifyConfigCallBackMqConfig `xml:"CallBackMqConfig,omitempty"`
4087+
}
4088+
4089+
func (s *CIService) CreateGeneratePlayListJob(ctx context.Context, opt *CreateGeneratePlayListJobOptions) (*CreateJobsResult, *Response, error) {
4090+
var res CreateJobsResult
4091+
sendOpt := sendOptions{
4092+
baseURL: s.client.BaseURL.CIURL,
4093+
uri: "/jobs",
4094+
method: http.MethodPost,
4095+
body: opt,
4096+
result: &res,
4097+
}
4098+
resp, err := s.client.send(ctx, &sendOpt)
4099+
return &res, resp, err
4100+
}

0 commit comments

Comments
 (0)