Skip to content

Commit 5f9dac3

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 0ed9e4d + 4108377 commit 5f9dac3

File tree

4 files changed

+103
-6
lines changed

4 files changed

+103
-6
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Qencode, Corp
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

examples/start_encode2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Qencode\QencodeApiClient;
1313

1414
// Replace this with your API key
15-
$apiKey = 'abcdefgh';
15+
$apiKey = '12345678';
1616
$video_url = 'https://qa.qencode.com/static/1.mp4';
1717

1818
$q = new QencodeApiClient($apiKey);

examples/start_encode2_json.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qencode\Exceptions\QencodeApiException;
5+
use Qencode\Exceptions\QencodeClientException;
6+
use Qencode\Exceptions\QencodeException;
7+
use Qencode\Classes\CustomTranscodingParams;
8+
use Qencode\Classes\Format;
9+
use Qencode\Classes\Stream;
10+
use Qencode\Classes\Destination;
11+
use Qencode\Classes\Libx264_VideoCodecParameters;
12+
use Qencode\QencodeApiClient;
13+
14+
// Replace this with your API key
15+
$apiKey = '12345678';
16+
$params = '
17+
{"query": {
18+
"source": "https://qa.qencode.com/static/timer.mp4",
19+
"format": [
20+
{
21+
"output": "mp4",
22+
"size": "320x240",
23+
"video_codec": "libx264"
24+
}
25+
]
26+
}
27+
}';
28+
29+
$q = new QencodeApiClient($apiKey);
30+
31+
try {
32+
33+
$task = $q->createTask();
34+
log_message("Created task: ".$task->getTaskToken());
35+
36+
$task->startCustom($params);
37+
38+
do {
39+
sleep(5);
40+
$response = $task->getStatus();
41+
if (is_array($response) and array_key_exists('percent', $response)) {
42+
log_message("Completed: {$response['percent']}%");
43+
}
44+
} while ($response['status'] != 'completed');
45+
46+
foreach ($response['videos'] as $video) {
47+
log_message($video['user_tag'] . ': ' . $video['url']);
48+
}
49+
echo "DONE!";
50+
51+
} catch (QencodeClientException $e) {
52+
// We got some inconsistent state in client application (e.g. task_token not found when requesting status)
53+
log_message('Qencode Client Exception: ' . $e->getCode() . ' ' . $e->getMessage());
54+
} catch (QencodeApiException $e) {
55+
// API response status code was not successful
56+
log_message('Qencode API Exception: ' . $e->getCode() . ' ' . $e->getMessage());
57+
} catch (QencodeException $e) {
58+
// API call failed
59+
log_message('Qencode Exception: ' . $e->getMessage());
60+
var_export($q->getLastResponseRaw());
61+
}
62+
63+
function log_message($msg) {
64+
echo $msg."\n";
65+
}

src/Classes/TranscodingTask.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,24 @@ public function start($transcodingProfiles, $uri = null, $transferMethod = null,
124124
* @return array start_encode API method response
125125
*/
126126
public function startCustom($task_params, $payload = null) {
127-
if (is_array($this->stitchVideoItems)) {
128-
$task_params->stitch = $this->stitchVideoItems;
127+
128+
switch (gettype($task_params)) {
129+
case 'object':
130+
if (is_array($this->stitchVideoItems)) {
131+
$task_params->stitch = $this->stitchVideoItems;
132+
}
133+
$query = array ('query' => $task_params);
134+
$query_json = json_encode($query);
135+
break;
136+
case 'string':
137+
$query_json = $task_params;
138+
break;
139+
default:
140+
$query_json = '';
129141
}
130-
$query = array ('query' => $task_params);
131-
$query_json = json_encode($query);
142+
132143
$query_json = preg_replace('/,\s*"[^"]+":null|"[^"]+":null,?/', '', $query_json);
133-
//echo $query_json."\n\n";
144+
// echo $query_json."\n\n";
134145
$params = array(
135146
'task_token' => $this->taskToken,
136147
'query' => $query_json

0 commit comments

Comments
 (0)