Hi! We have the following interesting scenario, has anyone done that before?

We have a live camera stream to serve, that we need to convert and must be 
used on html5 video tag. Since html5 does not work with udp for multicast 
use, we need to use the same ffmpeg converted stream to more that one 
client (response), to avoid creating multiple instances of ffmpeg to the 
same source camera.

But it seems that the stream cannot be piped to more than 1 response. First 
one gets the stream alright, but the second one does not.

We are storing the converted stream (stdout) in an array (one stdout for 
each source camera) but it does not pipe to a second client response.

Any ideas of how to do that?

Thanks!

Here is the code:

var request = require('request');var http = require('http');var child_process = 
require("child_process");var n = 1;var stdouts = {};

http.createServer(function (req, resp) {

console.log("***** url ["+req.url+"], call "+n);
if (req.url != "/favicon.ico" && req.url != "/"){var params = 
req.url.substring(1).split("/");
switch (params[0]){
  case "VIEW":
    if (params[1] == "C2FLOOR1" || params[1] == "C2FLOOR2" || params[1] == 
"C2PORFUN" || params[1] == "C2TESTCAM")
      var camera = 
"rtsp://192.168.16.19:554/Inter/Cameras/Stream?Camera="+params[1];
    else
      var camera = 
"http://192.168.16.19:8609/Inter/Cameras/GetStream?Camera="+params[1];

    // Write header
    resp.writeHead(200, {'Content-Type': 'video/ogg', 'Connection': 
'keep-alive'});

    if (stdouts.hasOwnProperty(params[1]))
    {
      console.log("Getting stream already created for camera "+params[1]);

      var newStdout = Object.create(stdouts[params[1]]);

      newStdout.pipe(resp);
    }
    else
    {
        // Start ffmpeg
        var ffmpeg = child_process.spawn("ffmpeg",[
        "-i",camera,
        "-vcodec","libtheora",
        "-qscale:v","7",        // video quality
        "-f","ogg",             // File format
        "-g","1",               // GOP (Group Of Pictures) size
        "-"                     // Output to STDOUT
        ]);

        stdouts[params[1]] = ffmpeg.stdout;

        // Pipe the video output to the client response
        ffmpeg.stdout.pipe(resp);

    console.log("Initializing camera at "+camera);
    }

    // Kill the subprocesses when client disconnects/*
    resp.on("close",function(){
      ffmpegs[params[1]].kill();
      console.log("FIM!");
    });
*/
    break;}}else{
resp.writeHeader(200, {"Content-Type": "text/html"});
resp.write("WRONG CALL");
resp.end();}
n++;
}).listen(8088);

console.log('Server running at port 8088');

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to