PHP code example of innoboxrr / video-processor
1. Go to this page and download the library: Download innoboxrr/video-processor library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
innoboxrr / video-processor example snippets
'cloudfront' => [
'domain' => env('CLOUDFRONT_DOMAIN'),
'public_key_id' => env('CLOUDFRONT_PUBLIC_KEY_ID'),
'private_key_path' => base_path(env('CLOUDFRONT_PRIVATE_KEY_PATH')),
'url_expiration' => env('CLOUDFRONT_URL_EXPIRATION', 240),
],
use Carbon\Carbon;
class ModernCloudFrontService
{
public function generateSignedUrl(string $resourceUrl): string
{
$expires = Carbon::now()->addMinutes(config('videoprocessor.cloudfront.url_expiration'))->timestamp;
$policy = json_encode([
'Statement' => [[
'Resource' => $resourceUrl,
'Condition' => [
'DateLessThan' => ['AWS:EpochTime' => $expires],
],
]],
]);
$privateKey = file_get_contents(config('videoprocessor.cloudfront.private_key_path'));
openssl_sign($policy, $signature, $privateKey, OPENSSL_ALGO_SHA1);
$encodedPolicy = strtr(base64_encode($policy), ['+' => '-', '=' => '_', '/' => '~']);
$encodedSignature = strtr(base64_encode($signature), ['+' => '-', '=' => '_', '/' => '~']);
return $resourceUrl
. '?Policy=' . $encodedPolicy
. '&Signature=' . $encodedSignature
. '&Key-Pair-Id=' . config('videoprocessor.cloudfront.public_key_id');
}
}
$service = new ModernCloudFrontService();
$url = $service->generateSignedUrl('https://tudistribucion.cloudfront.net/path/to/video/index.m3u8');
return redirect()->away($url);
CLOUDFRONT_DOMAIN=https://tudistribucion.cloudfront.net
CLOUDFRONT_PUBLIC_KEY_ID=K123ABC456XYZ
CLOUDFRONT_PRIVATE_KEY_PATH=storage/cloudfront/private_key.pem
CLOUDFRONT_URL_EXPIRATION=240