Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert RTSP stream to MP4

I have a IP Camera that supports RTSP, and I need to display this stream to multiple clients using HTML5.

Since HTML Video tag doesn't support RTSP, I'm calling ffmpeg to encode it to a WEBM stream, but the result is very glitchy and distorts the original stream.

The command im using is the following: ffmpeg -i my_RSTP_URL -vcodec libvpx -f webm -

To distribute the stream I'm using a Node.js instance that calls the rtsp stream via ffpmeg when needed.

The solution looks like such:

Camera --Via RSTP--> ffmpeg --Encodes to WEBM--> Node.js --Via HTML5 Video--> Client

Node.js code:

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

    http.createServer(function (req, resp) {
    switch (params[0])
    {
      case "LIVE":
        resp.writeHead(200, {'Content-Type': 'video/mp4', 'Connection': 'keep-alive'});


            // Start ffmpeg
                var ffmpeg = child_process.spawn("ffmpeg",[
                    "-i","my_RSTP_URL", // Capture offset
                    "-vcodec","libvpx",      // vp8 encoding
                    "-f","webm",             // File format
                    "-"                      // Output to STDOUT
                ]);

            ffmpeg.on('exit', function()
                {
                    console.log('ffmpeg terminado');
                });

            ffmpeg.on('error',function(e)
            {
                console.log(e);
            })

            ffmpeg.stdout.on('data',function(data)
            {
                console.log('datos'+data);
            });


            ffmpeg.stderr.on('data', function(data) {
                console.log('stderr'+data);
            });

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

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

        console.log("Initializing camera");
        break;
    }


    }).listen(8088);

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

Am I using the wrong library codec? Or why Am I getting such a weird result?

like image 781
edua_glz Avatar asked Nov 11 '22 20:11

edua_glz


1 Answers

It seems to me, this can help for https://github.com/kyriesent/node-rtsp-stream Also I worked with this technology, you can visit repository on bitBucket: https://bitbucket.org/kaleniuk_ihor/neuro_vision/src/db_watch/

Оn the other hand, your code may not work because you did not install ffmpeg at the root of drive C.

like image 119
Dasha Avatar answered Nov 14 '22 22:11

Dasha