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. use Kms\Request\V20160120 as kms;
  2. /**
  3. * 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. Ignore this configuration if watermark replacement is not required.
  4. * The watermark ID of the source watermark information (to be replaced) must be associated with the transcoding template ID specified by the TranscodeTemplateId parameter.
  5. * You can call the SubmitTranscodeJobs operation to add only watermarks whose IDs are associated with template IDs.
  6. */
  7. function buildOverrideParams() {
  8. $overrideParams = array();
  9. // For example, replace a watermark.
  10. $watermarks = array();
  11. // Replaces the file URL of an image watermark.
  12. $watermarks1 = array();
  13. $watermarks1["WatermarkId"] = "2ea587477c5a1bc8bxxxxx";
  14. $watermarks1["FileUrl"] = "https://outin-40564284ef05113e1403e7.oss-cn-shanghai.aliyuncs.com/watermarks/02A1B22DF25D46C3C725A4-6-2.png";
  15. $watermarks[] = $watermarks1;
  16. // Replaces the content of a text watermark.
  17. $watermarks2 = array();
  18. $watermarks2["WatermarkId"] = "d297ba31ac5242d20xxxxx";
  19. $watermarks2["Content"] = "User ID: 66666";
  20. $watermarks[] = $watermarks2;
  21. $overrideParams["Watermarks"] = $watermarks;
  22. return json_encode($overrideParams);
  23. }
  24. /**
  25. * The standard HLS encryption configuration is optional. Ignore this configuration if standard HLS encryption is not required.
  26. * This operation is dependent on KMS. You need to install the KMS dependency package aliyun-python-sdk-kms.
  27. * For more information about the operation used to generate a key, see https://help.aliyun.com/document_detail/28948.html.
  28. */
  29. function buildEncryptConfig($client) {
  30. try {
  31. // Generates a random encryption key. The response contains a plaintext key and a ciphertext key.
  32. // Specifies only the ciphertext key for standard video encryption.
  33. $request = new kms\GenerateDataKeyRequest();
  34. $request->setKeyId('<serviceKey>');
  35. $request->setKeySpec("AES_128");
  36. $response = $client->getAcsResponse($request);
  37. $encryptConfig = array();
  38. # 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. Note that you need to deploy a decryption service.
  39. $encryptConfig["DecryptKeyUri"] = "http://decrypt.demo.com/decrypt?Ciphertext=" + $response->getCiphertextBlob();
  40. // Sets the key service type. Currently, only KMS is supported.
  41. $encryptConfig["KeyServiceType"] = "KMS";
  42. # You can customize the name of the decryption API parameter. Ciphertext is used as an example.
  43. $encryptConfig["CipherText"] = $response->getCiphertextBlob();
  44. return json_encode($encryptConfig);
  45. } catch (Exception $e) {
  46. print $e->getMessage()."\n";
  47. return null;
  48. }
  49. }
  50. /**
  51. * Method for submitting a media processing job
  52. */
  53. function submitTranscodeJobs($client) {
  54. $request = new vod\SubmitTranscodeJobsRequest();
  55. // Specifies the ID of the video to be transcoded.
  56. $request->setVideoId("6893fca9814640c8821efa523exxxxxx");
  57. // Sets the ID of the transcoding template group.
  58. $request->setTemplateGroupId("44f915b63a2375a6121533c6b2xxxxxx");
  59. // Constructs a watermark replacement parameter (applicable only when the watermark information needs to be replaced).
  60. $request->setOverrideParams(buildOverrideParams());
  61. // Specifies the standard HLS encryption configuration (applicable only to standard encryption).
  62. $request->setEncryptConfig(buildEncryptConfig($client));
  63. return $client->getAcsResponse($request);
  64. }
  65. /**
  66. * Call example
  67. */
  68. try {
  69. $client = initVodClient("<AccessKeyId>", "<AccessKeySecret>");
  70. $result = submitTranscodeJobs($client);
  71. var_dump($result);
  72. } catch (Exception $e) {
  73. print $e->getMessage()."\n";
  74. }

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. /**
  2. * Method for constructing the sprite snapshot configuration
  3. * @return
  4. */
  5. function buildSnapshotTemplateConfig() {
  6. $spriteSnapshotConfig = array();
  7. $spriteSnapshotConfig["CellWidth"] = "120";
  8. $spriteSnapshotConfig["CellHeight"] = "68";
  9. $spriteSnapshotConfig["Columns"] = "3";
  10. $spriteSnapshotConfig["Lines"] = "10";
  11. $spriteSnapshotConfig["Padding"] = "20";
  12. $spriteSnapshotConfig["Margin"] = "50";
  13. // Keeps the original sprite snapshots.
  14. $spriteSnapshotConfig["KeepCellPic"] = "keep";
  15. $spriteSnapshotConfig["Color"] = "tomato";
  16. return json_encode($spriteSnapshotConfig);
  17. }
  18. /**
  19. * Method for submitting a video snapshot job
  20. */
  21. function submitSnapshotJob($client) {
  22. $request = new vod\SubmitSnapshotJobRequest();
  23. // Specifies the ID of the video to be snapshot. (We recommend that you use a snapshot template.)
  24. $request->setVideoId("6893fca9814640c8821efa523exxxxx");
  25. // Specifies the snapshot template ID.
  26. $request->setSnapshotTemplateId("44f915b63a2375a6121533c6b2xxxxx");
  27. // If you set the SnapshotTemplateId parameter, ignore the following parameters:
  28. $request->setCount(50);
  29. $request->setSpecifiedOffsetTime(0);
  30. $request->setInterval(1);
  31. $request->setWidth("200");
  32. $request->setHeight("200");
  33. $request->setSpriteSnapshotConfig(buildSnapshotTemplateConfig());
  34. return $client->getAcsResponse($request);
  35. }
  36. /**
  37. * Call example
  38. */
  39. try {
  40. $client = initVodClient("<AccessKeyId>", "<AccessKeySecret>");
  41. $result = submitSnapshotJob($client);
  42. var_dump($result);
  43. } catch (Exception $e) {
  44. print $e->getMessage()."\n";
  45. }

Query snapshot data

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

  1. /**
  2. * Method for querying snapshot data
  3. */
  4. function listSnapshots($client) {
  5. $request = new vod\ListSnapshotsRequest();
  6. // Sets the video ID.
  7. $request->setVideoId("6893fca9814640c8821efa523exxxxxx");
  8. // Sets the snapshot type.
  9. $request->setSnapshotType("CoverSnapshot");
  10. // Sets the page number and number of data records per page.
  11. $request->setPageNo("1");
  12. $request->setPageSize("20");
  13. return $client->getAcsResponse($request);
  14. }
  15. /**
  16. * Call example
  17. */
  18. try {
  19. $client = initVodClient("<AccessKeyId>", "<AccessKeySecret>");
  20. $result = listSnapshots($client);
  21. var_dump($result);
  22. } catch (Exception $e) {
  23. print $e->getMessage()."\n";
  24. }