All Products
Search
Document Center

Media processing

Last Updated: Aug 01, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Submit a transcoding job

For more information about the request and response parameters, see SubmitTranscodeJobs.

  1. #include <stdio.h>
  2. #include <string>
  3. #include <map>
  4. #include <jsoncpp/json/json.h>
  5. #include "vod_sdk/openApiUtil.h"
  6. /**
  7. * Currently, the constructed watermark replacement parameter can be used to replace only the file URL of an image watermark or the content of a text watermark.
  8. * The watermark ID of the source watermark information (to be replaced) must be associated with the transcoding template ID specified by the TranscodeTemplateId parameter.
  9. * You can call the SubmitTranscodeJobs operation to add only watermarks whose IDs are associated with template IDs.
  10. * Note: The origin that stores the image watermark file must be the same as the origin that stores the video to be transcoded.
  11. */
  12. Json::Value buildOverrideParams() {
  13. Json::Value overrideParams;
  14. Json::Value watermarks;
  15. Json::Value watermark1;
  16. watermark1["WatermarkId"] = "2ea587477c5a1bc8b5742d7";
  17. // Specifies the target OSS URL of the image watermark file. The origin that stores the image watermark file must be the same as the origin that stores the video to be transcoded.
  18. watermark1["FileUrl"] = "https://outin-40564284ef05113e1403e7.oss-cn-shanghai.aliyuncs.com/watermarks/02A1B22DF25D46C3C725A4-6-2.png";
  19. watermarks.append(watermark1);
  20. // Replaces the content of a text watermark.
  21. Json::Value watermark2;
  22. // Associates the ID of the source text watermark with a template ID.
  23. watermark2["WatermarkId"] = "d297ba31ac5242d2071bf7";
  24. // Specifies the target content of the text watermark.
  25. watermark2["Content"] = "User ID: 66666";
  26. watermarks.append(watermark2);
  27. overrideParams["Watermarks"] = watermarks;
  28. return overrideParams;
  29. }
  30. /**
  31. * Generates an encryption key. The response contains a plaintext key and a ciphertext key. You need to specify only the ciphertext key for ApsaraVideo for VOD.
  32. * Note: Set the KeySpec parameter to AES_128 and do not set the NumberOfBytes parameter.
  33. * @param serviceKey The service key that ApsaraVideo for VOD grants to you for generating a key. You can view the service key whose description is vod on the Keys page in the KMS console.
  34. */
  35. string generateDataKey(string serviceKey) {
  36. string ciphertextBlob;
  37. /*You need to use KMS to generate a ciphertext key. For more information, see the GenerateDataKey operation of KMS.*/
  38. return ciphertextBlob;
  39. }
  40. /**
  41. * Method for constructing the standard HLS encryption configuration
  42. */
  43. Json::Value buildEncryptConfig() {
  44. // Specifies the service key that ApsaraVideo for VOD grants to you in KMS. You can view the service key whose description is vod on the Keys page in the KMS console.
  45. string serviceKey = "<Your service key>";
  46. // Generates a random encryption key. The response contains a plaintext key and a ciphertext key.
  47. // Specifies only the ciphertext key for standard video encryption.
  48. string ciphertextBlob = generateDataKey(serviceKey);
  49. Json::Value encryptConfig;
  50. // Specifies the URL of the decryption API. The ciphertext key generated each time and the API URL are concatenated to generate the value of this parameter to provide a unique ciphertext decryption key for each video.
  51. // You can customize the name of the decryption API parameter. Ciphertext is used as an example.
  52. encryptConfig["DecryptKeyUri"] = "http://decrypt.demo.com/decrypt?Ciphertext=" + ciphertextBlob;
  53. // Sets the key service type. Currently, only KMS is supported.
  54. encryptConfig["KeyServiceType"] = "KMS";
  55. // Specifies the ciphertext key.
  56. encryptConfig["CipherText"] = ciphertextBlob;
  57. return encryptConfig;
  58. }
  59. /**
  60. * Method for submitting a media processing job
  61. */
  62. VodApiResponse submitTranscodeJobs(VodCredential authInfo) {
  63. string apiName = "SubmitTranscodeJobs";
  64. map<string, string> args;
  65. // Specifies the ID of the video to be transcoded.
  66. args["VideoId"] = "34a6ca54f5c140eece85a289096d";
  67. // Sets the ID of the transcoding template group.
  68. args["TemplateGroupId"] = "e8aa925a9798c630d30cd737d4";
  69. // Constructs a watermark replacement parameter (applicable only when the watermark information needs to be replaced).
  70. //Json::Value overrideParams = buildOverrideParams();
  71. // Sets the watermark replacement parameter (applicable only when the watermark information needs to be replaced).
  72. //args["OverrideParams"] = overrideParams.toStyledString();
  73. // Constructs a standard encryption configuration parameter (applicable only to standard encryption).
  74. //Json::Value encryptConfig = buildEncryptConfig();
  75. // Specifies the standard HLS encryption configuration (applicable only to standard encryption).
  76. //args["EncryptConfig"] = encryptConfig.toStyledString();
  77. return getAcsResponse(authInfo, apiName, args);
  78. }
  79. /**
  80. * Call example
  81. */
  82. void main() {
  83. VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
  84. VodApiResponse response = submitTranscodeJobs(authInfo);
  85. printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
  86. }

Submit a video snapshot job

For more information about the request and response parameters, see SubmitSnapshotJob.

For more information about how to create a snapshot template, see AddVodTemplate.

  1. #include <stdio.h>
  2. #include <string>
  3. #include <map>
  4. #include <jsoncpp/json/json.h>
  5. #include "vod_sdk/openApiUtil.h"
  6. /**
  7. * Method for constructing the sprite snapshot configuration
  8. * @return
  9. */
  10. Json::Value buildSnapshotTemplateConfig() {
  11. Json::Value spriteSnapshotConfig;
  12. spriteSnapshotConfig["CellWidth"] = "120";
  13. spriteSnapshotConfig["CellHeight"] = "68";
  14. spriteSnapshotConfig["Columns"] = "3";
  15. spriteSnapshotConfig["Lines"] = "10";
  16. spriteSnapshotConfig["Padding"] = "20";
  17. spriteSnapshotConfig["Margin"] = "50";
  18. // Keeps the original sprite snapshots.
  19. spriteSnapshotConfig["KeepCellPic"] = "keep";
  20. spriteSnapshotConfig["Color"] = "tomato";
  21. return spriteSnapshotConfig;
  22. }
  23. /**
  24. * Method for submitting a video snapshot job
  25. */
  26. VodApiResponse submitSnapshotJob(VodCredential authInfo) {
  27. string apiName = "SubmitSnapshotJob";
  28. map<string, string> args;
  29. // Specifies the ID of the video to be snapshot. (We recommend that you use a snapshot template.)
  30. args["VideoId"] = "4d237a8270084849bf42078761814069";
  31. // Specifies the snapshot template ID.
  32. args["SnapshotTemplateId"] = "5d745e6b8baadf589e0702426cfc62c81";
  33. // If you set the SnapshotTemplateId parameter, ignore the following parameters:
  34. args["Count"] = "50";
  35. args["SpecifiedOffsetTime"] = "0";
  36. args["Interval"] = "1";
  37. args["Width"] = "200";
  38. args["Height"] = "200";
  39. // Specifies the sprite snapshot configuration if required.
  40. Json::Value spriteSnapshotConfig = buildSnapshotTemplateConfig();
  41. args["SpriteSnapshotConfig"] = spriteSnapshotConfig.toStyledString();
  42. return getAcsResponse(authInfo, apiName, args);
  43. }
  44. // Call example
  45. void main() {
  46. VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
  47. VodApiResponse response = submitSnapshotJob(authInfo);
  48. printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
  49. }

Query snapshot data

For more information about the request and response parameters, see ListSnapshots.

  1. #include <stdio.h>
  2. #include <string>
  3. #include <map>
  4. #include "vod_sdk/openApiUtil.h"
  5. /**
  6. * Method for querying snapshot data
  7. */
  8. VodApiResponse listSnapshots(VodCredential authInfo) {
  9. string apiName = "ListSnapshots";
  10. map<string, string> args;
  11. // Sets the video ID.
  12. args["VideoId"] = "c86c0ceba97965352418";
  13. args["SnapshotType"] = "CoverSnapshot";
  14. args["PageNo"] = "1";
  15. args["PageSize"] = "20";
  16. return getAcsResponse(authInfo, apiName, args);
  17. }
  18. // Call example
  19. void main() {
  20. VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
  21. VodApiResponse response = listSnapshots(authInfo);
  22. printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
  23. }