- Notifications
You must be signed in to change notification settings - Fork43
Zencoder integration library for PHP.
License
zencoder/zencoder-php
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Author:Steve Heffernan (steve (a) zencoder (.) c�om)Company:Zencoder - Online Video Encoder
Version: 1.3Date: 2011-09-21Repository:http://github.com/zencoder/zencoder-php/
For more details on the Zencoder API requirements visit
http://zencoder.com/docs/api
The ZencoderJob object creates an encoding job usingcURLto sendJSON formatted parameters to Zencoder's encoding API.
Visit theAPI builder in your account,and execute a successful encoding job.
Copy the successful JSON string, starting with the first curly brace "{",and pass it as the parameters for a new ZencoderJob object. Execute the script on your server to test that it works.
<pre><?php// Make sure this points to a copy of Zencoder.php on the same server as this script.require_once("zencoder-php/Zencoder.php");// New Encoding Job$encoding_job = new ZencoderJob(' { "api_key": "93h630j1dsyshjef620qlkavnmzui3", "input": "s3://bucket-name/file-name.avi", "outputs": [ { "label": "web" } ] }');// Check if it workedif ($encoding_job->created) { // Success echo "w00t! \n\n"; echo "Job ID: ".$encoding_job->id."\n"; echo "Output '".$encoding_job->outputs["web"]->label."' ID: ".$encoding_job->outputs["web"]->id."\n"; // Store Job/Output IDs to update their status when notified or to check their progress.} else { // Failed echo "Fail :(\n\n"; echo "Errors:\n"; foreach($encoding_job->errors as $error) { echo $error."\n"; }}echo "\nAll Job Attributes:\n";var_dump($encoding_job);?></pre>
Modify the above script to meet your needs.
YourAPI Request History may come in handy.
You can revisit yourAPI builder to add/update parameters of the JSON.
You can translate the JSON string into nested associative arrays so that you can dynamically change attributes like "input".
The previous JSON example would become:
$encoding_job = new ZencoderJob(array( "api_key" => "93h630j1dsyshjef620qlkavnmzui3", "input" => "s3://bucket-name/file-name.avi", "outputs" => array( array( "label" => "web" ) )));
A general API request can be used for all API functionality includingJob Listing,Job Details,Account Creation,Account Details (even Job Creation if desired). See theAPI docs for all possible API requests.The first argument is theAPI URL.
The second argument is yourAPI Key.
The third argument is therequest parameters if needed. It can either be a JSON string or an array of parameters.
$request = new ZencoderRequest( 'https://app.zencoder.com/api/jobs', '93h630j1dsyshjef620qlkavnmzui3');if ($request->successful) { print_r($request->results);} else { foreach($request->errors as $error) { echo $error."\n"; }}
$request = new ZencoderRequest( 'https://app.zencoder.com/api/account', false, // API key isn't needed for new account creation array( "terms_of_service" => "1", "email" => "test@example.com", "password" => "1234" ));if ($request->successful) { print_r($request->results);} else { foreach($request->errors as $error) { echo $error."\n"; }}
The ZencoderOutputNotification class is used to capture and parse JSON data sent fromZencoder to your app when an output file has been completed.
Create a script to receive notifications, and upload it to a location on your server that is publicly accessible.
<?php// Make sure this points to a copy of Zencoder.php on the same server as this script.require("Zencoder.php");// Catch notification$notification = ZencoderOutputNotification::catch_and_parse();// Check output/job stateif($notification->output->state == "finished") { echo "w00t!\n"; // If you're encoding to multiple outputs and only care when all of the outputs are finished // you can check if the entire job is finished. if($notification->job->state == "finished") { echo "Dubble w00t!"; }} elseif ($notification->output->state == "cancelled") { echo "Cancelled!\n";} else { echo "Fail!\n"; echo $notification->output->error_message."\n"; echo $notification->output->error_link;}?>
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.Then submit the job to test if it works.
You can view the results at:
https://app.zencoder.com/notifications
..."outputs" => array( array( "label" => "web", "notifications" => array("http://example.com.com/encoding/notification.php") ), array( "label" => "iPhone", "notifications" => array("http://example.com.com/encoding/notification.php") ))...
Modify the above script to meet your needs.
Yournotifications page will come in handy.
Version 1.6 - 2011-10-24 Fixed issue with user agents in cURLVersion 1.4 - 2011-10-06 Fixed error with adding api_key to URLVersion 1.3 - 2011-09-21 Fixed bundled SSL certification chain and made catch_and_parse() staticVersion 1.2 - 2011-08-06 Added fixes for PHP Notices and SSL handlingVersion 1.1 - 2010-06-04 Added General API RequestsVersion 1.0 - 2010-04-02 Jobs and Notifications.
About
Zencoder integration library for PHP.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.