全部产品
云市场

视频水印

更新时间:2019-01-02 12:45:12

初始化客户端

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

添加水印

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

  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. "encoding/json"
  7. "fmt"
  8. )
  9. func MyAddWatermark(client *vod.Client) (response *vod.AddWatermarkResponse, err error) {
  10. request := vod.CreateAddWatermarkRequest()
  11. request.Name = "watermark-sample"
  12. // 图片水印必须传图片文件的OSS地址,且水印文件需要和视频在同一区域,如:华东2的视频添加水印,水印文件必须存放在华东2
  13. request.FileUrl = "http://sample.oss-cn-shanghai.aliyuncs.com/watermark/test.png"
  14. // 文字水印设置示例
  15. request.Type = "Text"
  16. // 水印的文本内容、字体、大小、颜色、透明度等配置
  17. watermarkConfig := map[string]interface{}{"Content": "watermark Text", "FontName": "SimSun", "FontSize": 25,
  18. "FontColor": "Black", "FontAlpha": 0.2, "BorderColor": "White", "BorderWidth": 1, "Top": 20, "Left": 15}
  19. jsonConfig, err := json.Marshal(watermarkConfig)
  20. if err != nil {
  21. fmt.Println("json.Marshal failed:", err)
  22. return
  23. }
  24. request.WatermarkConfig = string(jsonConfig)
  25. /*
  26. // 图片水印设置示例
  27. request.Type = "Image"
  28. // 水印显示的开始时间和结束时间
  29. timeline := map[string]interface{}{"Start": 2, "Duration": "ToEND"}
  30. // 水印的位置等配置
  31. watermarkConfig := map[string]interface{}{"Dx": 8, "Dy": 8, "Width": 55, "Height": 55, "ReferPos": "BottomRight", "Timeline": timeline}
  32. jsonConfig, err := json.Marshal(watermarkConfig)
  33. if err != nil {
  34. fmt.Println("json.Marshal failed:", err)
  35. return
  36. }
  37. request.WatermarkConfig = string(jsonConfig)
  38. */
  39. request.AcceptFormat = "JSON"
  40. return client.AddWatermark(request)
  41. }
  42. func main() {
  43. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  44. if err != nil {
  45. panic(err)
  46. }
  47. response, err := MyAddWatermark(client)
  48. if err != nil {
  49. panic(err)
  50. }
  51. fmt.Println(response.GetHttpContentString())
  52. fmt.Println(response.RequestId)
  53. fmt.Printf("%s: %s\n", response.WatermarkInfo.WatermarkId, response.WatermarkInfo.WatermarkConfig)
  54. }

修改水印

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

注:本接口不支持图片水印图片文件地址的修改,如要更换请创建新的水印。

  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. "encoding/json"
  7. "fmt"
  8. )
  9. func MyUpdateWatermark(client *vod.Client) (response *vod.UpdateWatermarkResponse, err error) {
  10. request := vod.CreateUpdateWatermarkRequest()
  11. request.WatermarkId = "5a5abf8e458a9d5c97dea86e686cdf18"
  12. request.Name = "new-watermark-name"
  13. // 更改文字水印设置示例
  14. // 水印的文本内容、字体、大小、颜色、透明度等配置
  15. watermarkConfig := map[string]interface{}{"Content": "New watermark Text", "FontName": "SimSun", "FontSize": 25,
  16. "FontColor": "Black", "FontAlpha": 0.2, "BorderColor": "White", "BorderWidth": 1, "Top": 20, "Left": 15}
  17. jsonConfig, err := json.Marshal(watermarkConfig)
  18. if err != nil {
  19. fmt.Println("json.Marshal failed:", err)
  20. return
  21. }
  22. request.WatermarkConfig = string(jsonConfig)
  23. /*
  24. // 更改图片水印设置示例
  25. // 水印显示的开始时间和结束时间
  26. timeline := map[string]interface{}{"Start": 2, "Duration": "ToEND"}
  27. // 水印的位置等配置
  28. watermarkConfig := map[string]interface{}{"Dx": 8, "Dy": 8, "Width": 55, "Height": 55, "ReferPos": "BottomRight",
  29. "Timeline": timeline}
  30. jsonConfig, err := json.Marshal(watermarkConfig)
  31. if err != nil {
  32. fmt.Println("json.Marshal failed:", err)
  33. return
  34. }
  35. request.WatermarkConfig = string(jsonConfig)
  36. */
  37. request.AcceptFormat = "JSON"
  38. return client.UpdateWatermark(request)
  39. }
  40. func main() {
  41. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  42. if err != nil {
  43. panic(err)
  44. }
  45. response, err := MyUpdateWatermark(client)
  46. if err != nil {
  47. panic(err)
  48. }
  49. fmt.Println(response.GetHttpContentString())
  50. fmt.Println(response.RequestId)
  51. fmt.Printf("%s: %s\n", response.WatermarkInfo.WatermarkId, response.WatermarkInfo.WatermarkConfig)
  52. }

删除水印

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

  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. "encoding/json"
  7. "fmt"
  8. )
  9. func MyDeleteWatermark(client *vod.Client) (response *vod.DeleteWatermarkResponse, err error) {
  10. request := vod.CreateDeleteWatermarkRequest()
  11. request.WatermarkId = "<WatermarkId>"
  12. request.AcceptFormat = "JSON"
  13. return client.DeleteWatermark(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MyDeleteWatermark(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. }

查询水印列表

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

  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. "encoding/json"
  7. "fmt"
  8. )
  9. func MyListWatermark(client *vod.Client) (response *vod.ListWatermarkResponse, err error) {
  10. request := vod.CreateListWatermarkRequest()
  11. request.AcceptFormat = "JSON"
  12. return client.ListWatermark(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyListWatermark(client)
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. fmt.Println(response.RequestId)
  25. for _, watermark := range response.WatermarkInfos {
  26. fmt.Printf("%s: %s %s\n", watermark.WatermarkId, watermark.Name, watermark.WatermarkConfig)
  27. }
  28. }

查询单个水印

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

  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. "encoding/json"
  7. "fmt"
  8. )
  9. func MyGetWatermark(client *vod.Client) (response *vod.GetWatermarkResponse, err error) {
  10. request := vod.CreateGetWatermarkRequest()
  11. request.WatermarkId = "<WatermarkId>"
  12. request.AcceptFormat = "JSON"
  13. return client.GetWatermark(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MyGetWatermark(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. watermark := response.WatermarkInfo
  27. fmt.Printf("%s: %s %s\n", response.WatermarkInfo.WatermarkId, watermark.Name, watermark.WatermarkConfig)
  28. }

设置默认水印

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

  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. "encoding/json"
  7. "fmt"
  8. )
  9. func MySetDefaultWatermark(client *vod.Client) (response *vod.SetDefaultWatermarkResponse, err error) {
  10. request := vod.CreateSetDefaultWatermarkRequest()
  11. request.WatermarkId = "<WatermarkId>"
  12. request.AcceptFormat = "JSON"
  13. return client.SetDefaultWatermark(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MySetDefaultWatermark(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. }