• Stars
    star
    110
  • Rank 315,796 (Top 7 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 14 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Zencoder integration library for PHP.

Zencoder API PHP Library

Company: Brightcove/Zencoder

Version: 2.2.4

Date: 2019-09-05

Repository: http://github.com/zencoder/zencoder-php/

HTTP headers are handled in a case-insensitve manner so that they are compatible with HTTP2.

Author: [Nathan Sutton] (nsutton (a) brightcove (.) c�om)

Company: Brightcove/Zencoder

Version: 2.2.3

Date: 2014-07-29

Repository: http://github.com/zencoder/zencoder-php/

To help address problems where users cannot modify php.ini to point cURL to their system CA bundle path, or are using a PHP release before 5.3.7, we have extended this library to allow users to set CURLOPT_CAPATH and CURLOPT_CAINFO on the cURL connection used to submit requests.

$zencoder = new Services_Zencoder($my_api_key, 'v2', 'https://app.zencoder.com', false, $my_curlopt_capath, $my_curlopt_cainfo);

See also the constructor for Services_Zencoder for more information on the available arguments.

See the cURL CA bundle extraction page for information on obtaining a CA bundle. We recommend using the HTTPS link to download the CA bundle.

Author: [Zac Shenker] (zshenker (a) brightcove (.) c�om)

Company: Brightcove/Zencoder

Version: 2.2.0

Date: 2014-07-24

Repository: http://github.com/zencoder/zencoder-php/

The Zencoder CA chain certificate has been removed from the library as the bundled cert will be expiring on July 26 2014, and should not be required as PHP/curl should be able to use the built in CA chain. Please contact us at [email protected] with an issues.

Author: [Michael Christopher] (mchristopher (a) brightcove (.) c�om)

Company: Zencoder - Online Video Encoder

Version: 2.1.1

Date: 2012-08-02

Repository: http://github.com/zencoder/zencoder-php/

Parts of this library are based on http://github.com/twilio/twilio-php

For more details on v2 of the Zencoder API visit http://blog.zencoder.com/2012/01/05/announcing-zencoder-api-v2/

For more details on the Zencoder API requirements visit https://support.brightcove.com/zencoder

To start working with the library, create a new instance of the Services_Zencoder class, passing your API Key as the 1st parameter.

$zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');

Once you have created the object, you can use it to interact with the API. For full information, see the Documentation folder, but here is a quick overview of some of the functions that can be called:

$zencoder->accounts->create($array);
$zencoder->jobs->create($array);
$zencoder->jobs->progress($job_id);
$zencoder->inputs->details($input_id);
$zencoder->outputs->details($output_id);
$zencoder->notifications->parseIncoming();

Any errors will throw a Services_Zencoder_Exception. You can call getErrors() on an exception and it will return any errors received from the Zencoder API.

ENCODING JOB

The ZencoderJob object creates an encoding job using cURL to send JSON formatted parameters to Zencoder's encoding API.

Step 1

Visit the API builder in your account, and execute a successful encoding job.

Step 2

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.

Example

<?php

// Make sure this points to a copy of Zencoder.php on the same server as this script.
require_once('Services/Zencoder.php');

try {
  // Initialize the Services_Zencoder class
  $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');

  // New Encoding Job
  $encoding_job = $zencoder->jobs->create(
    array(
      "input" => "s3://bucket-name/file-name.avi",
      "outputs" => array(
        array(
          "label" => "web"
        )
      )
    )
  );

  // Success if we got here
  echo "w00t! \n\n";
  echo "Job ID: ".$encoding_job->id."\n";
  echo "Output ID: ".$encoding_job->outputs['web']->id."\n";
  // Store Job/Output IDs to update their status when notified or to check their progress.
} catch (Services_Zencoder_Exception $e) {
  // If were here, an error occurred
  echo "Fail :(\n\n";
  echo "Errors:\n";
  foreach ($e->getErrors() as $error) echo $error."\n";
  echo "Full exception dump:\n\n";
  print_r($e);
}

echo "\nAll Job Attributes:\n";
var_dump($encoding_job);

?>

Step 3

Modify the above script to meet your needs.

Your API Request History may come in handy.

You can revisit your API 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 = $zencoder->jobs->create(array(
  "input" => "s3://bucket-name/file-name.avi",
  "outputs" => array(
    array(
      "label" => "web"
    )
  )
));

NOTIFICATION HANDLING

The ZencoderOutputNotification class is used to capture and parse JSON data sent from Zencoder to your app when an output file has been completed.

Step 1

Create a script to receive notifications, and upload it to a location on your server that is publicly accessible.

Example

<?php

// Make sure this points to a copy of Zencoder.php on the same server as this script.
require_once('Services/Zencoder.php');

// Initialize the Services_Zencoder class
$zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');

// Catch notification
$notification = $zencoder->notifications->parseIncoming();

// Check output/job state
if($notification->job->outputs[0]->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->job->outputs[0]->state == "cancelled") {
  echo "Cancelled!\n";
} else {
  echo "Fail!\n";
  echo $notification->job->outputs[0]->error_message."\n";
  echo $notification->job->outputs[0]->error_link;
}

?>

Step 2

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

Example

...
"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")
  )
)
...

Step 3

Modify the above script to meet your needs.

Your notifications page will come in handy.

VERSIONS

Version 2.2.4 - 2019-09-05    HTTP headers are handled in a case-insensitve manner so that they are compatible with HTTP2.
Version 2.2.3 - 2014-07-29    Fixed the versions listed in the user agent and throughout the code
Version 2.2.2 - 2014-07-29    Fixed a bug where api_key was set as api_version in the http connection options
Version 2.2.1 - 2014-07-29    Support setting CURLOPT_CAPATH and CURLOPT_CAINFO on cURL connections.
Version 2.2.0 - 2014-07-24    Removing the bundled CA chain to address expiring intermediate certificate
Version 2.1.1 - 2012-08-02    Fixing issue where jobs index call didn't return jobs as individual objects
Version 2.1.0 - 2012-06-05    Adding support for job-level notifications & merging output with job in notification object
Version 2.0.2 - 2012-01-11    Fixed job creation response object, added documentation to variables
Version 2.0.1 - 2012-01-10    Added ability to get error info from API
Version 2.0   - 2012-01-02    Complete refactoring of library
Version 1.6   - 2011-10-24    Fixed issue with user agents in cURL
Version 1.4   - 2011-10-06    Fixed error with adding api_key to URL
Version 1.3   - 2011-09-21    Fixed bundled SSL certification chain and made catch_and_parse() static
Version 1.2   - 2011-08-06    Added fixes for PHP Notices and SSL handling
Version 1.1   - 2010-06-04    Added General API Requests
Version 1.0   - 2010-04-02    Jobs and Notifications.

More Repositories

1

html5-boilerplate-for-wordpress

The HTML5 Boilerplate adapted into a WordPress template, including Bruce Lawson's HTML5 blog markup.
PHP
633
star
2

go-dash

A Go library for generating MPEG-DASH manifests.
Go
216
star
3

rvideo

Official home of the RVideo project, a Ruby gem for video and audio transcoding.
Ruby
121
star
4

zencoder-rb

Zencoder integration gem.
Ruby
105
star
5

zencoder-py

Zencoder integration library for Python
Python
63
star
6

disque-go

Go client for the Disque server
Go
47
star
7

video-js-for-wordpress

The VideoJS HTML5 video player library in plugin form for
JavaScript
40
star
8

zencoder-node

Node integration library for Zencoder
JavaScript
35
star
9

recurrent

Scheduled tasks.
Ruby
32
star
10

zencoder-fetcher

Notification retrieval.
Ruby
25
star
11

m3uzi

Read/write M3U8 files with (relative) ease.
Ruby
24
star
12

net-ntp

Read time from NTP
Ruby
23
star
13

gokay

Code generated struct validation tool for go.
Go
23
star
14

zenflow

Development workflow helper
Ruby
22
star
15

messenger

Send messages to email, http(s), sms, jabber, twitter, slack, and campfire.
Ruby
18
star
16

go-remote-config

A Go library for configuration management with JSON files in remote storage.
Go
14
star
17

VideoBooth

Simple app to record a user's webcam and transcode it through Zencoder. http://videobooth.herokuapp.com/
JavaScript
14
star
18

index-tanked

Ruby
13
star
19

zencoder-java

Zencoder Java client library
Java
10
star
20

go-smile

A Golang implementation of the Jackson-Smile data format
Go
9
star
21

locker

A locking mechanism for limiting the concurrency of ruby code using the database
Ruby
9
star
22

redis-queue

A Go implementation of a FIFO queue backed by Redis
Go
7
star
23

zpv

Stick that in your pipe and view it.
C
7
star
24

filepicker-zencoder

JavaScript
7
star
25

zencoder-dotnet

Zencoder integration app for .NET.
C#
6
star
26

ceiling-cat

...is watching you.
Ruby
6
star
27

contribflow

Contribflow is a suite of high-level repository operations for making open source contributions easier.
JavaScript
5
star
28

zencoder-ex

Elixir integration library for Zencoder
Elixir
4
star
29

fastly-tokens

Generate tokens for securing content distributed with the Fastly CDN
Go
3
star
30

zensockets

Repository for demo code on building an app around Zencoder.
JavaScript
3
star
31

zencoder-cli

Zencoder CLI
Ruby
3
star
32

demos

All the demos, all the time
JavaScript
2
star
33

go-fastly-purge

Go
2
star
34

dropwizard-s3-config

Dropwizard provider to retrieve application configuration from an S3 URI
Java
2
star
35

cloudharmony-benchmark

Cloud Harmony benchmark test harness
PHP
2
star