rtsp 流媒体节点 js 网络摄像机 jsmpeg 失败

rtsp streaming node js ip camera jsmpeg fail

连接上了网络摄像头,但是像图片一样的问题

when 运行 node app.js "frame= 1970 fps=2.0 q=7.6 size= 22457kB time=00:16:25.00 bitrate= 186.8kbits/s dup=0 drop=3 speed =1.01x

当执行index.html "name: New WebSocket Connection (1 total)kB time=00:00:43.00 bitrate= 147.0kbits/s speed=1.28x"

但是,有时候canvas上没有出现相机,打印出来如下图

app.js

// const onvif = require('node-onvif');

// console.log('Start the discovery process.');
// // Find the ONVIF network cameras.
// // It will take about 3 seconds.
// onvif.startProbe().then((device_info_list) => {
//   console.log(device_info_list.length + ' devices were found.');
//   // Show the device name and the URL of the end point.
//   device_info_list.forEach((info) => {
//     console.log('- ' + info.urn);
//     console.log('  - ' + info.name);
//     console.log('  - ' + info.xaddrs[0]);
//   });
// }).catch((error) => {
//   console.error(error);
// });

///////////////////////////////////////

// const onvif = require('node-onvif');

// // Create an OnvifDevice object
// let device = new onvif.OnvifDevice({
//   xaddr: 'http://192.168.88.4:8081/onvif/device_service',
//   user : 'admin',
//   pass : 'tmzkdl123$'
// });

// // Initialize the OnvifDevice object
// device.init().then(() => {
//     // Get the UDP stream URL
//     let url = device.getUdpStreamUrl();
//     console.log(url);
//   }).catch((error) => {
//     console.error(error);
//   });

/////////////////////////////////////////

Stream = require('node-rtsp-stream')
stream = new Stream({
  name: 'name',
  streamUrl: 'rtsp://192.168.88.8:554/0/onvif/profile1/media.smp',
  wsPort: 9900,
  ffmpegOptions: { // options ffmpeg flags
    '-stats': '', // an option with no neccessary value uses a blank string
    '-r': 30 // options with required values specify the value after the key
  }
})

index.html

<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>rtsp</title>

        <div><canvas id="video" width="640" height="360"></canvas></div>
        <script type="text/javascript" src="jsmpeg.js"></script>
        <script type="text/javascript">
            var canvas = document.getElementById('video');
            var ws = new WebSocket("ws://192.168.88.174:9900");
                var player = new jsmpeg(ws, {canvas:canvas, autoplay:true, audio:false, loop:true});
        </script>
    </head>
    <body>
    </body>
</html>

图片url enter image description here

我也遇到过这个问题但是解决了, 您必须从 https://jsmpeg.com/ 下载 jsmpeg.min.js 并将其替换为 jsmpeg.js 文件然后更改此行

<script type="text/javascript" src="jsmpeg.js"></script>

<script type="text/javascript" src="jsmpeg.min.js"></script>

之后清除此行

var ws = new WebSocket("ws://192.168.88.174:9900");

并更改此行

var player = new jsmpeg(ws, {canvas:canvas, autoplay:true, audio:false, loop:true});

对此:

var player = new JSMpeg.Player("ws://192.168.88.174:9900", {canvas:canvas, autoplay:true, audio:false, loop:true});

你的问题必须解决!