【问题标题】:PHP Streaming video handlerPHP 流式视频处理程序
【发布时间】:2011-12-06 14:22:29
【问题描述】:

我正在尝试实现基于用户访问的视频流解决方案。

我有许多视频流位于连接到服务器 (http//192.168.100.101/mpeg4/1/media.amp) 的专用网络上,我想通过网络服务器“代理”该视频流。

我知道如何设置用户访问部分,但是如何将视频流代理给用户?

我尝试过类似的方法,但它似乎不起作用。

header('Content-type: application/x-rtsp-tunnelled');
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, "http//192.168.100.101/mpeg4/1/media.amp");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
echo $output;
curl_close($ch);

关于最佳方式的任何想法?其他流媒体网站是如何做到的?

谢谢:)

【问题讨论】:

    标签: php curl streaming video-streaming


    【解决方案1】:

    是的,这很容易做到。无需手动设置这些标题。让服务器自动完成。

    这是我为视频流代理编写的工作脚本 -

    ini_set('memory_limit','1024M');
    
    set_time_limit(3600);
    
    ob_start();
    
    **// do any user checks here - authentication / ip restriction / max downloads / whatever**
    
    **// if check fails, return back error message**
    
    **// if check succeeds, proceed with code below**
    
    if( isset($_SERVER['HTTP_RANGE']) )
    
    $opts['http']['header']="Range: ".$_SERVER['HTTP_RANGE'];
    
    $opts['http']['method']= "HEAD";
    
    $conh=stream_context_create($opts);
    
    $opts['http']['method']= "GET";
    
    $cong= stream_context_create($opts);
    
    $out[]= file_get_contents($real_file_location_path_or_url,false,$conh);
    
    $out[]= $http_response_header;
    
    ob_end_clean();
    
    array_map("header",$http_response_header);
    
    readfile($real_file_location_path_or_url,false,$cong);
    

    【讨论】:

    • 伙计,你刚刚为我节省了很多时间 :) 在 php 5.1 和 5.6 上进行了测试,具有魅力
    【解决方案2】:

    curl_exec() 不是为流输出而设计的。只有当 http 请求完成时才会返回。对于流式传输请求,理论上这将是“从不”,您只会在某处填充内存缓冲区。

    查看此答案以了解解决方法:Manipulate a string that is 30 million characters long

    【讨论】:

      【解决方案3】:

      试试这个页面中的解决方案:Streaming POST data through PHP cURL 我会自己尝试看看它是否有效,但我想在我分心并忘记这个问题之前将其发布在这里 :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多