Skip to content

Commit fa17742

Browse files
Added support for additional params
start_time / duration output_path_variables
1 parent 9a7e9e1 commit fa17742

File tree

6 files changed

+59
-17
lines changed

6 files changed

+59
-17
lines changed

autoload.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
"Classes/Format.php",
1010
"Classes/Stream.php",
1111
"Classes/VideoCodecParameters.php",
12-
"Classes/TranscodingTaskStatus.php",
13-
"Classes/VideoStatus.php",
14-
"Classes/VideoStorageInfo.php",
1512
"QencodeApiClient.php",
1613
);
1714

examples/start_encode.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,53 @@
66
use Qencode\QencodeApiClient;
77

88
// Replace this with your API key
9-
$apiKey = '5a5db6fa5b4c5';
9+
// API key and params below, such as transcoding profile id and transfer method id
10+
// can be found in your account on https://cloud.qencode.com under Project settings
11+
$apiKey = 'abcdefgh';
12+
$transcodingProfileId = 'abcdefgh';
13+
$transferMethodId = 'abcdefgh';
1014

11-
$transcodingProfileId = '5a5db6fa5b8ac';
15+
$video_url = 'https://qa.qencode.com/static/bbb_sunflower_1080p_60fps_normal_339mb.mp4';
1216

13-
$video_url = 'https://qa.stagevids.com/static/1.mp4';
14-
15-
$q = new QencodeApiClient($apiKey, 'https://api-qa.qencode.com');
17+
$q = new QencodeApiClient($apiKey);
1618

1719
try {
1820

1921
$task = $q->createTask();
20-
$task->start($transcodingProfileId, $video_url);
22+
log_message("Created task: ".$task->getTaskToken());
23+
24+
//set start time (in seconds) in input video to begin transcoding from
25+
$task->start_time = 30.0;
26+
//duration of the video fragment (in seconds) to be transcoded
27+
$task->duration = 10.0;
28+
29+
//Setting output file name with a custom output path variable.
30+
//This refers to Output path values specified in transcoding profile for video or image settings
31+
//See https://portal.qencode.com/docs for more examples
32+
$task->output_path_variables->filename = 'qencode_test';
33+
34+
$task->start($transcodingProfileId, $video_url, $transferMethodId);
2135

2236
do {
2337
sleep(5);
2438
$response = $task->getStatus();
2539
} while ($response['status'] != 'completed');
2640

2741
foreach ($response['videos'] as $video) {
28-
echo $video['user_tag'] . ': ' . $video['url'].'<BR>';
42+
log_message($video['user_tag'] . ': ' . $video['url']);
2943
}
3044
echo "DONE!";
3145

3246

3347
} catch (QencodeApiException $e) {
3448
// API response status code was not successful
35-
echo 'Qencode API Exception: ' . $e->getCode() . ' ' . $e->getMessage();
49+
log_message('Qencode API Exception: ' . $e->getCode() . ' ' . $e->getMessage());
3650
} catch (QencodeException $e) {
3751
// API call failed
38-
echo 'Qencode Exception: ' . $e->getMessage();
52+
log_message('Qencode Exception: ' . $e->getMessage());
3953
var_export($pf->getLastResponseRaw());
4054
}
55+
56+
function log_message($msg) {
57+
echo $msg."\n";
58+
}

src/Classes/CustomTranscodingParams.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CustomTranscodingParams {
1111

1212
/**
1313
* A list of objects, each describing params for a single output video stream (MP4, WEBM, HLS or MPEG-DASH).
14-
* @var string
14+
* @var Format
1515
*/
1616
public $format;
1717
}

src/Classes/Format.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ class Format {
2323

2424
/**
2525
* Segment duration to split media (in seconds). Defaults to 8.
26-
* @var string
26+
* @var int
2727
*/
2828
public $segment_duration;
2929

3030
/**
3131
* Contains a list of elements each describing a single view stream (e.g. for HLS format).
32-
* @var string
32+
* @var Stream
3333
*/
3434
public $stream;
3535
}

src/Classes/Stream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ class Stream {
113113
* Defaults to stereo
114114
* @var string
115115
*/
116-
public $downmix_mode;
116+
//public $downmix_mode;
117117

118118
}

src/Classes/TranscodingTask.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ class TranscodingTask {
99
private $statusUrl;
1010
private $lastStatus;
1111

12+
/**
13+
* Video clip start time
14+
*/
15+
public $start_time;
16+
17+
/**
18+
* Video duration
19+
*/
20+
public $duration;
21+
22+
/**
23+
* JSON-encoded string containing a dictionary (key-value pairs) of params for video or image output path.
24+
*/
25+
public $output_path_variables;
26+
1227
/**
1328
* Gets transcoding task token
1429
* @return string
@@ -25,6 +40,7 @@ public function getStatusUrl() {
2540
return $this->statusUrl;
2641
}
2742

43+
2844
/**
2945
* @param QencodeApiClient $api a reference to QencodeApiClient object
3046
* @param string $task_token transcoding task token
@@ -33,6 +49,9 @@ public function __construct($api, $task_token) {
3349
$this->api = $api;
3450
$this->taskToken = $task_token;
3551
$this->statusUrl = null;
52+
$this->start_time = null;
53+
$this->duration = null;
54+
$this->output_path_variables = new \stdClass();
3655
}
3756

3857
/**
@@ -55,7 +74,15 @@ public function start($transcodingProfiles, $uri, $transferMethod = null, $paylo
5574
if ($payload) {
5675
$params['payload'] = $payload;
5776
}
58-
77+
if ($this->start_time) {
78+
$params['start_time'] = $this->start_time;
79+
}
80+
if ($this->duration) {
81+
$params['duration'] = $this->duration;
82+
}
83+
if ($this->output_path_variables) {
84+
$params['output_path_variables'] = json_encode($this->output_path_variables);
85+
}
5986
$response = $this->api->post('start_encode', $params);
6087
$this->statusUrl = $response['status_url'];
6188
return $response;

0 commit comments

Comments
 (0)