All Projects → boonya → rtsp-video-recorder

boonya / rtsp-video-recorder

Licence: MIT license
Provides an API to record RTSP video stream to filesystem.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to rtsp-video-recorder

Rtmp Rtsp Stream Client Java
Library to stream in rtmp and rtsp for Android. All code in Java
Stars: ✭ 1,338 (+6271.43%)
Mutual labels:  stream, rtsp
Rtp Streamer
rtp record and rtp streamer
Stars: ✭ 60 (+185.71%)
Mutual labels:  rtsp, recorder
node-rtsp-recorder
Records and saves RTSP Video Streams
Stars: ✭ 50 (+138.1%)
Mutual labels:  rtsp, recorder
wsa
WSA(Websocket Streaming Agent) is a stream server target for mp4/h264 streaming over websocket
Stars: ✭ 35 (+66.67%)
Mutual labels:  stream, rtsp
Pyinstalive
Python script to download Instagram livestreams and replays.
Stars: ✭ 336 (+1500%)
Mutual labels:  stream, recorder
Rtspallthethings
Deprecated RTSP media server -- Use github.com/aler9/rtsp-simple-server instead.
Stars: ✭ 258 (+1128.57%)
Mutual labels:  stream, rtsp
WebRTCCTV
WebRTCCTV is a signaling server & webapp able to stream from RTSP cameras using WebRTC
Stars: ✭ 32 (+52.38%)
Mutual labels:  stream, rtsp
Endoscope
Endoscope lets you to stream live video between android devices over Wi-Fi! 📱📲
Stars: ✭ 587 (+2695.24%)
Mutual labels:  stream, rtsp
Vxg.media.sdk.android
Market leading Android SDK with encoding, streaming & playback functionality
Stars: ✭ 119 (+466.67%)
Mutual labels:  stream, rtsp
canvas-record
A one trick pony package to record and download a video from a canvas animation.
Stars: ✭ 64 (+204.76%)
Mutual labels:  recorder
matroska-subtitles
💬 Streaming parser for embedded .mkv subtitles.
Stars: ✭ 40 (+90.48%)
Mutual labels:  stream
streamer
Go Package built around spinning up streaming processes
Stars: ✭ 37 (+76.19%)
Mutual labels:  rtsp
create-music-stream
Creates a PCM 16 bit Little Endian Stream from a mp3 file or youtube video
Stars: ✭ 21 (+0%)
Mutual labels:  stream
log
A thin (and fast) PSR-3 logger.
Stars: ✭ 45 (+114.29%)
Mutual labels:  stream
sox-stream
📣 A stream-friendly wrapper around SoX
Stars: ✭ 50 (+138.1%)
Mutual labels:  stream
AnimeDLR
AnimeDLR
Stars: ✭ 47 (+123.81%)
Mutual labels:  stream
live555ProxyServerEx
Improved version of the "LIVE555 Proxy Server"
Stars: ✭ 35 (+66.67%)
Mutual labels:  rtsp
castty
A CLI tool to record audio-enabled screencasts of your terminal, for the web.
Stars: ✭ 109 (+419.05%)
Mutual labels:  recorder
papilo
DEPRECATED: Stream data processing micro-framework
Stars: ✭ 24 (+14.29%)
Mutual labels:  stream
dot
distributed data sync with operational transformation/transforms
Stars: ✭ 73 (+247.62%)
Mutual labels:  stream

RTSP Video Recorder

Provides an API to record rtsp video stream as a mp4 files splitted out on separate segments

  • Does not depend on any other third-party packages at a production environment.
  • Small bundle size
  • Fluent Interface
  • Event Emitter
  • Very customizable

Validation & build Release npm Maintainability Test Coverage Bundle Size

Precondition

This library spawns ffmpeg as a child process, so it won't work with no ffmpeg installed. To do so just type:

sudo apt update
sudo apt install -y ffmpeg

If you prefer different package manager or work on different linux distr use appropriate to your system command.

Installation

Installation process of this lib as simple as it can be. Just run

npm i --save rtsp-video-recorder

After that you can use it like on example below

Example

Init an instance of recorder

import Recorder, { RecorderEvents } from 'rtsp-video-recorder';

const recorder = new Recorder('rtsp://username:password@host/path', '/media/Recorder', {
  title: 'Test Camera',
});

if you application is a CommonJs module you should be able do the same this way:

const {Recorder, RecorderEvents} = require('rtsp-video-recorder');

const recorder = new Recorder('rtsp://username:password@host/path', '/media/Recorder', {
  title: 'Test Camera',
});

Start recording

recorder.start();

Stop recording

recorder.stop();

If you need to know whether recording is in process or no

You can execute isRecording method on recorder instance which returns boolean value

recorder.isRecording();

It also supports Fluent Interface

import Recorder, { RecorderEvents } from 'rtsp-video-recorder';

new Recorder('rtsp://username:password@host/path', '/media/Recorder')
  .on(RecorderEvents.STARTED, onStarted)
  .on(RecorderEvents.STOPPED, onStopped)
  .on(RecorderEvents.FILE_CREATED, onFileCreated)
  .start();

Arguments

uri

RTSP stream URI. e.g. rtsp://username:password@host/path

destination

Path to the directory for video records. It may be relative but better to define it in absolute manner.

Options

title

Title of video file. Used as metadata of video file.

playlistName

The name you want your playlist file to have.

By default the name is going to be a datetime string in a format Y.m.d-H.M.S (e.g. 2020.01.03-03.19.15) which represents the time playlist have been created.

filePattern

File path pattern. By default it is %Y.%m.%d/%H.%M.%S which will be translated to e.g. 2020.01.03/03.19.15

Accepts C++ strftime specifiers:

segmentTime

Duration of one video file (in seconds). 600 seconds or 10 minutes by default if not defined. It can be a number of seconds or string xs, xm or xh what means amount of seconds, minutes or hours respectively.

noAudio

By default the process is going to record audio stream into a file but in case you don't want to, you can pass true to this option. Note that audio stream is encoded using ACC.

dirSizeThreshold

In case you have this option specified you will have ability to catch SPACE_FULL event when threshold is reached. It can be a number of bytes or string xM, xG or xT what means amount of Megabytes, Gigabytes or Terabytes respectively.

NOTE that option does not make sense if dirSizeThreshold option is not specified.

ffmpegBinary

In case you need to specify a path to ffmpeg binary you can do it using this argument.

Events

start event

recorder.on(RecorderEvents.START, (payload) => {
  assert.equal(payload, 'programmatically');
});

stop event

Normal stop

recorder.on(RecorderEvents.STOP, (payload) => {
  assert.equal(payload, 'programmatically');
});

If space full

recorder.on(RecorderEvents.STOP, (payload) => {
  assert.equal(payload, 'space_full');
});

In case of other errors

recorder.on(RecorderEvents.STOP, (payload) => {
  assert.equal(payload, 'error', Error);
});

started event

Handler receives an object that contains options applied to the current process

  • Default values if no options passed.
  • Converted values in case of some options if passed.
recorder.on(RecorderEvents.STARTED, (payload) => {
  assert.equal(payload, {
    uri: 'rtsp://username:password@host/path',
    destination: '/media/Recorder',
    playlist: 'playlist.m3u8',
    title: 'Test Camera',
    filePattern: '%Y.%m.%d/%H.%M.%S',
    segmentTime: 600,
    noAudio: false,
    ffmpegBinary: 'ffmpeg',
  });
});

stopped event

If stopped because of space full handler receives 0 exit code & reason message 'space_full'.

recorder.on(RecorderEvents.STOPPED, (payload) => {
  assert.equal(payload, 0, 'space_full');
});

Or if stop reason is FFMPEG process exited, handler receives an exit code of ffmpeg process and a message that FFMPEG exited.

recorder.on(RecorderEvents.STOPPED, (payload) => {
  assert.equal(payload, 255, 'ffmpeg_exited');
});

file_created event

New file should be created when new segment started or in case of recording stopped.

recorder.on(RecorderEvents.FILE_CREATED, (payload) => {
  assert.equal(payload, `2020.06.25/10.18.04.mp4`);
});

space_full event

If no space left an event should be emitted and payload raised.

There is approximation percentage which is set to 1, so when you reach out 496 you'll have space_full event emitted if you set your threshold e.g. 500. In other words it works based on formula Math.ceil(used + used * APPROXIMATION_PERCENTAGE / 100) > threshold where threshold is you threshold valid and used is amount of space used.

recorder.on(RecorderEvents.SPACE_FULL, (payload) => {
  assert.equal(payload, {
    threshold: 500,
    used: 496,
  });
});

error event

recorder.on(RecorderEvents.ERROR, () => {
  /** Do what you need in case of recording error */
});

Here you may see several examples of usage

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].