For outputting a big video (duration 20m46s, size 1.34 GB),
I use the following code (file video.php):
<?php
define('CHUNK_SIZE', 1024*1024); // Size (in bytes) of tiles chunk
// Read a file and display its content chunk by chunk
function readfile_chunked($filename, $retbytes = TRUE) {
$buffer = '';
$cnt = 0;
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, CHUNK_SIZE);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}
$filename = 'video.mp4';
$mimetype = 'video/mp4';
header('Content-Type: '.$mimetype );
readfile_chunked($filename);
?>
The video is watched in a HTML page with the following code:
<video controls>
<source src='video.php' type='video/mp4'>
</video>
However, seeking in the video doesn’t work correctly.
For example, if I move the play cursor for seeking to the 18:00 timestamp, it will
instead seek to the 0:58 timestamp.
How can I solve this?