全部产品
云市场

视频AI

更新时间:2019-01-24 15:40:00

初始化客户端

使用前请先初始化客户端,参考 InitVodClient 接口。

提交AI作业

接口参数和返回字段请参考 SubmitAIJob

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MySubmitAIJob(client *vod.Client) (response *vod.SubmitAIJobResponse, err error) {
  9. request := vod.CreateSubmitAIJobRequest()
  10. // 视频ID
  11. request.MediaId = "<VideoId>"
  12. // AI类型,多个用逗号分隔;请确保已开通该类型AI服务
  13. request.Types = "AIVideoCover,AIVideoCensor"
  14. request.AcceptFormat = "JSON"
  15. return client.SubmitAIJob(request)
  16. }
  17. func main() {
  18. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  19. if err != nil {
  20. panic(err)
  21. }
  22. response, err := MySubmitAIJob(client)
  23. if err != nil {
  24. panic(err)
  25. }
  26. fmt.Println(response.GetHttpContentString())
  27. fmt.Println(response.RequestId)
  28. for _, job := range response.AIJobList.AIJob {
  29. fmt.Printf("%s: %s\n", job.Type, job.JobId)
  30. }
  31. }

查询AI作业

接口参数和返回字段请参考 ListAIJob

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyListAIJob(client *vod.Client) (response *vod.ListAIJobResponse, err error) {
  9. request := vod.CreateListAIJobRequest()
  10. // 视频AI作业ID,多个用逗号分隔
  11. request.JobIds = "JobId1,JobId2"
  12. request.AcceptFormat = "JSON"
  13. return client.ListAIJob(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MyListAIJob(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. for _, job := range response.AIJobList.AIJob {
  27. fmt.Printf("%s: %s %s\n", job.JobId, job.Status, job.Data)
  28. }
  29. }

添加AI模板

接口参数和返回字段请参考 AddAITemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. "encoding/json"
  8. )
  9. func MyAddAITemplate(client *vod.Client) (response *vod.AddAITemplateResponse, err error) {
  10. request := vod.CreateAddAITemplateRequest()
  11. // 设置模板类型,以智能审核模板为例
  12. request.TemplateType = "AIMediaAudit"
  13. // 设置模板名称
  14. request.TemplateName = "My AI Template"
  15. // 设置模板详细配置
  16. auditItem := []string{"terrorism", "porn"}
  17. auditRange := []string{"video", "image-cover", "text-title"}
  18. auditContent := []string{"screen"}
  19. templateConfig := map[string]interface{}{"AuditItem": auditItem, "AuditRange": auditRange,
  20. "AuditContent": auditContent, "AuditAutoBlock": "no"}
  21. jsonConfig, err := json.Marshal(templateConfig)
  22. if err != nil {
  23. fmt.Println("json.Marshal failed:", err)
  24. return
  25. }
  26. request.TemplateConfig = string(jsonConfig)
  27. request.AcceptFormat = "JSON"
  28. return client.AddAITemplate(request)
  29. }
  30. func main() {
  31. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  32. if err != nil {
  33. panic(err)
  34. }
  35. response, err := MyAddAITemplate(client)
  36. if err != nil {
  37. panic(err)
  38. }
  39. fmt.Println(response.GetHttpContentString())
  40. fmt.Println(response.TemplateId)
  41. }

删除AI模板

接口参数和返回字段请参考 DeleteAITemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyDeleteAITemplate(client *vod.Client) (response *vod.DeleteAITemplateResponse, err error) {
  9. request := vod.CreateDeleteAITemplateRequest()
  10. request.TemplateId = "<TemplateId>"
  11. request.AcceptFormat = "JSON"
  12. return client.DeleteAITemplate(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyDeleteAITemplate(client)
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. fmt.Println(response.RequestId)
  25. }

修改AI模板

接口参数和返回字段请参考 UpdateAITemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. "encoding/json"
  8. )
  9. func MyUpdateAITemplate(client *vod.Client) (response *vod.UpdateAITemplateResponse, err error) {
  10. request := vod.CreateUpdateAITemplateRequest()
  11. // 设置模板ID
  12. request.TemplateId = "2a0aadb19e187a58f296e2aeb2ad503e"
  13. // 设置模板名称
  14. request.TemplateName = "New AI Template Name"
  15. // 设置模板详细配置
  16. auditItem := []string{"terrorism", "porn"}
  17. auditRange := []string{"video", "image-cover"}
  18. auditContent := []string{"screen"}
  19. templateConfig := map[string]interface{}{"AuditItem": auditItem, "AuditRange": auditRange,
  20. "AuditContent": auditContent, "AuditAutoBlock": "yes"}
  21. jsonConfig, err := json.Marshal(templateConfig)
  22. if err != nil {
  23. fmt.Println("json.Marshal failed:", err)
  24. return
  25. }
  26. request.TemplateConfig = string(jsonConfig)
  27. request.AcceptFormat = "JSON"
  28. return client.UpdateAITemplate(request)
  29. }
  30. func main() {
  31. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  32. if err != nil {
  33. panic(err)
  34. }
  35. response, err := MyUpdateAITemplate(client)
  36. if err != nil {
  37. panic(err)
  38. }
  39. fmt.Println(response.GetHttpContentString())
  40. fmt.Println(response.RequestId)
  41. }

查询AI模板

接口参数和返回字段请参考 GetAITemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetAITemplate(client *vod.Client) (response *vod.GetAITemplateResponse, err error) {
  9. request := vod.CreateGetAITemplateRequest()
  10. request.TemplateId = "<TemplateId>"
  11. request.AcceptFormat = "JSON"
  12. return client.GetAITemplate(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyGetAITemplate(client)
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. fmt.Println(response.TemplateInfo)
  25. }

查询AI模板列表

接口参数和返回字段请参考 ListAITemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyListAITemplate(client *vod.Client) (response *vod.ListAITemplateResponse, err error) {
  9. request := vod.CreateListAITemplateRequest()
  10. request.TemplateType = "AIMediaAudit"
  11. request.AcceptFormat = "JSON"
  12. return client.ListAITemplate(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyListAITemplate(client)
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. fmt.Println(response.TemplateInfoList)
  25. }

设置默认AI模板

接口参数和返回字段请参考 SetDefaultAITemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MySetDefaultAITemplate(client *vod.Client) (response *vod.SetDefaultAITemplateResponse, err error) {
  9. request := vod.CreateSetDefaultAITemplateRequest()
  10. request.TemplateId = "<TemplateId>"
  11. request.AcceptFormat = "JSON"
  12. return client.SetDefaultAITemplate(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MySetDefaultAITemplate(client)
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. fmt.Println(response.RequestId)
  25. }

查询默认AI模板

接口参数和返回字段请参考 GetDefaultAITemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetDefaultAITemplate(client *vod.Client) (response *vod.GetDefaultAITemplateResponse, err error) {
  9. request := vod.CreateGetDefaultAITemplateRequest()
  10. request.TemplateType = "AIMediaAudit"
  11. request.AcceptFormat = "JSON"
  12. return client.GetDefaultAITemplate(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyGetDefaultAITemplate(client)
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. fmt.Println(response.TemplateInfo)
  25. }