This script is designed to record a video stream from an RTSP source and save the recordings to the specified directory. It uses the fluent-ffmpeg
library to handle the RTSP stream and create video files in MKV format.
-
Continuous Recording: The script continuously records the video stream and starts a new recording when the previous one ends.
-
File Naming: Recordings are named based on the start time, with the filename format
hour-minute-second.mkv
. -
Automatic Deletion: Monitors the available disk space, and if it exceeds the defined threshold, it deletes the oldest recordings to free up space.
To use the script, create a config.json
file with the following parameters (based on config.json.example
file):
- rtspUrl: The RTSP stream URL.
- recordingsDirectory: The base directory where recordings are saved.
- diskSpaceThresholdMb: The maximum size of the recording directory in megabytes. After the directory exceeds this size, the script will delete the oldest recordings to free up space.
- segmentTimeSeconds: The duration of each recording segment in seconds.
- timeZone: The time zone used to name the recordings (list of time zones: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
Example config.json
:
{
"rtspUrl": "rtsp://admin:passwd@192.168.1.12/h264/main/av_stream",
"recordingsDirectory": "recordings",
"diskSpaceThresholdMb": 10000,
"segmentTimeSeconds": 60,
"timeZone": "Europe/Warsaw"
}
To run the script, first install the dependencies:
npm install
Then run the script:
npm start
or
node index.js
To stop the script, press Ctrl + C
in the terminal window where it is running.