I have a Node.js application that uses the node-rtsp-stream package to stream an RTSP video from an IP camera. However, when I run the application, I encounter the following errors in the console after a few minutes:
[rtsp @ 000002402795dd80] Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, rtsp, from 'rtsp://fake_test:jksdfhskhdfsomethingfake@111.111.11.1111:50213/cam/realmonitor?channel=1&subtype=1'(fake rtsp link used for privacy)':
Metadata:
title : Media Server
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264, none, 90k tbr, 90k tbn
Output #0, mpegts, to 'pipe:':
[out#0/mpegts @ 0000024027987b80] Output file does not contain any stream
Error opening output file -.
Error opening output files: Invalid argument
RTSP stream exited with error
I am certain that the RTSP stream from the camera is in H.264 - MPEG-4 AVC format, and I can play it in VLC without any issues. However, when I try to stream it using the node-rtsp-stream package, I encounter these errors.
Here is my Node.js code:
const express = require('express');
const Stream = require('node-rtsp-stream');
const app = express();
const port = 4000;
const stream = new Stream({
name: 'rtsp_server_name',
streamUrl: 'rtsp://fake_test:jksdfhskhdfsomethingfake@111.111.11.1111:50213/cam/realmonitor?channel=1&subtype=1'(fake rtsp link used for privacy),
wsPort: 9999,
ffmpegOptions: {
'-stats': '', // an option with no necessary value uses a blank string
'-r': 30, // options with required values specify the value after the key
},
});
// Middleware to log each request
app.use((req, res, next) => {
console.log(`${req.method} ${req.url}`);
next();
});
app.get('/', (req, res) => {
res.send('Hello World');
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
});
// Event listener to check if the RTSP stream is ready
stream.on('data', (data) => {
if (data.includes('frame=')) {
console.log('RTSP stream is ready and streaming.');
}
});
I have tried increasing the values for 'analyzeduration' and 'probesize' options, but the errors persist. How can I resolve these errors and successfully stream the RTSP video in H.264 format using the node-rtsp-stream package? Any help or guidance would be appreciated. Thank you!