Skip to content

Commit 193a4a4

Browse files
authored
视频转码接口 (#217)
1 parent ed9feda commit 193a4a4

File tree

6 files changed

+270
-2
lines changed

6 files changed

+270
-2
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
$result = $cosClient->createMediaTranscodeJobs(array(
17+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
18+
'Tag' => 'Transcode',
19+
'QueueId' => 'asdadadfafsdkjhfjghdfjg',
20+
'CallBack' => 'https://example.com/callback',
21+
'Input' => array(
22+
'Object' => 'video01.mp4'
23+
),
24+
'Operation' => array(
25+
'TemplateId' => 'asdfafiahfiushdfisdhfuis',
26+
'Output' => array(
27+
'Region' => $region,
28+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
29+
'Object' => 'video02.webm',
30+
),
31+
),
32+
));
33+
// 请求成功
34+
print_r($result);
35+
} catch (\Exception $e) {
36+
// 请求失败
37+
echo($e);
38+
}
39+

src/Qcloud/Cos/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
* @method object DeleteBucketGuetzli (array $arg)
9393
* @method object GetObjectSensitiveContentRecognition (array $arg)
9494
* @method object DetectText (array $arg)
95+
* @method object CreateMediaTranscodeJobs (array $arg)
9596
*/
9697
class Client extends GuzzleClient {
9798
const VERSION = '2.2.3';

src/Qcloud/Cos/CommandToRequestTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function ciParamTransformer( CommandInterface $command, $request ) {
218218

219219
public function cosDomain2CiTransformer($command, $request) {
220220
$action = $command->getName();
221-
if ($action == 'DetectText') {
221+
if ($action == 'DetectText' || $action == 'CreateMediaTranscodeJobs') {
222222
$bucketname = $command['Bucket'];
223223
$appId = $this->config['appId'];
224224
if ( $appId != null && endWith( $bucketname, '-'.$appId ) == False ) {
@@ -234,7 +234,7 @@ public function cosDomain2CiTransformer($command, $request) {
234234
$host = $this->config['ip'] . ':' . $this->config['port'];
235235
}
236236
}
237-
$path = $this->config['schema'].'://'. $host . '/text/auditing';
237+
$path = $this->config['schema'].'://'. $host . $request->getUri()->getPath();
238238
$uri = new Uri( $path );
239239
$query = $request->getUri()->getQuery();
240240
$uri = $uri->withQuery( $query );

src/Qcloud/Cos/Descriptions.php

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
<?php
2+
3+
namespace Qcloud\Cos;
4+
5+
/**
6+
* 为 src/Qcloud/Cos/Service.php 服务,视觉上区分各方法的参数\输出描述
7+
* 原service的参数描述可不改动
8+
* Class Descriptions
9+
* @package Qcloud\Cos
10+
*/
11+
class Descriptions {
12+
public static function CreateMediaTranscodeJobs() {
13+
return array(
14+
'httpMethod' => 'POST',
15+
'uri' => '/{Bucket}jobs',
16+
'class' => 'Qcloud\\Cos\\Command',
17+
'responseClass' => 'CreateMediaTranscodeJobsOutput',
18+
'responseType' => 'model',
19+
'data' => array(
20+
'xmlRoot' => array(
21+
'name' => 'Request',
22+
),
23+
),
24+
'parameters' => array(
25+
'Bucket' => array( 'required' => true, 'type' => 'string', 'location' => 'uri', ),
26+
'Tag' => array( 'required' => true, 'location' => 'xml', 'type' => 'string', ),
27+
'QueueId' => array( 'required' => true, 'location' => 'xml', 'type' => 'string', ),
28+
'CallBack' => array( 'required' => true, 'location' => 'xml', 'type' => 'string', ),
29+
'Input' => array(
30+
'required' => true,
31+
'type' => 'object',
32+
'location' => 'xml',
33+
'properties' => array(
34+
'Object' => array( 'required' => true, 'type' => 'string', 'location' => 'xml', ),
35+
),
36+
),
37+
'Operation' => array(
38+
'required' => true,
39+
'type' => 'object',
40+
'location' => 'xml',
41+
'properties' => array(
42+
'TemplateId' => array( 'type' => 'string', 'location' => 'xml', ),
43+
'WatermarkTemplateId' => array( 'type' => 'string', 'location' => 'xml', ),
44+
'Transcode' => array(
45+
'type' => 'object',
46+
'location' => 'xml',
47+
'properties' => array(
48+
'Container' => array(
49+
'type' => 'object',
50+
'location' => 'xml',
51+
'properties' => array(
52+
'Format' => array( 'type' => 'string', 'location' => 'xml', ),
53+
),
54+
),
55+
'Video' => array(
56+
'type' => 'object',
57+
'location' => 'xml',
58+
'properties' => array(
59+
'Codec' => array( 'type' => 'string', 'location' => 'xml', ),
60+
'Width' => array( 'type' => 'string', 'location' => 'xml', ),
61+
'Height' => array( 'type' => 'string', 'location' => 'xml', ),
62+
'Fps' => array( 'type' => 'string', 'location' => 'xml', ),
63+
'Remove' => array( 'type' => 'string', 'location' => 'xml', ),
64+
'Profile' => array( 'type' => 'string', 'location' => 'xml', ),
65+
'Bitrate' => array( 'type' => 'string', 'location' => 'xml', ),
66+
'Crf' => array( 'type' => 'string', 'location' => 'xml', ),
67+
'Gop' => array( 'type' => 'string', 'location' => 'xml', ),
68+
'Preset' => array( 'type' => 'string', 'location' => 'xml', ),
69+
'Bufsize' => array( 'type' => 'string', 'location' => 'xml', ),
70+
'Maxrate' => array( 'type' => 'string', 'location' => 'xml', ),
71+
'HlsTsTime' => array( 'type' => 'string', 'location' => 'xml', ),
72+
'Pixfmt' => array( 'type' => 'string', 'location' => 'xml', ),
73+
'LongShortMode' => array( 'type' => 'string', 'location' => 'xml', ),
74+
),
75+
),
76+
'TimeInterval' => array(
77+
'type' => 'object',
78+
'location' => 'xml',
79+
'properties' => array(
80+
'Start' => array( 'type' => 'string', 'location' => 'xml', ),
81+
'Duration' => array( 'type' => 'string', 'location' => 'xml', ),
82+
),
83+
),
84+
'Audio' => array(
85+
'type' => 'object',
86+
'location' => 'xml',
87+
'properties' => array(
88+
'Codec' => array( 'type' => 'string', 'location' => 'xml', ),
89+
'Samplerate' => array( 'type' => 'string', 'location' => 'xml', ),
90+
'Bitrate' => array( 'type' => 'string', 'location' => 'xml', ),
91+
'Channels' => array( 'type' => 'string', 'location' => 'xml', ),
92+
'Remove' => array( 'type' => 'string', 'location' => 'xml', ),
93+
'KeepTwoTracks' => array( 'type' => 'string', 'location' => 'xml', ),
94+
'SwitchTrack' => array( 'type' => 'string', 'location' => 'xml', ),
95+
'SampleFormat' => array( 'type' => 'string', 'location' => 'xml', ),
96+
),
97+
),
98+
'TransConfig' => array(
99+
'type' => 'object',
100+
'location' => 'xml',
101+
'properties' => array(
102+
'AdjDarMethod' => array( 'type' => 'string', 'location' => 'xml', ),
103+
'IsCheckReso' => array( 'type' => 'string', 'location' => 'xml', ),
104+
'ResoAdjMethod' => array( 'type' => 'string', 'location' => 'xml', ),
105+
'IsCheckVideoBitrate' => array( 'type' => 'string', 'location' => 'xml', ),
106+
'VideoBitrateAdjMethod' => array( 'type' => 'string', 'location' => 'xml', ),
107+
'IsCheckAudioBitrate' => array( 'type' => 'string', 'location' => 'xml', ),
108+
'AudioBitrateAdjMethod' => array( 'type' => 'string', 'location' => 'xml', ),
109+
'DeleteMetadata' => array( 'type' => 'string', 'location' => 'xml', ),
110+
'IsHdr2Sdr' => array( 'type' => 'string', 'location' => 'xml', ),
111+
'HlsEncrypt' => array(
112+
'type' => 'object',
113+
'location' => 'xml',
114+
'properties' => array(
115+
'IsHlsEncrypt' => array( 'type' => 'string', 'location' => 'xml', ),
116+
'UriKey' => array( 'type' => 'string', 'location' => 'xml', ),
117+
),
118+
),
119+
),
120+
),
121+
),
122+
),
123+
'Watermark' => array(
124+
'type' => 'object',
125+
'location' => 'xml',
126+
'properties' => array(
127+
'Type' => array( 'type' => 'string', 'location' => 'xml', ),
128+
'Pos' => array( 'type' => 'string', 'location' => 'xml', ),
129+
'LocMode' => array( 'type' => 'string', 'location' => 'xml', ),
130+
'Dx' => array( 'type' => 'string', 'location' => 'xml', ),
131+
'Dy' => array( 'type' => 'string', 'location' => 'xml', ),
132+
'StartTime' => array( 'type' => 'string', 'location' => 'xml', ),
133+
'EndTime' => array( 'type' => 'string', 'location' => 'xml', ),
134+
'Image' => array(
135+
'type' => 'object',
136+
'location' => 'xml',
137+
'properties' => array(
138+
'Url' => array( 'type' => 'string', 'location' => 'xml', ),
139+
'Mode' => array( 'type' => 'string', 'location' => 'xml', ),
140+
'Width' => array( 'type' => 'string', 'location' => 'xml', ),
141+
'Height' => array( 'type' => 'string', 'location' => 'xml', ),
142+
'Transparency' => array( 'type' => 'string', 'location' => 'xml', ),
143+
'Background' => array( 'type' => 'string', 'location' => 'xml', ),
144+
),
145+
),
146+
'Text' => array(
147+
'type' => 'object',
148+
'location' => 'xml',
149+
'properties' => array(
150+
'FontSize' => array( 'type' => 'string', 'location' => 'xml', ),
151+
'FontType' => array( 'type' => 'string', 'location' => 'xml', ),
152+
'FontColor' => array( 'type' => 'string', 'location' => 'xml', ),
153+
'Transparency' => array( 'type' => 'string', 'location' => 'xml', ),
154+
'Text' => array( 'type' => 'string', 'location' => 'xml', ),
155+
),
156+
),
157+
),
158+
),
159+
'RemoveWatermark' => array(
160+
'type' => 'object',
161+
'location' => 'xml',
162+
'properties' => array(
163+
'Dx' => array( 'type' => 'string', 'location' => 'xml', ),
164+
'Dy' => array( 'type' => 'string', 'location' => 'xml', ),
165+
'Width' => array( 'type' => 'string', 'location' => 'xml', ),
166+
'Height' => array( 'type' => 'string', 'location' => 'xml', ),
167+
),
168+
),
169+
'Output' => array(
170+
'required' => true,
171+
'type' => 'object',
172+
'location' => 'xml',
173+
'properties' => array(
174+
'Region' => array( 'required' => true, 'type' => 'string', 'location' => 'xml', ),
175+
'Bucket' => array( 'required' => true, 'type' => 'string', 'location' => 'xml', ),
176+
'Object' => array( 'required' => true, 'type' => 'string', 'location' => 'xml', ),
177+
),
178+
),
179+
),
180+
),
181+
),
182+
);
183+
}
184+
185+
public static function CreateMediaTranscodeJobsOutput() {
186+
return array(
187+
'type' => 'object',
188+
'additionalProperties' => true,
189+
'properties' => array(
190+
'Body' => array(
191+
'type' => 'string',
192+
'instanceOf' => 'GuzzleHttp\\Psr7\\Stream',
193+
'location' => 'body',
194+
),
195+
'RequestId' => array(
196+
'type' => 'string',
197+
'location' => 'header',
198+
'sentAs' => 'x-ci-request-id',
199+
),
200+
'ContentType' => array(
201+
'type' => 'string',
202+
'location' => 'header',
203+
'sentAs' => 'Content-Type',
204+
),
205+
'ContentLength' => array(
206+
'type' => 'numeric',
207+
'minimum'=> 0,
208+
'location' => 'header',
209+
'sentAs' => 'Content-Length',
210+
),
211+
),
212+
);
213+
}
214+
}

src/Qcloud/Cos/ResultTransformer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ public function ciContentInfoTransformer(CommandInterface $command, Result $resu
104104
}
105105
}
106106

107+
if ($action == 'CreateMediaTranscodeJobs') {
108+
$length = intval($result['ContentLength']);
109+
if($length > 0){
110+
$content = $this->geCiContentInfo($result, $length);
111+
$obj = simplexml_load_string($content, "SimpleXMLElement", LIBXML_NOCDATA);
112+
$xmlData = json_decode(json_encode($obj),true);
113+
$result['Response'] = $xmlData;
114+
}
115+
}
116+
107117
return $result;
108118
}
109119

src/Qcloud/Cos/Service.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Qcloud\Cos;
33
// http://guzzle3.readthedocs.io/webservice-client/guzzle-service-descriptions.html
4+
5+
use Qcloud\Cos\Descriptions;
46
class Service {
57
public static function getService() {
68
return array(
@@ -3496,6 +3498,7 @@ public static function getService() {
34963498
),
34973499
),
34983500
),
3501+
'CreateMediaTranscodeJobs' => Descriptions::CreateMediaTranscodeJobs(),
34993502
),
35003503
'models' => array(
35013504
'AbortMultipartUploadOutput' => array(
@@ -6470,6 +6473,7 @@ public static function getService() {
64706473
),
64716474
),
64726475
),
6476+
'CreateMediaTranscodeJobsOutput' => Descriptions::CreateMediaTranscodeJobsOutput(),
64736477
)
64746478
);
64756479
}

0 commit comments

Comments
 (0)