@@ -2,9 +2,13 @@ Zencoder API PHP Library
2
2
==========================
3
3
4
4
Author: [ Zac Shenker] (zshenker (a) brightcove (.) c ; om)
5
+
5
6
Company: [ Brightcove/Zencoder] ( http://www.zencoder.com )
7
+
6
8
Version: 2.2.0
9
+
7
10
Date: 2014-07-24
11
+
8
12
Repository: < http://github.com/zencoder/zencoder-php/ >
9
13
10
14
The Zencoder CA chain certificate has been removed from the library as the bundled cert will be expiring on July 26 2014,
@@ -13,9 +17,13 @@ Please contact us at help@zencoder.com with an issues.
13
17
14
18
15
19
Author: [ Michael Christopher] (mchristopher (a) brightcove (.) c ; om)
20
+
16
21
Company: [ Zencoder - Online Video Encoder] ( http://www.zencoder.com )
22
+
17
23
Version: 2.1.1
24
+
18
25
Date: 2012-08-02
26
+
19
27
Repository: < http://github.com/zencoder/zencoder-php/ >
20
28
21
29
Parts of this library are based on < http://github.com/twilio/twilio-php >
@@ -29,165 +37,190 @@ For more details on the Zencoder API requirements visit
29
37
To start working with the library, create a new instance of the Services_Zencoder class, passing
30
38
your API Key as the 1st parameter.
31
39
32
- $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
40
+ ``` php
41
+ $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
42
+ ```
33
43
34
44
Once you have created the object, you can use it to interact with the API. For full information,
35
45
see the Documentation folder, but here is a quick overview of some of the functions that can be
36
46
called:
37
47
38
- $zencoder->accounts->create($array);
39
- $zencoder->jobs->create($array);
40
- $zencoder->jobs->progress($job_id);
41
- $zencoder->inputs->details($input_id);
42
- $zencoder->outputs->details($output_id);
43
- $zencoder->notifications->parseIncoming();
48
+ ``` php
49
+ $zencoder->accounts->create($array);
50
+ $zencoder->jobs->create($array);
51
+ $zencoder->jobs->progress($job_id);
52
+ $zencoder->inputs->details($input_id);
53
+ $zencoder->outputs->details($output_id);
54
+ $zencoder->notifications->parseIncoming();
55
+ ```
44
56
45
57
Any errors will throw a Services_Zencoder_Exception. You can call getErrors() on an exception
46
58
and it will return any errors received from the Zencoder API.
47
59
48
60
49
61
ENCODING JOB
50
62
------------
63
+
51
64
The ZencoderJob object creates an encoding job using [ cURL] ( http://zencoder.com/docs/glossary/curl/ )
52
65
to send [ JSON] ( http://zencoder.com/docs/glossary/json/ ) formatted parameters to Zencoder's encoding API.
53
66
54
67
### Step 1
68
+
55
69
Visit the [ API builder] ( https://app.zencoder.com/api_builder ) in your account,
56
70
and execute a successful encoding job.
57
71
58
72
### Step 2
73
+
59
74
Copy the successful JSON string, starting with the first curly brace "{",
60
75
and pass it as the parameters for a new ZencoderJob object. Execute the script on your server to test that it works.
61
76
62
77
#### Example
63
- <pre>
64
- <?php
65
78
66
- // Make sure this points to a copy of Zencoder.php on the same server as this script.
67
- require_once('Services/Zencoder.php');
79
+ ``` php
80
+ <?php
81
+
82
+ // Make sure this points to a copy of Zencoder.php on the same server as this script.
83
+ require_once('Services/Zencoder.php');
68
84
69
- try {
70
- // Initialize the Services_Zencoder class
71
- $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
85
+ try {
86
+ // Initialize the Services_Zencoder class
87
+ $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
72
88
73
- // New Encoding Job
74
- $encoding_job = $zencoder->jobs->create(
89
+ // New Encoding Job
90
+ $encoding_job = $zencoder->jobs->create(
91
+ array(
92
+ "input" => "s3://bucket-name/file-name.avi",
93
+ "outputs" => array(
75
94
array(
76
- "input" => "s3://bucket-name/file-name.avi",
77
- "outputs" => array(
78
- array(
79
- "label" => "web"
80
- )
81
- )
95
+ "label" => "web"
82
96
)
83
- );
84
-
85
- // Success if we got here
86
- echo "w00t! \n\n";
87
- echo "Job ID: ".$encoding_job->id."\n";
88
- echo "Output ID: ".$encoding_job->outputs['web']->id."\n";
89
- // Store Job/Output IDs to update their status when notified or to check their progress.
90
- } catch (Services_Zencoder_Exception $e) {
91
- // If were here, an error occured
92
- echo "Fail :(\n\n";
93
- echo "Errors:\n";
94
- foreach ($e->getErrors() as $error) echo $error."\n";
95
- echo "Full exception dump:\n\n";
96
- print_r($e);
97
- }
98
-
99
- echo "\nAll Job Attributes:\n";
100
- var_dump($encoding_job);
101
-
102
- ?>
103
- </pre>
97
+ )
98
+ )
99
+ );
100
+
101
+ // Success if we got here
102
+ echo "w00t! \n\n";
103
+ echo "Job ID: ".$encoding_job->id."\n";
104
+ echo "Output ID: ".$encoding_job->outputs['web']->id."\n";
105
+ // Store Job/Output IDs to update their status when notified or to check their progress.
106
+ } catch (Services_Zencoder_Exception $e) {
107
+ // If were here, an error occured
108
+ echo "Fail :(\n\n";
109
+ echo "Errors:\n";
110
+ foreach ($e->getErrors() as $error) echo $error."\n";
111
+ echo "Full exception dump:\n\n";
112
+ print_r($e);
113
+ }
114
+
115
+ echo "\nAll Job Attributes:\n";
116
+ var_dump($encoding_job);
117
+
118
+ ?>
119
+ ```
104
120
105
121
### Step 3
122
+
106
123
Modify the above script to meet your needs.
124
+
107
125
Your [ API Request History] ( https://app.zencoder.com/api_requests ) may come in handy.
126
+
108
127
You can revisit your [ API builder] ( https://app.zencoder.com/api_builder ) to add/update parameters of the JSON.
109
128
110
129
You can translate the JSON string into nested associative arrays so that you can dynamically change attributes like "input".
111
130
The previous JSON example would become:
112
131
113
- $encoding_job = $zencoder->jobs->create(array(
114
- "input" => "s3://bucket-name/file-name.avi",
115
- "outputs" => array(
116
- array(
117
- "label" => "web"
118
- )
119
- )
120
- ));
132
+ ``` php
133
+ $encoding_job = $zencoder->jobs->create(array(
134
+ "input" => "s3://bucket-name/file-name.avi",
135
+ "outputs" => array(
136
+ array(
137
+ "label" => "web"
138
+ )
139
+ )
140
+ ));
141
+ ```
121
142
122
143
NOTIFICATION HANDLING
123
144
----------------------
145
+
124
146
The ZencoderOutputNotification class is used to capture and parse JSON data sent from
125
147
Zencoder to your app when an output file has been completed.
126
148
127
149
128
150
129
151
### Step 1
152
+
130
153
Create a script to receive notifications, and upload it to a location on your server that is publicly accessible.
131
154
132
155
#### Example
133
- <?php
134
156
135
- // Make sure this points to a copy of Zencoder.php on the same server as this script.
136
- require_once('Services/Zencoder.php');
157
+ ``` php
158
+ <?php
159
+
160
+ // Make sure this points to a copy of Zencoder.php on the same server as this script.
161
+ require_once('Services/Zencoder.php');
137
162
138
- // Initialize the Services_Zencoder class
139
- $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
163
+ // Initialize the Services_Zencoder class
164
+ $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
140
165
141
- // Catch notification
142
- $notification = $zencoder->notifications->parseIncoming();
166
+ // Catch notification
167
+ $notification = $zencoder->notifications->parseIncoming();
143
168
144
- // Check output/job state
145
- if($notification->job->outputs[0]->state == "finished") {
146
- echo "w00t!\n";
169
+ // Check output/job state
170
+ if($notification->job->outputs[0]->state == "finished") {
171
+ echo "w00t!\n";
147
172
148
- // If you're encoding to multiple outputs and only care when all of the outputs are finished
149
- // you can check if the entire job is finished.
150
- if($notification->job->state == "finished") {
151
- echo "Dubble w00t!";
152
- }
153
- } elseif ($notification->job->outputs[0]->state == "cancelled") {
154
- echo "Cancelled!\n";
155
- } else {
156
- echo "Fail!\n";
157
- echo $notification->job->outputs[0]->error_message."\n";
158
- echo $notification->job->outputs[0]->error_link;
159
- }
173
+ // If you're encoding to multiple outputs and only care when all of the outputs are finished
174
+ // you can check if the entire job is finished.
175
+ if($notification->job->state == "finished") {
176
+ echo "Dubble w00t!";
177
+ }
178
+ } elseif ($notification->job->outputs[0]->state == "cancelled") {
179
+ echo "Cancelled!\n";
180
+ } else {
181
+ echo "Fail!\n";
182
+ echo $notification->job->outputs[0]->error_message."\n";
183
+ echo $notification->job->outputs[0]->error_link;
184
+ }
160
185
161
- ?>
186
+ ?>
187
+ ```
162
188
163
189
### Step 2
190
+
164
191
In the parameters for an encoding job, add the URL for your script to the notifications array of each output you want to be notified for.
165
192
Then submit the job to test if it works.
166
193
167
194
** You can view the results at:**
168
195
< https://app.zencoder.com/notifications >
169
196
170
197
#### Example
171
- ...
172
- "outputs" => array(
173
- array(
174
- "label" => "web",
175
- "notifications" => array("http://example.com.com/encoding/notification.php")
176
- ),
177
- array(
178
- "label" => "iPhone",
179
- "notifications" => array("http://example.com.com/encoding/notification.php")
180
- )
181
- )
182
- ...
183
198
199
+ ``` php
200
+ ...
201
+ "outputs" => array(
202
+ array(
203
+ "label" => "web",
204
+ "notifications" => array("http://example.com.com/encoding/notification.php")
205
+ ),
206
+ array(
207
+ "label" => "iPhone",
208
+ "notifications" => array("http://example.com.com/encoding/notification.php")
209
+ )
210
+ )
211
+ ...
212
+ ```
184
213
185
214
### Step 3
215
+
186
216
Modify the above script to meet your needs.
217
+
187
218
Your [ notifications page] ( https://app.zencoder.com/notifications ) will come in handy.
188
219
189
220
VERSIONS
190
221
---------
222
+
223
+ Version 2.2.0 - 2014-07-24 Removing the bundled CA chain to address expiring intermediate certificate
191
224
Version 2.1.1 - 2012-08-02 Fixing issue where jobs index call didn't return jobs as individual objects
192
225
Version 2.1.0 - 2012-06-05 Adding support for job-level notifications & merging output with job in notification object
193
226
Version 2.0.2 - 2012-01-11 Fixed job creation response object, added documentation to variables
0 commit comments