fix ffmpeg

This commit is contained in:
Francesco Picone
2025-12-09 16:58:11 +01:00
parent e7ea7dbd3b
commit 59c9b1f5be
11 changed files with 476 additions and 57 deletions

View File

@@ -86,18 +86,25 @@ if (isset($_SERVER['HTTP_RANGE'])) {
}
$length = $end - $start + 1;
http_response_code(206); // Partial Content
header("Content-Range: bytes $start-$end/$file_size");
} else {
http_response_code(200);
}
} else {
http_response_code(200);
}
// Pulisci output buffer per evitare corruzione
if (ob_get_level()) {
ob_end_clean();
}
// Invia header
header("Content-Type: $mime_type");
header("Accept-Ranges: bytes");
header("Content-Length: $length");
header("Content-Range: bytes $start-$end/$file_size");
// Header per impedire il download e la cache aggressiva
// Header per impedire il download
header("Content-Disposition: inline; filename=\"video.{$extension}\"");
header("X-Content-Type-Options: nosniff");
@@ -105,16 +112,37 @@ header("X-Content-Type-Options: nosniff");
header("Cache-Control: public, max-age=3600");
header("Pragma: public");
// Disabilita compressione per lo streaming
header("Content-Encoding: none");
// Apri e leggi il file
$fp = fopen($file, 'rb');
if ($fp === false) {
http_response_code(500);
exit('Impossibile aprire il file video');
}
fseek($fp, $start);
$buffer = 1024 * 8; // 8KB buffer
while (!feof($fp) && ($pos = ftell($fp)) <= $end) {
if ($pos + $buffer > $end) {
$buffer = $end - $pos + 1;
// Buffer più grande per migliore performance
$buffer = 1024 * 256; // 256KB buffer
$bytes_sent = 0;
while (!feof($fp) && ($bytes_sent < $length) && connection_status() == 0) {
$bytes_to_read = min($buffer, $length - $bytes_sent);
$data = fread($fp, $bytes_to_read);
if ($data === false) {
break;
}
echo $data;
$bytes_sent += strlen($data);
// Forza l'invio dei dati al browser
if (ob_get_level() > 0) {
ob_flush();
}
echo fread($fp, $buffer);
flush();
}