将RTSPstream转换为MP4

我有一个支持RTSP的IP摄像头,我需要使用HTML5将这个stream显示给多个客户端。

由于HTML Video标签不支持RTSP,因此我打电话给ffmpeg将其编码为一个WEBMstream,但是结果非常不好,并且使原始stream失真。

我使用的命令如下: ffmpeg -i my_RSTP_URL -vcodec libvpx -f webm -

为了分发stream,我使用了一个Node.js实例,在需要时通过ffpmeg调用rtspstream。

解决scheme如下所示:

相机–Via RSTP – > ffmpeg – 编程到WEBM – > Node.js –Via HTML5video – >客户端

Node.js代码:

  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'); 

我使用错误的库编解码器? 或者为什么我得到这样一个奇怪的结果?