mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-01-07 12:17:02 +08:00
feat: oss video snapshot
This commit is contained in:
parent
89c18ac358
commit
cb929e4c9c
@ -45,6 +45,11 @@ const (
|
|||||||
imageWebp = "webp"
|
imageWebp = "webp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
videoSnapshotImagePng = "png"
|
||||||
|
videoSnapshotImageJpg = "jpg"
|
||||||
|
)
|
||||||
|
|
||||||
func NewOSS() (s3.Interface, error) {
|
func NewOSS() (s3.Interface, error) {
|
||||||
conf := config.Config.Object.Oss
|
conf := config.Config.Object.Oss
|
||||||
if conf.BucketURL == "" {
|
if conf.BucketURL == "" {
|
||||||
@ -271,7 +276,7 @@ func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
var opts []oss.Option
|
var opts []oss.Option
|
||||||
if opt != nil {
|
if opt != nil {
|
||||||
if opt.Image != nil {
|
if opt.Image != nil {
|
||||||
// https://help.aliyun.com/zh/oss/user-guide/resize-images-4?spm=a2c4g.11186623.0.0.4b3b1e4fWW6yji
|
// 文档地址: https://help.aliyun.com/zh/oss/user-guide/resize-images-4?spm=a2c4g.11186623.0.0.4b3b1e4fWW6yji
|
||||||
var format string
|
var format string
|
||||||
switch opt.Image.Format {
|
switch opt.Image.Format {
|
||||||
case
|
case
|
||||||
@ -281,29 +286,54 @@ func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
imageGif,
|
imageGif,
|
||||||
imageWebp:
|
imageWebp:
|
||||||
format = opt.Image.Format
|
format = opt.Image.Format
|
||||||
opt.ContentType = "image/" + format
|
default:
|
||||||
if opt.Filename == "" {
|
opt.Image.Format = imageJpg
|
||||||
opt.Filename = filepath.Base(name) + "." + format
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var wh []string
|
opt.ContentType = "image/" + format
|
||||||
if opt.Image.Width > 0 {
|
if opt.Filename == "" {
|
||||||
wh = append(wh, "w_"+strconv.Itoa(opt.Image.Width))
|
opt.Filename = filepath.Base(name) + "." + opt.Video.ImageFormat
|
||||||
|
} else if filepath.Ext(opt.Filename) != "."+opt.Video.ImageFormat {
|
||||||
|
opt.Filename += "." + opt.Video.ImageFormat
|
||||||
}
|
}
|
||||||
if opt.Image.Height > 0 {
|
// https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,h_100,m_lfit
|
||||||
wh = append(wh, "h_"+strconv.Itoa(opt.Image.Height))
|
process := "image/resize,m_lfit"
|
||||||
|
if opt.Video.Width > 0 {
|
||||||
|
process += ",w_" + strconv.Itoa(opt.Image.Width)
|
||||||
}
|
}
|
||||||
if len(format)+len(wh) > 0 {
|
if opt.Video.Height > 0 {
|
||||||
style := make([]string, 0, 3)
|
process += ",h_" + strconv.Itoa(opt.Image.Height)
|
||||||
style = append(style, "image")
|
|
||||||
if len(wh) > 0 {
|
|
||||||
style = append(style, "resize,m_lfit,"+strings.Join(wh, ","))
|
|
||||||
}
|
|
||||||
if format != "" {
|
|
||||||
style = append(style, "format,"+format)
|
|
||||||
}
|
|
||||||
opts = append(opts, oss.Process(strings.Join(style, "/")))
|
|
||||||
}
|
}
|
||||||
|
process += ",format," + format
|
||||||
|
opts = append(opts, oss.Process(process))
|
||||||
|
}
|
||||||
|
if opt.Video != nil {
|
||||||
|
// 文档地址: https://help.aliyun.com/zh/oss/user-guide/video-snapshots?spm=a2c4g.11186623.0.0.23f743b0BR5WxX
|
||||||
|
// x-oss-process=video/snapshot,t_7000,f_jpg,w_800,h_600,m_fast
|
||||||
|
millisecond := int(opt.Video.Time / time.Millisecond)
|
||||||
|
if millisecond < 0 {
|
||||||
|
millisecond = 0
|
||||||
|
}
|
||||||
|
switch opt.Video.ImageFormat {
|
||||||
|
case videoSnapshotImageJpg, videoSnapshotImagePng:
|
||||||
|
default:
|
||||||
|
opt.Video.ImageFormat = videoSnapshotImageJpg
|
||||||
|
}
|
||||||
|
opt.ContentType = "image/" + opt.Video.ImageFormat
|
||||||
|
if opt.Filename == "" {
|
||||||
|
opt.Filename = filepath.Base(name) + "." + opt.Video.ImageFormat
|
||||||
|
} else if filepath.Ext(opt.Filename) != "."+opt.Video.ImageFormat {
|
||||||
|
opt.Filename += "." + opt.Video.ImageFormat
|
||||||
|
}
|
||||||
|
process := "video/snapshot,t_" + strconv.Itoa(millisecond) + ",f_" + opt.Video.ImageFormat
|
||||||
|
if opt.Video.Width > 0 {
|
||||||
|
process += ",w_" + strconv.Itoa(opt.Video.Width)
|
||||||
|
}
|
||||||
|
if opt.Video.Height > 0 {
|
||||||
|
process += ",h_" + strconv.Itoa(opt.Video.Height)
|
||||||
|
}
|
||||||
|
process += ",m_fast"
|
||||||
|
fmt.Println(process)
|
||||||
|
opts = append(opts, oss.Process(process))
|
||||||
}
|
}
|
||||||
if opt.ContentType != "" {
|
if opt.ContentType != "" {
|
||||||
opts = append(opts, oss.ResponseContentType(opt.ContentType))
|
opts = append(opts, oss.ResponseContentType(opt.ContentType))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user