Rtsp streaming on nodejs - Blank screen

941 Views Asked by At

I am currently working on a Node.js project where I need to implement streaming using ffmpeg. However, I am facing an issue with the streaming process, as I am getting an empty blank screen instead of the expected video stream.

Here's a brief overview of what I have done so far on the server-side:

Installed ffmpeg and made sure it is accessible in the environment. Configured the server-side code for the streaming process. However, despite these efforts, the stream is not working correctly, and I am unable to see the video stream on the client-side.

Server-side code: app.js

const express = require('express');
const Stream = require('node-rtsp-stream');

const app = express();
const port = 4000;

// Start the RTSP stream
const stream = new Stream({
  name: 'rtsp_server_name',
  streamUrl: 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4',
  wsPort: 3000,
  ffmpegOptions: {
    '-stats': '', // an option with no necessary value uses a blank string
    '-r': 30, // options with required values specify the value after the key
  },
});

stream.on('data', data => {
  console.log(data);
});

app.get('/', (req, res) => {
  res.send('Hello World');
});

app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}/`);
});

index.html

<html>
  <body>
    <canvas id="canvas"></canvas>
  </body>
  <h1>Test rtsp video</h1>
  <script type="text/javascript" src="js/jsmpeg.min.js"></script>
  <script type="text/javascript">
    player = new JSMpeg.Player('ws://localhost:3000', {
      canvas: document.getElementById('canvas'), // Canvas should be a canvas DOM element
    });
  </script>
</html>

I got no console error when I open index.html but only get blank black screen
Blank Screen

1

There are 1 best solutions below

0
DeNiks_One On

Not use localhost. Use local ip your PC. Open CMD and write ifconfig. IP4 your machine ip.

<html>
  <body>
    <canvas id="canvas"></canvas>
  </body>
  <h1>Test rtsp video</h1>
  <script type="text/javascript" src="js/jsmpeg.min.js"></script>
  <script type="text/javascript">
    player = new JSMpeg.Player('ws://192.168.0.100:3000', {
      canvas: document.getElementById('canvas'), // Canvas should be a canvas DOM element
    });
  </script>
</html>