The Coconut PHP library provides access to the Coconut API for encoding videos, packaging media files into HLS and MPEG-Dash, generating thumbnails and GIF animation.
This library is only compatible with the Coconut API v2.
See the full documentation.
To install the Coconut PHP library, you need composer first:
curl -sS https://getcomposer.org/installer | php
Edit composer.json
:
{
"require": {
"opencoconut/coconut": "3.*"
}
}
Install the depencies by executing composer
:
php composer.phar install
The library needs you to set your API key which can be found in your dashboard. Webhook URL and storage settings are optional but are very convenient because you set them only once.
<?php
require_once('vendor/autoload.php');
$coconut = new Coconut\Client('k-api-key');
$coconut->notification = [
'type' => 'http',
'url' => 'https://yoursite/api/coconut/webhook'
];
$coconut->storage = [
'service' => 's3',
'bucket' => 'my-bucket',
'region' => 'us-east-1',
'credentials' => [
'access_key_id' => 'access-key',
'secret_access_key' => 'secret-key'
]
];
?>
<?php
try {
$job = $coconut->job->create([
'input' => [ 'url' => 'https://mysite/path/file.mp4' ],
'outputs' => [
'jpg:300x' => [ 'path' => '/image.jpg' ],
'mp4:1080p' => [ 'path' => '/1080p.mp4' ],
'httpstream' => [
'hls' => [ 'path' => 'hls/' ]
]
]
]);
print_r($job);
} cacth(Exception $e) {
echo $e->getMessage();
}
?>
$job = $coconut->job->retrieve('OolQXaiU86NFki');
$metadata = $coconut->metadata->retrieve('OolQXaiU86NFki');
Released under the MIT license.