Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php Recording a Live streaming to a file

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?

like image 695
0qo Avatar asked Sep 08 '15 13:09

0qo


People also ask

How can I record my entire stream?

Select Create > Record screen from your navigation bar in Stream. If needed for your recording, make sure your device's camera and microphone are enabled. Select to start recording. You'll then be prompted to choose what you want to record: your entire screen, an application window, or browser tab.

Can a live feed be recorded?

There are several ways to record a live stream. You can do it through an encoder, an online video player, or through a dedicated screen-capture tool. Let's take a look at how to record live streaming videos with each of these methods.


1 Answers

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

like image 163
0qo Avatar answered Oct 10 '22 22:10

0qo