Encode a video

POST /api/transcode queues an H.264 HLS ladder. Send the API key as a Bearer token from your server. source_path is a key in the bucket stored on that API key. A 202 response includes job_id.

<?php

$apiKey = getenv('CC_ENCODE_API_KEY');
if ($apiKey === false || $apiKey === '') {
    throw new RuntimeException('CC_ENCODE_API_KEY is not set');
}

$payload = json_encode([
    'source_path' => 'videos/source.mp4',
    'qualities' => ['1080p', '720p', '480p'],
    'webhook_url' => 'https://yourapp.com/webhooks/transcode',
], JSON_THROW_ON_ERROR);

$ch = curl_init('https://services.closedcircuit.io/api/transcode');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer '.$apiKey,
        'Content-Type: application/json',
        'Accept: application/json',
    ],
    CURLOPT_POSTFIELDS => $payload,
]);

$body = curl_exec($ch);
if ($body === false) {
    throw new RuntimeException(curl_error($ch));
}

$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$job = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
// $status is 202. $job['job_id'] is the encode.

Read the job with GET /api/transcode/{job_id} and the same token. status is completed when the ladder is in the bucket. Omit webhook_url if you will poll. Product page: CC Encode.