How to Set Up a Simple Network Video Recorder (NVR) in Node.js

Oct 14, 2023 | Programming

If you’re looking to create a cost-effective Network Video Recorder (NVR) that runs on budget-friendly hardware like a Raspberry Pi, you’ve come to the right place! This guide will walk you through the setup process, allowing you to save 24/7 video streams from network cameras with ease.

Understanding the NVR Functionality

Think of the NVR as a library for your video footage. Each video stream is like a book that’s added to your library’s collection. Why five-minute clips? This is a precaution to ensure that if one “book” (file) gets damaged, you won’t lose the entire “library” (all your footage). Every day at 01:00 UTC, your NVR will compile these short clips into a longer, cohesive “novel” (single 24-hour file) before deleting the original clips, keeping your video archive organized.

Setting Up Your Configuration

Here’s how to set everything up step by step:

  1. First, install ffmpeg.
  2. Next, choose a directory for saving the video files, and update the rootpath directory in the storage.json configuration file.
  3. Add camera names and their RTSP addresses to the cameras.json configuration file.
  4. Finally, run the nvr.js server, for example, using PM2 with the command: pm2 start nvr.js --name nvr.

Once you run the nvr.js server, it will automatically start recording videos in five-minute segments. The recordings will be consolidated daily into a single video file at 01:00 UTC, and you can view them through the web interface.

Starting the Web Interface

If you’d like to browse your video files, you can run nvr-browser.js, which will start a web server at http://localhost:3000. Now, you can peruse your recorded footage much like flipping through the pages of a book!

If your interest lies solely in recording without browsing, simply run nvr.js.

Choosing the Right File Format

It’s crucial to understand the difference between MP4 and MKV file formats. While the former may be prevalent, MKV files show greater resilience against data corruption. Consider this: if you accidentally “break” an MP4 file while unplugging the camera, you might lose access entirely, like tearing a page out of the book. In contrast, an MKV file can still provide usable data, akin to keeping a damaged book on the shelf, where you can still read much of it.

Troubleshooting Your NVR Setup

As with any technology, issues can arise. Here are some common troubleshooting tips:

  • Verify Network Connection: Ensure that your Raspberry Pi has a stable wired network connection to avoid stream drops.
  • Check File Permissions: Make sure your NVR has the necessary permissions to write to the designated folders.
  • Monitor Stream Failures: Implement a file watcher script to detect when video feeds are inactive, allowing for quick troubleshooting.
  • Corrupted Files: Occasionally, files may get corrupted during recording or concatenation. Using ffprobe can help identify these issues before running the concatenation script.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Why Choose a Raspberry Pi?

The Raspberry Pi 3b+ is an ideal choice for this project. With a modest CPU consumption of around 9% per camera, it can effectively support multiple feeds without breaking a sweat. Imagine having a librarian who can handle a small library of books effortlessly—this is what the Raspberry Pi accomplishes in the realm of video recording.

Conclusion

Implementing a simple NVR on a Raspberry Pi allows you to capture and manage video streams efficiently. With the ability to save footage in manageable formats and a user-friendly web interface, you have a powerful tool at your fingertips. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox