I am trying to play a long video (4gb+) using an 8 MB chunk but it is not working. everything looks good with video until 2 GB size but getting problem for very large video size. Is anything I will need to optimize at PHP, Apache side, or anything needed to update in following script to support very large video?
<?php
require 'awss3/vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
$objectkey = '<VIDEO>.mp4';
$buffer = '';
$bucketname = '<BUCKETNAME>';
$key = '<KEY>';
$secret = '<SECRET_KEY>';
$region = '<REGION>';
$s3 = new S3Client([
'region' => $region,
'version' => 'latest',
'credentials' => [
'key' => $key,
'secret' => $secret,
]
]);
$s3->registerStreamWrapper();
$context = stream_context_create(array(
's3' => array(
'seekable' => true
)
));
// get the file's mime type to send the correct content type header
$path = "s3://$bucketname/$objectkey";
header('HTTP/1.0 200 OK');
header("Content-Type: video/mp4");
header('Accept-Ranges: bytes');
$options = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
$context = stream_context_create($options);
$handle = fopen($path, 'rb', false, $context);
$chunkSize = 1024 * 1024 * 8;
$buffer = '';
ob_start();
while (!feof($handle)) {
$buffer = fread($handle, $chunkSize);
echo $buffer;
ob_flush();
flush();
}
fclose($handle);
exit;