2
I need help to stream with Nodejs and Socket.io. I’m using the rtsp-ffmpeg library to stream. I was able to execute it transmitting in img format according to the specific documentation itself, but I am not able to send an mp4 even after setting the correct parameter in the library (https://github.com/agsh/rtsp-ffmpeg)
const app = require('express')()
, server = require('http').Server(app)
, io = require('socket.io').listen(server)
, rtsp = require('./lib/rtsp-ffmpeg');
// usar rtsp = require('rtsp-ffmpeg') se caso tiver instalado o pacote
server.listen(6147, function(){
console.log('Servidor executando em localhost:6147');
});
var uri = 'rtsp://mpv.cdn3.bigCDN.com:554/bigCDN/definst/mp4:bigbuckbunnyiphone_400.mp4'
, stream = new rtsp.FFMpeg({input: uri, resolution: '320x240', quality: 3});
io.on('connection', function(socket) {
var pipeStream = function(data) {
console.log('Client has connected to the server!')
socket.emit('data', data.toString('base64'));
};
stream.on('data', pipeStream);
socket.on('disconnect', function() {
stream.removeListener('data', pipeStream);
});
});
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
This is the HTML
<html>
<head>
<title></title>
</head>
<body>
<video id="video" controls autoplay autobuffer>
<source id="conteudo">
</video>
<script src="/socket.io/socket.io.js"></script>
<script>
var video = document.getElementById('conteudo'),
socket = io('');
socket.on('data', function(data) {
video.src = 'data:video/mp4;base64,' + data;
});
</script>
</body>
Package.json
{
"name": "VideoStream",
"version": "0.1.0",
"description": "A real-time media player",
"repository": "",
"dependencies": {
"express": "4",
"socket.io": "^1.4",
"jade" : "0.28.x"
},
"author": "Marco Gorak"
}
worked, thanks
– Alessandro Prudencio