2
votes

I have been struggling to get live streaming working from FFMPEG for many hours so raising the white flag and asking for help here.

My scenario is I have an IP security camera that I can successfully connect via RTSP (h.264) and save the video as file segments, and they play back fine either through a standalone app like VLC or via a node.js web server app that sends the 'video/mp4' & keep-alive header and streams the mp4 files previously saved by FFMPEG to a HTML5 video client.

However I want to take the same RTSP stream and re-stream it live to a HTML5 client. I know the HTML5 client bits and the FFMPEG remuxing to MP4 work as the MP4 recording/streaming works.

I have tried the following:

1) Set the output as a HTTP string. I don't think FFMPEG supports this as I get 'input/output error' and the FFMPEG documentation talks about another app called FFSERVER which isn't supported on Windows

ffmpeg -i rtsp://admin:[email protected]:554 -vcodec copy -f mp4 -movflags frag_keyframe+empty_moov http://127.0.0.1:8888

2) As ffmpeg runs as a spawn in node.js, I have tried piping the STDOUT to a node http server, using the same header I use for the recording playback stream. I can view this stream in VLC which is a good sign but I can't get the HTML client to recognize the stream and it shows blank, or occasionally a static image of the stream.

var liveServer = http.createServer(liveStream); 
var liveStream = function (req, resp) {                                            // handle each client request by instantiating a new FFMPEG instance
    resp.writeHead(200, {"Content-Type": "video/mp4", "Connection": "keep-alive"});
        var xffmpeg = child_process.spawn("ffmpeg", [
            "-i", "rtsp://admin:[email protected]:554" , "-vcodec", "copy", "-f", "mp4", "-movflags", "frag_keyframe+empty_moov", "-"   // output to stdout
            ],  {detached: false});

            xffmpeg.stdout.pipe(resp);

            xffmpeg.on("exit", function (code) {
                 console.log("Xffmpeg terminated with code " + code);
            });

            xffmpeg.on("error", function (e) {
                  console.log("Xsystem error: " + e);
            });

            xffmpeg.stdout.on("data",function(data) {
                  console.log('Xdata rcv ' + data);
            });

            xffmpeg.stderr.on("data", function (data) {
                  console.log("XFFMPEG -> " + data);
    }
}

I have tried both IE11 and Chrome HTML5 clients.

I suspect there is something not quite right with the format of the stream being sent which stops the HTML5 video client but not enough to stop VLC. The irritating thing is that the code above works just fine for playing back MP4 streams that have been recorded.

Any ideas how to get live re-streaming via FFMPEG working? Thanks.

1

1 Answers

0
votes

Just curious have you solved it ? I'm doing basically the same thing except for it being screen cast.... I've switched to using webm format which plays perfectly...however the video will "lag" behind by an additional few seconds more... Which is bad for me, but might work for you