@@ -2,9 +2,13 @@ Zencoder API PHP Library
22==========================
33
44Author:[ Zac Shenker] (zshenker (a) brightcove (.) c ; om)
5+
56Company:[ Brightcove/Zencoder] ( http://www.zencoder.com )
7+
68Version: 2.2.0
9+
710Date: 2014-07-24
11+
812Repository:< http://github.com/zencoder/zencoder-php/ >
913
1014The 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.
1317
1418
1519Author:[ Michael Christopher] (mchristopher (a) brightcove (.) c ; om)
20+
1621Company:[ Zencoder - Online Video Encoder] ( http://www.zencoder.com )
22+
1723Version: 2.1.1
24+
1825Date: 2012-08-02
26+
1927Repository:< http://github.com/zencoder/zencoder-php/ >
2028
2129Parts 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
2937To start working with the library, create a new instance of the Services_Zencoder class, passing
3038your API Key as the 1st parameter.
3139
32- $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
40+ ``` php
41+ $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
42+ ```
3343
3444Once you have created the object, you can use it to interact with the API. For full information,
3545see the Documentation folder, but here is a quick overview of some of the functions that can be
3646called:
3747
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+ ```
4456
4557Any errors will throw a Services_Zencoder_Exception. You can call getErrors() on an exception
4658and it will return any errors received from the Zencoder API.
4759
4860
4961ENCODING JOB
5062------------
63+
5164The ZencoderJob object creates an encoding job using[ cURL] ( http://zencoder.com/docs/glossary/curl/ )
5265to send[ JSON] ( http://zencoder.com/docs/glossary/json/ ) formatted parameters to Zencoder's encoding API.
5366
5467###Step 1
68+
5569Visit the[ API builder] ( https://app.zencoder.com/api_builder ) in your account,
5670and execute a successful encoding job.
5771
5872###Step 2
73+
5974Copy the successful JSON string, starting with the first curly brace "{",
6075and pass it as the parameters for a new ZencoderJob object. Execute the script on your server to test that it works.
6176
6277####Example
63- <pre>
64- <?php
6578
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');
6884
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');
7288
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(
7594 array(
76- "input" => "s3://bucket-name/file-name.avi",
77- "outputs" => array(
78- array(
79- "label" => "web"
80- )
81- )
95+ "label" => "web"
8296 )
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+ ```
104120
105121###Step 3
122+
106123Modify the above script to meet your needs.
124+
107125Your[ API Request History] ( https://app.zencoder.com/api_requests ) may come in handy.
126+
108127You can revisit your[ API builder] ( https://app.zencoder.com/api_builder ) to add/update parameters of the JSON.
109128
110129You can translate the JSON string into nested associative arrays so that you can dynamically change attributes like "input".
111130The previous JSON example would become:
112131
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+ ```
121142
122143NOTIFICATION HANDLING
123144----------------------
145+
124146The ZencoderOutputNotification class is used to capture and parse JSON data sent from
125147Zencoder to your app when an output file has been completed.
126148
127149
128150
129151###Step 1
152+
130153Create a script to receive notifications, and upload it to a location on your server that is publicly accessible.
131154
132155####Example
133- <?php
134156
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');
137162
138- // Initialize the Services_Zencoder class
139- $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
163+ // Initialize the Services_Zencoder class
164+ $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
140165
141- // Catch notification
142- $notification = $zencoder->notifications->parseIncoming();
166+ // Catch notification
167+ $notification = $zencoder->notifications->parseIncoming();
143168
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";
147172
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+ }
160185
161- ?>
186+ ?>
187+ ```
162188
163189###Step 2
190+
164191In 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.
165192Then submit the job to test if it works.
166193
167194** You can view the results at:**
168195< https://app.zencoder.com/notifications >
169196
170197####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- ...
183198
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+ ```
184213
185214###Step 3
215+
186216Modify the above script to meet your needs.
217+
187218Your[ notifications page] ( https://app.zencoder.com/notifications ) will come in handy.
188219
189220VERSIONS
190221---------
222+
223+ Version 2.2.0 - 2014-07-24 Removing the bundled CA chain to address expiring intermediate certificate
191224Version 2.1.1 - 2012-08-02 Fixing issue where jobs index call didn't return jobs as individual objects
192225Version 2.1.0 - 2012-06-05 Adding support for job-level notifications & merging output with job in notification object
193226Version 2.0.2 - 2012-01-11 Fixed job creation response object, added documentation to variables