PHP client library

Installation

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 dependancies by executing composer:


php composer.phar install

Usage

First, we will setup the notification and storage settings:

<?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'
    ]
  ];
  
  ?>

Creating a job

Creating complexe job is easy. In this example, we create 2 webp, 1 mp4 video and HLS outputs.

<?php

try {
  $job = $coconut->job->create([
  	'input' => ['url': 'https://mysite/path/file.mp4'],
    'outputs' => [
          'webp': [
        [
          'key': 'webp:cover',
          'path': '/cover_%05d.webp',
          'number': 10,
          'format' => [
            'resolution': '600x'
          ]
        ],
        [
          'key': 'webp:thumbs',
          'path': '/thumbs_%05d.webp',
          'interval': 10,
          'format' => [
            'resolution': '200x'
          ],
          'sprite' => [
            'limit': 100,
            'columns': 10
          ],
          'vtt' => [
            'filename': 'thumbs.vtt'
          ]
        ],
      ],
      'mp4': [
        [
          'key': 'mp4',
          'path': '/video.mp4',
          'format' => [
            'quality': 4
          ]
        ]
      ],
      'httpstream' => [
        'hls' => ['path': 'hls/']
      ]
    ]
  ]);
  print_r($job);

} cacth(Exception $e) {
  echo $e->getMessage();
}
?>