gpt4 book ai didi

php - 通过PHP流文件播放的AWS s3存储桶视频未播放音频

转载 作者:行者123 更新时间:2023-12-02 22:38:16 30 4
gpt4 key购买 nike

我已在AWS s3存储桶上上传了视频,并且s3存储桶的所有内容都是私有(private)的,现在我正在创建Cloudfront签名的URL并以PHP Stream的形式播放视频。

下面是代码,

        header('Content-Type: application/octetstream');
header('Content-Type: application/octet-stream');
header('Content-Type: ' . $audio_content);
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="' . $file_name . '"');
header('Content-Length: ' . $size);
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Accept-Ranges: bytes');
header('Content-Transfer-Encoding: binary');

// In case the file was streaming browser may request file in between
// for seeking file in middle, where audio file was not downloaded completely
// In such cases we send the proper content-range in bytes

if (isset($_SERVER['HTTP_RANGE']) && false)
{

if (preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches))
{

$begin = (int) $matches[1];

if ( ! empty($matches[2]))
{
$ending = (int) $matches[2];
}
}
header('HTTP/1.1 206 Partial Content');


}

if (isset($_SERVER['HTTP_RANGE'])) {

$c_start = $begin;
$c_end = $ending;
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
if (strpos($range, ',') !== false) {
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes $start-$ending/$size");
exit;
}
if ($range == '-') {
$c_start = $size - substr($range, 1);
}else{
$range = explode('-', $range);
$c_start = $range[0];
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
}
$c_end = ($c_end > $ending) ? $ending : $c_end;
if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes $begin-$end/$size");
exit;
}
$begin = $c_start;
$ending = $c_end;
$length = $ending - $begin + 1;

fseek($file_pointer, $begin);
header('HTTP/1.1 206 Partial Content');
}
$intLength = $ending - ($begin + 1);
header('Content-Range: bytes ' . $begin . '-' . $ending . '/' . $size);
header('Content-Length: ' . $intLength);
// Stream the file
$file_pointer = fopen('php://output', 'w');

// If we had downloaded file incase where we did not get content length
// send that file directly instead of fresh new cURL request
$curl = curl_init($signedUrlCustomPolicy);
curl_setopt($curl, CURLOPT_FILE, $file_pointer);
curl_setopt($curl, CURLOPT_RANGE, $begin . '-' . $ending);
curl_exec($curl);
//fwrite($file_pointer, $resultData);
curl_close($curl);

问题是Mac Safari和iPhone Safari中没有播放音频

最佳答案

使用AWS PHP SDK获取签名的URL,然后在音频播放器中使用它。
对于true streaming,您需要使用MediaConvert将音频转换为.m3u8和.ts。
或者使用https://S3MediaVault.com这样的插件

关于php - 通过PHP流文件播放的AWS s3存储桶视频未播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39616071/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com