Skip to content

Commit 9a7e9e1

Browse files
1st sdk version
1 parent 6b10d18 commit 9a7e9e1

13 files changed

+781
-0
lines changed

autoload.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
$files = array(
3+
"Exceptions/QencodeException.php",
4+
"Exceptions/QencodeApiException.php",
5+
"Classes/TranscodingTask.php",
6+
"Classes/TranscodingTaskCollection.php",
7+
"Classes/CustomTranscodingParams.php",
8+
"Classes/Destination.php",
9+
"Classes/Format.php",
10+
"Classes/Stream.php",
11+
"Classes/VideoCodecParameters.php",
12+
"Classes/TranscodingTaskStatus.php",
13+
"Classes/VideoStatus.php",
14+
"Classes/VideoStorageInfo.php",
15+
"QencodeApiClient.php",
16+
);
17+
18+
foreach ($files as $file) {
19+
require_once(__DIR__."/src/".$file);
20+
}

examples/start_encode.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qencode\Exceptions\QencodeApiException;
5+
use Qencode\Exceptions\QencodeException;
6+
use Qencode\QencodeApiClient;
7+
8+
// Replace this with your API key
9+
$apiKey = '5a5db6fa5b4c5';
10+
11+
$transcodingProfileId = '5a5db6fa5b8ac';
12+
13+
$video_url = 'https://qa.stagevids.com/static/1.mp4';
14+
15+
$q = new QencodeApiClient($apiKey, 'https://api-qa.qencode.com');
16+
17+
try {
18+
19+
$task = $q->createTask();
20+
$task->start($transcodingProfileId, $video_url);
21+
22+
do {
23+
sleep(5);
24+
$response = $task->getStatus();
25+
} while ($response['status'] != 'completed');
26+
27+
foreach ($response['videos'] as $video) {
28+
echo $video['user_tag'] . ': ' . $video['url'].'<BR>';
29+
}
30+
echo "DONE!";
31+
32+
33+
} catch (QencodeApiException $e) {
34+
// API response status code was not successful
35+
echo 'Qencode API Exception: ' . $e->getCode() . ' ' . $e->getMessage();
36+
} catch (QencodeException $e) {
37+
// API call failed
38+
echo 'Qencode Exception: ' . $e->getMessage();
39+
var_export($pf->getLastResponseRaw());
40+
}

examples/start_encode2.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qencode\Exceptions\QencodeApiException;
5+
use Qencode\Exceptions\QencodeException;
6+
use Qencode\Classes\CustomTranscodingParams;
7+
use Qencode\Classes\Format;
8+
use Qencode\Classes\Stream;
9+
use Qencode\Classes\Destination;
10+
use Qencode\Classes\Libx264_VideoCodecParameters;
11+
use Qencode\QencodeApiClient;
12+
13+
// Replace this with your API key
14+
$apiKey = '5a5db6fa5b4c5';
15+
16+
$transcodingProfileId = '5a5db6fa5b8ac';
17+
18+
$video_url = 'https://qa.stagevids.com/static/1.mp4';
19+
20+
$q = new QencodeApiClient($apiKey, 'https://api-qa.qencode.com');
21+
22+
try {
23+
24+
$task = $q->createTask();
25+
$params = new CustomTranscodingParams();
26+
$params->source = $video_url;
27+
28+
$format = new Format();
29+
$format->destination = new Destination();
30+
$format->destination->url = "s3://s3-eu-west-2.amazonaws.com/qencode-test";
31+
$format->destination->key = "AKIAIKZIPSJ7SDAIWK4A";
32+
$format->destination->secret = "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";
33+
$format->output = "advanced_hls";
34+
35+
$stream = new Stream();
36+
$stream->size = "1920x1080";
37+
$stream->audio_bitrate = 128;
38+
$vcodec_params = new Libx264_VideoCodecParameters();
39+
$vcodec_params->vprofile = "baseline";
40+
$vcodec_params->level = 31;
41+
$vcodec_params->coder = 0;
42+
$vcodec_params->flags2 = "-bpyramid+fastpskip-dct8x8";
43+
$vcodec_params->partitions = "+parti8x8+parti4x4+partp8x8+partb8x8";
44+
$vcodec_params->directpred = 2;
45+
46+
$stream->video_codec_parameters = $vcodec_params;
47+
48+
$format->stream = [$stream];
49+
$params->format = [$format];
50+
51+
$task->startCustom($params);
52+
53+
do {
54+
sleep(5);
55+
$response = $task->getStatus();
56+
print_r($response);
57+
echo "<BR><BR>";
58+
} while ($response['status'] != 'completed');
59+
60+
foreach ($response['videos'] as $video) {
61+
echo $video['user_tag'] . ': ' . $video['url'].'<BR>';
62+
}
63+
echo "DONE!";
64+
65+
66+
} catch (QencodeApiException $e) {
67+
// API response status code was not successful
68+
echo 'Qencode API Exception: ' . $e->getCode() . ' ' . $e->getMessage();
69+
} catch (QencodeException $e) {
70+
// API call failed
71+
echo 'Qencode Exception: ' . $e->getMessage();
72+
var_export($q->getLastResponseRaw());
73+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Qencode\Classes;
4+
5+
class CustomTranscodingParams {
6+
/**
7+
* Source video URI. Can be http(s) url or tus uri
8+
* @var string
9+
*/
10+
public $source;
11+
12+
/**
13+
* A list of objects, each describing params for a single output video stream (MP4, WEBM, HLS or MPEG-DASH).
14+
* @var string
15+
*/
16+
public $format;
17+
}

src/Classes/Destination.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Qencode\Classes;
4+
5+
class Destination {
6+
/**
7+
* Destination bucket url, e.g. s3://example.com/bucket
8+
* @var string
9+
*/
10+
public $url;
11+
12+
/**
13+
* Access key
14+
* @var string
15+
*/
16+
public $key;
17+
18+
/**
19+
* Access secret
20+
* @var string
21+
*/
22+
public $secret;
23+
}

src/Classes/Format.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Qencode\Classes;
4+
5+
class Format {
6+
/**
7+
* Output video format. Currently supported values are mp4, webm, advanced_hls, advanced_dash. Required.
8+
* @var string
9+
*/
10+
public $output;
11+
12+
/**
13+
* Output video file extension (for MP4 - defaults to '.mp4', for WEBM - defaults to '.webm').
14+
* @var string
15+
*/
16+
public $file_extension;
17+
18+
/**
19+
* URI to store output video in. In case this value is not specified, video is temporarily stored on Qencode servers.
20+
* @var Destination
21+
*/
22+
public $destination;
23+
24+
/**
25+
* Segment duration to split media (in seconds). Defaults to 8.
26+
* @var string
27+
*/
28+
public $segment_duration;
29+
30+
/**
31+
* Contains a list of elements each describing a single view stream (e.g. for HLS format).
32+
* @var string
33+
*/
34+
public $stream;
35+
}

src/Classes/Stream.php

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
3+
namespace Qencode\Classes;
4+
5+
class Stream {
6+
/**
7+
* Output video frame size in pixels ("width"x"height"). Defaults to original frame size.
8+
* @var string
9+
*/
10+
public $size;
11+
12+
/**
13+
* Output stream video codec. Defaults to libx264. Possible values are: libx264, libx265, libvpx, libvpx-vp9.
14+
* @var string
15+
*/
16+
public $video_codec;
17+
18+
/**
19+
* Output video stream bitrate in kylobytes. Defaults to 512.
20+
* Note: don't specify bitrate unless you want constant bitrate for the video. To create variable bitrate use quality param.
21+
* @var string
22+
*/
23+
public $bitrate;
24+
25+
/**
26+
* Output video stream quality (aka Constant rate factor). Use this param to produce optimized videos with variable bitrate.
27+
* For H.264 the range is 0-51: where 0 is lossless and 51 is worst possible.
28+
* A lower value is a higher quality and a subjectively sane range is 18-28.
29+
* Consider 18 to be visually lossless or nearly so: it should look the same or nearly the same as the input but it isn't technically lossless.
30+
* @var int
31+
*/
32+
public $quality;
33+
34+
/**
35+
* Rotate video through specified degrees value. Possible values are 90, 180, 270.
36+
* @var int
37+
*/
38+
public $rotate;
39+
40+
/**
41+
* Output video frame rate. Defaults to original frame rate.
42+
* @var string
43+
*/
44+
public $framerate;
45+
46+
/**
47+
* Output video pixel format. Possible values are yuv420p, yuv422p, yuvj420p, yuvj422p. Defaults to yuv420p.
48+
* @var string
49+
*/
50+
public $pix_format;
51+
52+
/**
53+
* x264 video codec settings profile. Possible values are high, main, baseline. Defaults to main.
54+
* @var string
55+
*/
56+
public $profile;
57+
58+
/**
59+
* Output stream video codec parameters.
60+
* @var VideoCodecParameters
61+
*/
62+
public $video_codec_parameters;
63+
64+
/**
65+
* Keyframe period (in frames). Defaults to 90.
66+
* @var int
67+
*/
68+
public $keyframe;
69+
70+
/**
71+
* Segment duration to split media (in seconds). Defaults to 8.
72+
* @var int
73+
*/
74+
public $segment_duration;
75+
76+
/**
77+
* Specifies the start time (in seconds) in input video to begin transcoding from.
78+
* @var float
79+
*/
80+
public $start_time;
81+
82+
/**
83+
* Specifies duration of the video fragment (in seconds) to be transcoded.
84+
* @var float
85+
*/
86+
public $duration;
87+
88+
/**
89+
* Output file audio bitrate value in kylobytes. Defaults to 64.
90+
* @var int
91+
*/
92+
public $audio_bitrate;
93+
94+
/**
95+
* Output file audio sample rate. Defaults to 44100.
96+
* @var int
97+
*/
98+
public $audio_sample_rate;
99+
100+
/**
101+
* Output file audio channels number. Default value is 2.
102+
* @var int
103+
*/
104+
public $audio_channels_number;
105+
106+
/**
107+
* Output file audio codec name. Possible values are: aac, vorbis. Defaults to aac.
108+
* @var string
109+
*/
110+
public $audio_codec;
111+
112+
/**
113+
* Defaults to stereo
114+
* @var string
115+
*/
116+
public $downmix_mode;
117+
118+
}

0 commit comments

Comments
 (0)