mp4をrangeリクエストをして、細切れにもらえる。
videoタグは、rangeリクエストを勝手にしくれるらしい。
リクエストヘッダに、 Range: bytes=18832832-
とういのがついている。
188xxx移行全部くださいということらしい。
下記PHPでは、全部と言われても1000しか上げないので、
結局大変細かいやり取りが続き、ローカルで試してもいっこうに再生が始まらなかった。
下記の部分は、参考サイトのように、1000000bytes(1MB)とかにしないといけない。
if (empty($end)) $end = $start + 1000 - 1;
index.html
<html> <head> <tiltle>PHP MP4 PROGRESSIVE</tiltle> </head> <body> <h1>PHP MP4 PROGRESSIVE</h1> <video controls> <source src="http://localhost:8001/php-mp4-progressive/mp4.php" type="video/mp4"> <p>Sorry...</p> </video> </body> </html>
mp4.php
<?php $file = './sample.mp4'; $size = filesize($file); $fp = fopen($file, 'rb'); if ($_SERVER['HTTP_RANGE']) { [$start, $end] = sscanf($_SERVER['HTTP_RANGE'], 'bytes=%d-%d'); if (empty($end)) $end = $start + 1000 - 1; if ($end >= ($size - 1)) $end = $size - 1; header('HTTP/1.1 206 Partial Content'); header("Content-Range: bytes {$start}-{$end}/{$size}"); $size = $end - $start + 1; fseek($fp, $start); } header('Accept-Ranges: bytes'); header('Content-Type: video/mp4'); header("Content-Length: {$size}"); if ($size) echo fread($fp, $size); fclose($fp);
参考サイトの真似ですがとりあえず出来ました。
参考: