Ir para conteúdo
Fórum Script Brasil

Bellamy Clark

Membros
  • Total de itens

    2
  • Registro em

  • Última visita

Sobre Bellamy Clark

Bellamy Clark's Achievements

0

Reputação

  1. Estou tentando ler arquivos mp4 com o PHP, meu código inicial era $file = 'https://s3-sa-east-1.amazonaws.com/onlytestes/video.mp4'; header('Content-type: video/mp4'); readfile($file); Mas dessa forma não dava pra navegar na barra de duração do vídeo, pular e nem mesmo voltar, até que o vídeo esteja 100% carregado. Claro que quando leio diretamente o arquivo (video.mp4) tudo ocorre bem. Alguém tem alguma ideia?
  2. Estou tentando ler arquivos mp4 com o PHP, meu código inicial era $file = 'https://s3-sa-east-1.amazonaws.com/onlytestes/video.mp4'; header('Content-type: video/mp4'); readfile($file); Mas dessa forma não dava pra navegar na barra de duração do vídeo, pular e nem mesmo voltar, até que o vídeo esteja 100% carregado. Claro que quando leio diretamente o arquivo (video.mp4) tudo ocorre bem. Resolvi este problema com o seguinte código $request = 'video.mp4'; $file = $request; $fp = @fopen($file, 'rb'); $size = filesize($file); // File size $length = $size; // Content length $start = 0; // Start byte $end = $size - 1; // End byte header('Content-type: video/mp4'); 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'); } header("Content-Range: bytes $start-$end/$size"); header("Content-Length: ".$length); $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); exit(); porém, só da certo com arquivos local, acho que o HTTP_RANGE não funciona, retorna o seguinte erro no console Failed to load resource: the server responded with a status of 416 (Requested Range Not Satisfiable) eu preciso ler vídeos da Amazon S3, exemplo: https://s3-sa-east-1.amazonaws.com/onlytestes/video.mp4 alguém tem alguma ideia?
×
×
  • Criar Novo...