createMediaTranscodeJobs.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. require dirname(__FILE__, 2) . '/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. // 提交转码任务 https://cloud.tencent.com/document/product/436/54009
  15. // start --------------- 使用模版 ----------------- //
  16. $result = $cosClient->createMediaTranscodeJobs(array(
  17. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  18. 'Tag' => 'Transcode',
  19. 'QueueId' => 'paaf4fce5521a40888a3034a5de80f6ca',
  20. 'Input' => array(
  21. 'Object' => 'example.mp4'
  22. ),
  23. 'Operation' => array(
  24. 'TemplateId' => 't04e1ab86554984f1aa17c062fbf6c007c',
  25. // 'UserData' => 'xxx', // 透传用户信息
  26. // 'JobLevel' => '0', // 任务优先级,级别限制:0 、1 、2。级别越大任务优先级越高,默认为0
  27. 'Output' => array(
  28. 'Region' => $region,
  29. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  30. 'Object' => 'video02.mp4',
  31. ),
  32. 'Watermark' => array(
  33. array(
  34. 'Type' => 'Text',
  35. 'LocMode' => 'Absolute',
  36. 'Dx' => '64',
  37. 'Dy' => '64',
  38. 'Pos' => 'TopRight',
  39. 'Text' => array(
  40. 'Text' => '第一个水印',
  41. 'FontSize' => '30',
  42. 'FontType' => 'simfang.ttf',
  43. 'FontColor' => '#99ff00',
  44. 'Transparency' => '100', // 不透明度
  45. ),
  46. ),
  47. array(
  48. 'Type' => 'Text',
  49. 'LocMode' => 'Absolute',
  50. 'Dx' => '64',
  51. 'Dy' => '64',
  52. 'Pos' => 'TopLeft',
  53. 'Text' => array(
  54. 'Text' => '第二个水印',
  55. 'FontSize' => '30',
  56. 'FontType' => 'simfang.ttf',
  57. 'FontColor' => '#99ff00',
  58. 'Transparency' => '100', // 不透明度
  59. ),
  60. ),
  61. ),
  62. ),
  63. ));
  64. // 请求成功
  65. print_r($result);
  66. // end --------------- 使用模版 ----------------- //
  67. // start --------------- 自定义参数 ----------------- //
  68. $result = $cosClient->createMediaTranscodeJobs(array(
  69. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  70. 'Tag' => 'Transcode',
  71. 'QueueId' => 'asdadadfafsdkjhfjghdfjg',
  72. 'CallBack' => 'https://example.com/callback',
  73. 'Input' => array(
  74. 'Object' => 'video01.mp4'
  75. ),
  76. 'Operation' => array(
  77. // 'UserData' => 'xxx', // 透传用户信息
  78. // 'JobLevel' => '0', // 任务优先级,级别限制:0 、1 、2。级别越大任务优先级越高,默认为0
  79. 'Output' => array(
  80. 'Region' => $region,
  81. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  82. 'Object' => 'video01.mkv',
  83. ),
  84. 'Transcode' => array(
  85. 'Container' => array(
  86. 'Format' => 'mp4'
  87. ),
  88. 'Video' => array(
  89. 'Codec' => 'H.264',
  90. 'Profile' => 'high',
  91. 'Bitrate' => '1000',
  92. 'Preset' => 'medium',
  93. 'Width' => '1280',
  94. 'Fps' => '30',
  95. ),
  96. 'Audio' => array(
  97. 'Codec' => 'aac',
  98. 'Samplerate' => '44100',
  99. 'Bitrate' => '128',
  100. 'Channels' => '4',
  101. ),
  102. 'TransConfig' => array(
  103. 'AdjDarMethod' => 'scale',
  104. 'IsCheckReso' => 'false',
  105. 'ResoAdjMethod' => '1',
  106. ),
  107. 'TimeInterval' => array(
  108. 'Start' => '0',
  109. 'Duration' => '60',
  110. ),
  111. ),
  112. ),
  113. ));
  114. // 请求成功
  115. print_r($result);
  116. // end --------------- 自定义参数 ----------------- //
  117. } catch (\Exception $e) {
  118. // 请求失败
  119. echo($e);
  120. }