Ich streamen große (500 MB +) MP4-Dateien, mit einer Funktion gefunden here. Die Idee ist, die Videoquelle versteckt zu halten, und bis jetzt funktioniert es.Website reagiert nicht während des Streamen von mp4
Das einzige Problem ist, dass die Interaktion mit der Website (Klicken auf einen Link usw.) nicht möglich ist, bis das Video abgeschlossen ist - auch wenn Sie es anhalten. Außerdem müssen Sie den Tab und/oder Browser schließen, um auf die Website zu reagieren. Es scheint, dass es möglich ist, Anfragen in einem anderen Browser zu stellen, so dass ich weiß, dass der Server selbst nicht gesperrt ist.
Hier ist die Funktion:
$file = "/home/webtest/videos/720p/video.mp4"; // The media file's location
$fp = @fopen($file, 'rb');
$size = filesize($file); // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
$content_type = 'application/octet-stream'; // type
header('Content-Type: '.$content_type);
header("Accept-Ranges: 0-$length");
if (isset($_SERVER['HTTP_RANGE'])){
$c_start = $start;
$c_end = $end;
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-$end/$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 > $end) ? $end : $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 $start-$end/$size");
exit;
}
$start = $c_start;
$end = $c_end;
$length = $end - $start + 1;
fseek($fp, $start);
header('HTTP/1.1 206 Partial Content');
}
// Notify the client the byte range we'll be outputting
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: $length");
// Start buffered download
$buffer = 1024 * 8;
while(!feof($fp) && ($p = ftell($fp)) <= $end){
if ($p + $buffer > $end){
$buffer = $end - $p + 1;
}
set_time_limit(0);
echo fread($fp, $buffer);
flush();
}
fclose($fp);
Hier ist der Header:
HTTP/1.1 206 Partial Content
Date: Mon, 18 Apr 2016 23:36:59 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Accept-Ranges: 0-203395220
Content-Range: bytes 0-203395219/203395220
Content-Length: 203395220
Connection: close
Content-Type: video/mp4
Anfrageheaders
Accept:*/*
Accept-Encoding:identity;q=1, *;q=0
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:PHPSESSID=24mf06f150895og6s59b9nfte5
DNT:1
Host:
Range:bytes=0-
Referer:
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36
Wenn Sie denken, diese Methode nicht korrekt oder fehlerhaft ist, bin ich auf jeden Fall offen zu alternativen Methoden für das Streaming. Vielen Dank.
Dank - ich werde versuchen, dass – visevo
Leben. Sparer. Vielen Dank! – visevo