createMediaTranscodeJobs.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. require dirname(__FILE__) . '/../vendor/autoload.php';
  3. $secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
  4. $secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
  5. $region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
  6. $cosClient = new Qcloud\Cos\Client(
  7. array(
  8. 'region' => $region,
  9. 'schema' => 'https', //协议头部,默认为http
  10. 'credentials'=> array(
  11. 'secretId' => $secretId ,
  12. 'secretKey' => $secretKey)));
  13. try {
  14. // 多任务接口
  15. $result = $cosClient->CreateMediaJobs(array(
  16. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  17. 'Tag' => 'Transcode',
  18. 'QueueId' => 'paaf4fce5521a40888a3034a5de80f6ca',
  19. 'CallBack' => '',
  20. 'Input' => array(
  21. 'Object' => 'example.mp4'
  22. ),
  23. 'Operation' => array(
  24. array(
  25. 'TemplateId' => 't04e1ab86554984f1aa17c062fbf6c007c',
  26. 'Output' => array(
  27. 'Region' => $region,
  28. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  29. 'Object' => 'video01.mp4',
  30. ),
  31. 'WatermarkTemplateId' => array(
  32. 't112d18d9b2a9b430e91d3c320f80af341',
  33. ),
  34. ),
  35. array(
  36. 'TemplateId' => 't04e1ab86554984f1aa17c062fbf6c007c',
  37. 'Output' => array(
  38. 'Region' => $region,
  39. 'Bucket' => 'wwj-cq-1253960454', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  40. 'Object' => 'video02.mp4',
  41. ),
  42. 'WatermarkTemplateId' => array(
  43. 't1bf713bb5c6a5496e859aebc4a8973ab5',
  44. ),
  45. ),
  46. ),
  47. ));
  48. // 单任务接口
  49. // start --------------- 使用模版 ----------------- //
  50. $result = $cosClient->createMediaTranscodeJobs(array(
  51. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  52. 'Tag' => 'Transcode',
  53. 'QueueId' => 'paaf4fce5521a40888a3034a5de80f6ca',
  54. 'Input' => array(
  55. 'Object' => 'example.mp4'
  56. ),
  57. 'Operation' => array(
  58. 'TemplateId' => 't04e1ab86554984f1aa17c062fbf6c007c',
  59. 'Output' => array(
  60. 'Region' => $region,
  61. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  62. 'Object' => 'video02.mp4',
  63. ),
  64. 'Watermark' => arrray(
  65. array(
  66. 'Type' => 'Text',
  67. 'LocMode' => 'Absolute',
  68. 'Dx' => '64',
  69. 'Dy' => '64',
  70. 'Pos' => 'TopRight',
  71. 'Text' => array(
  72. 'Text' => '第一个水印',
  73. 'FontSize' => '30',
  74. 'FontType' => 'simfang.ttf',
  75. 'FontColor' => '#99ff00',
  76. 'Transparency' => '100', // 不透明度
  77. ),
  78. ),
  79. array(
  80. 'Type' => 'Text',
  81. 'LocMode' => 'Absolute',
  82. 'Dx' => '64',
  83. 'Dy' => '64',
  84. 'Pos' => 'TopLeft',
  85. 'Text' => array(
  86. 'Text' => '第二个水印',
  87. 'FontSize' => '30',
  88. 'FontType' => 'simfang.ttf',
  89. 'FontColor' => '#99ff00',
  90. 'Transparency' => '100', // 不透明度
  91. ),
  92. ),
  93. ),
  94. ),
  95. ));
  96. $result = $cosClient->DescribeMediaJob(array(
  97. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  98. 'Key' => 'j20f7a6be6c5511eca253f3ee9d4082e0',
  99. ));
  100. $result = $cosClient->DescribeMediaJobs(array(
  101. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  102. 'Tag' => 'Transcode',
  103. 'QueueId' => 'paaf4fce5521a40888a3034a5de80f6ca',
  104. ));
  105. // 请求成功
  106. print_r($result);
  107. // end --------------- 使用模版 ----------------- //
  108. // start --------------- 自定义参数 ----------------- //
  109. $result = $cosClient->createMediaTranscodeJobs(array(
  110. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  111. 'Tag' => 'Transcode',
  112. 'QueueId' => 'asdadadfafsdkjhfjghdfjg',
  113. 'CallBack' => 'https://example.com/callback',
  114. 'Input' => array(
  115. 'Object' => 'video01.mp4'
  116. ),
  117. 'Operation' => array(
  118. 'Output' => array(
  119. 'Region' => $region,
  120. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  121. 'Object' => 'video01.mkv',
  122. ),
  123. 'Transcode' => array(
  124. 'Container' => array(
  125. 'Format' => 'mp4'
  126. ),
  127. 'Video' => array(
  128. 'Codec' => 'H.264',
  129. 'Profile' => 'high',
  130. 'Bitrate' => '1000',
  131. 'Preset' => 'medium',
  132. 'Width' => '1280',
  133. 'Fps' => '30',
  134. ),
  135. 'Audio' => array(
  136. 'Codec' => 'aac',
  137. 'Samplerate' => '44100',
  138. 'Bitrate' => '128',
  139. 'Channels' => '4',
  140. ),
  141. 'TransConfig' => array(
  142. 'AdjDarMethod' => 'scale',
  143. 'IsCheckReso' => 'false',
  144. 'ResoAdjMethod' => '1',
  145. ),
  146. 'TimeInterval' => array(
  147. 'Start' => '0',
  148. 'Duration' => '60',
  149. ),
  150. ),
  151. ),
  152. ));
  153. // 请求成功
  154. print_r($result);
  155. // end --------------- 自定义参数 ----------------- //
  156. } catch (\Exception $e) {
  157. // 请求失败
  158. echo($e);
  159. }