justadudewhohacks / justadudewhohacks/opencv4nodejs
Error to open VideoCapture RTSP
- Dominant language
- C++
- Stars
- 5.1k
- Forks
- 826
- PR merge metrics
- No merged PRs in 30d
Description
I have a problem when using a ip cam streaming with RTSP, with my usb cam that working.
More anybody having this error?
Thank you!
```
node -v
v8.10.0
npm -v
3.5.2
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
```
**ERROR**
> > streamingTesteSocketIO@1.0.0 start /app
> > nodemon index.js
>
> [nodemon] 1.18.11
> [nodemon] to restart at any time, enter `rs`
> [nodemon] watching: *.*
> [nodemon] starting `node index.js`
> /app/index.js:12
> const wCap = new cv.VideoCapture("rtsp://admin:a12345678@192.168.1.13/Streaming/Channels/1");
> ^
>
> Error: VideoCapture::New - failed to open capture
> at Object. (/app/index.js:12:14)
> at Module._compile (module.js:652:30)
> at Object.Module._extensions..js (module.js:663:10)
> at Module.load (module.js:565:32)
> at tryModuleLoad (module.js:505:12)
> at Function.Module._load (module.js:497:3)
> at Function.Module.runMain (module.js:693:10)
> at startup (bootstrap_node.js:188:16)
> at bootstrap_node.js:609:3
> [nodemon] app crashed - waiting for file changes before starting...
**index.js**
```
const cv = require('opencv4nodejs');
const path = require('path')
const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
const PORT = 3000;
const HOST = '0.0.0.0';
const FPS = 10;
// const wCap = new cv.VideoCapture(0); <<< - Work
const wCap = new cv.VideoCapture("rtsp://admin:a12345678@192.168.1.13/Streaming/Channels/1")
wCap.set(cv.CAP_PROP_FRAME_WIDTH, 300);
wCap.set(cv.CAP_PROP_FRAME_HEIGHT, 300);
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
setInterval(() => {
const frame = wCap.read();
const image = cv.imencode('.jpg', frame).toString('base64');
io.emit('image', image);
}, 1000 / FPS)
server.listen(PORT, HOST);
```
**package.json**
```
{
"name": "streamingTesteSocketIO",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.4",
"nodemon": "^1.18.11",
"opencv4nodejs": "^4.7.3",
"socket.io": "^2.1.1"
}
}
```
**index.html**
```
const socket = io.connect('http://192.168.1.15:3000');
socket.on('image', (image) => {
// console.log('data', data);
const imageElm = document.getElementById('image');
imageElm.src = `data:image/jpeg;base64,${image}`;
});
```
Contributor guide
Assessment
This issue has not been assessed yet.