GithubHelp home page GithubHelp logo

robszumski / tiny-nvr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hpaolini/tiny-nvr

0.0 2.0 0.0 19 KB

Docker container to capture IP camera streams

Home Page: https://hub.docker.com/r/hpaolini/tiny-nvr

Dockerfile 38.67% Shell 61.33%

tiny-nvr's Introduction

I've been using several scripts to record RTSP streams with ffmpeg, which have worked well over the years, but lately I thought they would be better served in a Docker container. So, here I will show you how to run an Alpine-based container that captures your camera's live stream, saves the video in segments, and deletes the old ones as time goes on.

First, you'll need to gather the following info from your IP camera:

  • Credentials (username and password)
  • IP address and port
  • RTSP stream URL syntax (for example, some Hikvision cameras follow this syntax rtsp://username:password@address:port//Streaming/Channels/1).

If your camera allows it, I recommend enabling TCP for the live stream. UDP is fine for view-only purposes but not saving, since frames are usually dropped to keep up with the packets.

From your terminal, cd to the directory where you wish to store the recordings and run the following command. (The first parameter is the RTSP URL, which you should format using the info you have gathered from your camera; while the second parameter is used to name the recording folder--the latter is optional.)

docker run \
       -v $(pwd):/usr/data/recordings \
       -e TZ=America/Chicago \
       hpaolini/tiny-nvr \
       rtsp://username:password@address:port//Streaming/Channels/2 \
       my_camera

With the default settings, the container creates a folder in the current directory (in the example the folder is named "my_camera"), saves the stream in 15 minute segments,1 and initiates a daily cron job to delete recordings older than 3 days.

I added the following environment variables for additional customization. (Remember, environment variables are changed using the -e flag.)

ENV Default Description
TZ Europe/Rome timezone data
DIR_NAME_FORCE false use the folder name you pass as parameter during docker run even if it exists, otherwise it generates a new folder name
HOUSEKEEP_ENABLED true cron job to delete old recordings
HOUSEKEEP_DAYS 3 delete files older than this number of days, if HOUSEKEEP_ENABLED is enabled
VIDEO_SEGMENT_TIME 900 seconds of each recording1
VIDEO_FORMAT mp4 save output as MKV or MP4 file

Combine this with Kubernetes or Docker Swarm and you've got a simple NVR with a small footprint. Happy hacking!

Footnotes

  1. I recommend saving streams in segments of 30 minutes or less. If your camera fails, most likely only your latest recording would result in a corrupted file, so you still have access to recordings that are closer to the point of failure. Also, the most recent recordings are synced faster to a backup solution. 2

tiny-nvr's People

Contributors

robszumski avatar hpaolini avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.