package helper import ( "encoding/base64" "fmt" "strings" "github.com/anxpp/beego/logs" "github.com/qiniu/go-sdk/v7/auth" "github.com/qiniu/go-sdk/v7/storage" "github.com/spf13/viper" ) //{"id":"z0.0A2234420A3600F3365DD1FA282B440D","pipeline":"1381904061.XZVideoToImagesQueue","code":0, // "desc":"The fop was completed successfully","reqid":"Ry0AAMB45er_HtgV","inputBucket":"media","inputKey":"shot/xingzuan_appstore_video.mp4_000001.jpg", // "items":[{"cmd":"animate/duration/5/merge/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDAyLmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDAzLmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDA0LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDA1LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDA2LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDA3LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDA4LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDA5LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDEwLmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDExLmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDEyLmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDEzLmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDE0LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDE1LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDE2LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDE3LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDE4LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDE5LmpwZw==/key/c2hvdC94aW5nenVhbl9hcHBzdG9yZV92aWRlby5tcDRfMDAwMDIwLmpwZw==/effect/0", // "code":0,"desc":"The fop was completed successfully","hash":"lmW7N4-x40al165ufZj2SJGbut6L","key":"-KqubldLD_opMcwnpcOJ2FOml7M=/Ftq7oAVtIsQ-hOdz1amflU4f0mxO","returnOld":0}]} type QiNiuVideoToImagesParam struct { Id string `json:"id"` Pipeline string `json:"pipeline"` Code int `json:"code"` Desc string `json:"desc"` Reqid string `json:"reqid"` InputBucket string `json:"inputBucket"` InputKey string `json:"inputKey"` Items []QiNiuVideoToImagesParamItem `json:"items"` } type QiNiuVideoToImagesParamItem struct { Cmd string `json:"cmd"` Code int `json:"code"` Desc string `json:"desc"` Keys []string `json:"keys"` Key string `json:"key"` Hash string `json:"hash"` ReturnOld int `json:"returnOld"` } // 获取视频抽帧的token // 第2秒开始,每秒10张,抽20张 func QiNiuVideoToImages(key string) (persistentId string) { mac := auth.New(viper.GetString("qiniu.key"), viper.GetString("qiniu.secret")) cfg := storage.Config{UseHTTPS: true} operationManager := storage.NewOperationManager(mac, &cfg) saveBucket := "dddjmedia" // 处理指令集合 // vsample//ss//t//s//rotate//interval//pattern/ // /ss/ 是 指定截取视频的开始时刻,单位:秒,精度为 100ms。例如 /ss/1.1 // /t/ 是 采样总时长,单位:秒,精度为 100ms。例如 t/1.1 // /s/ 缩略图分辨率,单位:像素(px),格式:x,宽度取值范围为1-1920,高度取值范围为1-1080。 默认为原始视频分辨率。 // /rotate/ 指定顺时针旋转的度数,可取值为90、180、270、auto。 默认为不旋转。 // /interval/ 指定采样间隔,单元:秒。 默认为5秒,精度为 100ms,例如/interval/0.1 // /pattern/ 是 指定各张截图的资源名格式,支持如下魔法变量: $(count) :六个占位符的数字串,不足位的填充前导零即%06d,如 000001 fopVSample := fmt.Sprintf("vsample/png/ss/2/t/2/interval/0.1/pattern/%s", base64.URLEncoding.EncodeToString([]byte("shot/"+key+"_$(count).jpg"))) fopBatch := []string{fopVSample} fops := strings.Join(fopBatch, ";") persistentId, err := operationManager.Pfop(saveBucket, key, fops, "FYVideoToImagesQueue", viper.GetString("open.notify.qiniuVideoShot"), true) if err != nil { logs.Error(err.Error(), " ", persistentId, "", key) } return persistentId } func QiNiuImagesToGif(keys []string) (persistentId string) { mac := auth.New(viper.GetString("qiniu.key"), viper.GetString("qiniu.secret")) cfg := storage.Config{UseHTTPS: true} operationManager := storage.NewOperationManager(mac, &cfg) saveBucket := "dddjmedia" an := "animate/duration/5/merge" for i := 1; i < len(keys); i++ { an += "/key/" + base64.URLEncoding.EncodeToString([]byte(keys[i])) } an += "/effect/0" logs.Info("result of img merge", an) fopBatch := []string{an} fops := strings.Join(fopBatch, ";") persistentId, err := operationManager.Pfop(saveBucket, keys[0], fops, "FYVideoToImagesQueue", viper.GetString("open.notify.qiniuImgMergeShot"), true) if err != nil { fmt.Println(err) logs.Error(err.Error()) } return persistentId }