Mps.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. include_once '../vendor/aliyun/aliyun-php-sdk-core/Config.php';
  5. use Mts\Request\V20140618 as Mts;
  6. /**
  7. * 示例接口
  8. */
  9. class Mps extends Api
  10. {
  11. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  12. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  13. //如果接口已经设置无需登录,那也就无需鉴权了
  14. //
  15. // 无需登录的接口,*表示全部
  16. protected $noNeedLogin = ['mpsvideo'];
  17. // 无需鉴权的接口,*表示全部
  18. protected $noNeedRight = [''];
  19. //阿里云媒体处理视频
  20. public function mpsvideo()
  21. {
  22. // $i = strpos('https://eyefate.oss-cn-hangzhou.aliyuncs.com/uploads/xuanzhuan.mp4','uploads');
  23. // var_dump($i);
  24. // $oss_input_object = substr('https://eyefate.oss-cn-hangzhou.aliyuncs.com/uploads/xuanzhuan.mp4', strpos('https://eyefate.oss-cn-hangzhou.aliyuncs.com/uploads/xuanzhuan.mp4', 'uploads'));
  25. // var_dump($oss_input_object);
  26. // $oss_output_object = str_replace('uploads', 'output', $oss_input_object);
  27. // var_dump($oss_output_object);
  28. // die;
  29. $access_key_id = 'LTAI5tRun9ZQVSgeg9mbjzjh'; //AccessKey ID
  30. $access_key_secret = 'nIkOAGe5Xttrjn7B5s0flk4z8zCdw8'; //AccessKey Secret
  31. $mps_region_id = 'cn-hangzhou';
  32. $pipeline_id = '0c4f9b648be54da09e29d8819f60a0df'; //管道id
  33. $watermark_template_id = '0c09ed4ef64e424b89a3449bcc0de522'; //水印模板id
  34. $template_id = '4c43c0ff9436425dbb6eaf2ce74e0ff0';//'S00000001-200030'; //转码模板id
  35. $oss_location = 'oss-cn-hangzhou';
  36. $oss_bucket = 'eyefate'; //bucket
  37. $oss_input_object = 'uploads/2022330/ZWIFbwAxNmdF.mp4'; //输入文件
  38. $oss_output_object = 'output/2022330/ZWIFbwAxNmdF.mp4'; //输出文件
  39. $image_watermark_object = 'logo.png'; //水印logo地址
  40. // $video_watermark_object = 'logo.mov';
  41. # DefaultAcsClient
  42. $clientProfile = \DefaultProfile::getProfile(
  43. $mps_region_id, # Region ID
  44. $access_key_id, # AccessKey ID
  45. $access_key_secret # AccessKey Secret
  46. );
  47. $client = new \DefaultAcsClient($clientProfile);
  48. # request
  49. $request = new Mts\SubmitJobsRequest();
  50. $request->setAcceptFormat('JSON');
  51. # Input
  52. $input = array('Location' => $oss_location,
  53. 'Bucket' => $oss_bucket,
  54. 'Object' => urlencode($oss_input_object));
  55. $request->setInput(json_encode($input));
  56. # Output
  57. $output = array('OutputObject' => urlencode($oss_output_object));
  58. # Ouput->TemplateId
  59. $output['TemplateId'] = $template_id;
  60. ## Image Watermark
  61. $image_watermark_input = array(
  62. 'Location' => $oss_location,
  63. 'Bucket' => $oss_bucket,
  64. 'Object' => urlencode($image_watermark_object)
  65. );
  66. $image_watermark = array(
  67. 'WaterMarkTemplateId' => $watermark_template_id,
  68. 'Type' => 'Image',
  69. 'InputFile' => $image_watermark_input,
  70. // 'ReferPos' => 'TopRight',
  71. // 'Width' => 0.05,
  72. 'Dx' => 100,
  73. 'Dy'=> 50
  74. );
  75. ## Text Watermark
  76. /* $text_config = array(
  77. 'Content' => '5rWL6K+V5paH5a2X5rC05Y2w',
  78. 'FontName' => 'SimSun',
  79. 'FontSize' => 16,
  80. 'FontColor' => 'Red',
  81. 'FontAlpha' => 0.5,
  82. 'Top' => 10,
  83. 'Left' => 10
  84. );
  85. $text_watermark = array(
  86. 'WaterMarkTemplateId' => $watermark_template_id,
  87. 'Type' => 'Text',
  88. 'TextWaterMark' => $text_config
  89. );*/
  90. ## Video Watermark
  91. /*$video_watermark_input = array (
  92. 'Location' => $oss_location,
  93. 'Bucket' => $oss_bucket,
  94. 'Object' => urlencode($video_watermark_object)
  95. );
  96. $video_watermark = array(
  97. 'WaterMarkTemplateId' => $watermark_template_id,
  98. 'Type' => 'Image',
  99. 'InputFile'=> $video_watermark_input,
  100. 'ReferPos' => 'BottomLeft',
  101. 'Height' => 240,
  102. 'Dx' => 0,
  103. 'Dy' => 0
  104. );*/
  105. # Output->Watermarks
  106. // $watermarks = array($image_watermark, $text_watermark, $video_watermark);
  107. $watermarks = array($image_watermark);
  108. $output['WaterMarks'] = $watermarks;
  109. # Outputs
  110. $outputs = array($output);
  111. $request->setOUtputs(json_encode($outputs));
  112. $request->setOutputBucket($oss_bucket);
  113. $request->setOutputLocation($oss_location);
  114. # PipelineId
  115. $request->setPipelineId($pipeline_id);
  116. # call api
  117. try {
  118. $response = $client->getAcsResponse($request);
  119. print 'RequestId is:' . $response->{'RequestId'} . "\n";;
  120. if ($response->{'JobResultList'}->{'JobResult'}[0]->{'Success'}) {
  121. print 'JobId is:' .
  122. $response->{'JobResultList'}->{'JobResult'}[0]->{'Job'}->{'JobId'} . "\n";
  123. } else {
  124. print 'SubmitJobs Failed code:' .
  125. $response->{'JobResultList'}->{'JobResult'}[0]->{'Code'} .
  126. ' message:' .
  127. $response->{'JobResultList'}->{'JobResult'}[0]->{'Message'} . "\n";
  128. }
  129. } catch(ServerException $e) {
  130. print 'Error: ' . $e->getErrorCode() . ' Message: ' . $e->getMessage() . "\n";
  131. } catch(ClientException $e) {
  132. print 'Error: ' . $e->getErrorCode() . ' Message: ' . $e->getMessage() . "\n";
  133. }
  134. }
  135. }