rtsp 流节点 js ip 摄像头 jsmpeg 失败

问题描述

连接到网络摄像头,但像图片一样问题

运行 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"

但是,有时相机没有出现在画布上,而是像下图一样打印

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>

图片网址 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",loop:true});

你的问题必须解决!