I have a 4GB .mp4 video I need to allow authenticated users to stream.
I have the video in a directory which is secured via .htaccess like this:
Deny from all
When a user requests access to the video, I use a PHP script to check for authentication, then send the video like this:
<?php
header('Content-Type: video/mp4');
header('Content-Disposition: inline; filename="' . $video . '.mp4"');
header('Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
ob_clean();
$wasdownloaded = readfile('video/' . $video . '.mp4');
if ($wasdownloaded===true){
Flush();
}
?>
I am using Floatbox.js which has built-in (and simple) capability to stream video. I am not tied to using that, though.
I am finding that I can stream 1-3 minutes of the video before it times out, even on a good connection. I would think there are a couple of potential bottlenecks, and not sure where to start:
- Is the "readfile" technique in PHP able to handle a 4GB video? It definitely works to start, but possibly it is too much for the server to handle, especially if the video is placed in memory as it is streaming?
- Do I need a more sophisticated streaming software platform? Floatbox.js works nicely for small videos or YouTube embeds, but it is not designed primarily for video streaming.
- Do I need to look to an outside provider (Vimeo, etc.) to handle streaming, compression, etc.? The issue here is that I don't know if I can authenticate the users as easily, or at all.