How to write RTSP stream

Asked

Viewed 324 times

0

I’m using the package node-rtsp-stream more Websocket to do the transmission of my IP-Camera, and the preview goes well, now I would like to know how to record this transmission and I have no idea how to do it.

index.js on Server(Nodejs)

const Stream = require('node-rtsp-stream'),
  stream = new Stream({
    name: 'Camera-Garagem',
    streamUrl: `rtsp://${meu_ip}:1030/user=${user}&password=${pass}&channel=1&stream=0.sdp?`,
    wsPort: 5000
  })

index.html in the Client

<div>
  <canvas id="videoCanvas"></canvas>
</div>
<script src="jsmpeg.js"></script>
<script>
  const ws = new WebSocket("ws://localhost:5000")
  const player = new jsmpeg(ws, {
    canvas: document.querySelector('#videoCanvas'),
    autoplay: true,
    audio: false,
    loop: true
  })
</script>

1 answer

3

You can take a look at this library

https://www.npmjs.com/package/node-rtsp-recorder

const Recorder = require('node-rtsp-recorder').Recorder

var rec = new Recorder({
    url: 'rtsp://${meu_ip}:1030/user=${user}&password=${pass}&channel=1&stream=0.sdp?',
    timeLimit: 60, // time in seconds for each segmented video file
    folder: '/node-rtsp-recorder/videos',
    name: 'cam1',
})
// Starts Recording
rec.startRecording();

setTimeout(() => {
    console.log('Stopping Recording')
    rec.stopRecording()
    rec = null
}, 300000)

Allows you to record the recording and store it on the server disk, then you can implement some kind of logic/route to download that video if needed.

  • recorded files are at 0 bytes, have any idea what might be?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.