duangai2831 2018-10-12 15:48
浏览 30

允许使用PHP将大型视频文件传输给经过身份验证的用户

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.
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探