Php Recording a Live streaming to a file

折月煮酒 提交于 2019-12-05 06:29:00

问题


Hi i have a live streaming code and i stream my web cam on the local host.

Here is my stream file code

<?php

function flush_buffers(){
    ob_end_flush();
    ob_flush();
    flush();
    ob_start();
}


header('Content-Type: video/mpeg');
$stream = fopen( 'http://localhost:8080/stream.mp2v', "rb" );
#$save = fopen("save.mp4", "w");
while ( ! feof( $stream ) )
{

    $response = fread( $stream, 8192 ); 
    echo $response;
    #fwrite($save,$stream);
    flush_buffers();
}

fclose( $stream );
fclose($save);
exit();

What I need to do is record this live streaming simultaneously to a file here i stated save.mp4 in my code.I tried to do that with fwrite but when i run the program with this code i could see my webcam running but it could not record anything to save.mp4.I dont think fwrite is a suitable function for my purpose.I need help in this point.What should i do?


回答1:


I should have written fwrite($save,$response); instead of fwrite($save,$stream);. It worked in this way.




回答2:


I think you have to use another technology than PHP to do what exactly you want. But if you want to use PHP , i think you can save stream in a file and after convert it with a convertion software . :)



来源:https://stackoverflow.com/questions/32459509/php-recording-a-live-streaming-to-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!