Skip to content

seekwhencer/ffmpeg-rekorder

Repository files navigation

ffmpeg-rekorder

A little node.js app around ffmpeg, dnsmasq and samba to run it on a Raspberry Pi4.

With this setup you can:

  • record ip camera rtsp streams in segmented files with ffmpeg
  • start automatically recording when a camera is available
  • provide dhcp with dnsmasq
  • provide local network shares with samba
  • notify availability and recording state to a mqtt server
  • control the app per mqtt to enable or disable a stream and to start stop the recording
  • define an age for the recorded files and drop them if necessary

Setup

Get it

git clone [email protected]:seekwhencer/ffmpeg-rekorder.git

Network

  • edit network config
sudo nano /etc/network/interfaces
  • add this
source /etc/network/interfaces.d/*
  • create eth1 config
sudo nano /etc/network/interface.d/eth1.conf
  • add (and change) this
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 192.168.179.1
netmask 255.255.255.0
gateway 192.168.179.1
broadcast 192.168.179.255
dns-nameservers 192.168.179.1

Run setup

chmod +x ./setup.sh
./setup.sh

Config

Environment

There are three possibilities to put config parameters in the app.

  • at first, the app/config/ENVIRONMENT.conf will be loaded
  • the ENVIRONMENT comes from the environment as variable ENVIRONMENT
  • the ENVIRONMEMT is a string and equals the filename: app/config/ENVIRONMENT.conf
  • then the .env file will be loaded and override existing values
  • at last, the environment variables override existing parameters
  1. config file
  2. .env file
  3. env variables

Environment variables comes from the docker-compose file.

Duplicate

  • from .env.example to .env
  • from dnsmasq/example.conf to dnsmasq/dnsmasq.conf
  • from app/config/example.conf to app/config/default.conf
  • from app/config/streams/conf.example to app/config/streams/mycam1.conf

Edit

  • all duplicated files with your own settings
  • to create multiple stream configs, create mycam1.conf, mycam2.conf, ... in app/config/streams/

.env

  • PROJECT_NAME
    Prefix for the container name.

  • DOCKER_COMPOSE_SOURCE
    The binary URL from github.

  • HOST_STORE_ROOT_PATH
    The absolute path to the storage root directory on the docker host.

  • STORE_ROOT_PATH
    The absolute storage path in the container.

  • STORE_FILE_PREFIX
    FFmpeg parameter syntax for:strftime (FFmpeg Documentation)

  • SEGMENT_TIME
    FFmpeg parameter syntax for:segment_time (FFmpeg Documentation)

  • SAMBA_USER
    The network shares username

  • SAMBA_PW
    The network share userpassword

  • BUILD_TARGET=node16-linux-armv7
    https://github.com/vercel/pkg#targets

  • BUILD_FILENAME=rekorder
    The binary filename

app/config/default.conf

  • DEBUG
    Verbose on, off

  • SERVER_PORT
    The listen port for the web app and api

  • MQTT_HOST
    The mqtt host or ip

  • MQTT_PORT
    The mqtt port

  • MQTT_CLIENT_ID
    The mqtt client id for the app

  • FFMPEG_BINARY=/usr/local/bin/ffmpeg
    The absolute path and filename to the ffmpeg binary

  • STREAMS_CONFIG_PATH=config/streams
    The relative path from app path for streams config files

app/config/streams/mycam.conf (multiple camera configs)

  • NAME
    The name of the camera or stream

  • ENABLED
    Is the camera enabled on app start

  • CHECK_INTERVAL_DURATION
    Milliseconds to check if a stream is available

  • SEGMENT_TIME
    Duration of a file. If not set, value comes from .env

  • FILE_PREFIX
    Same STORE_FILE_PREFIX from .env or changed

  • STREAM_URL
    The reachable stream url from the ip camera.

  • AUTO_RECORD
    1 or 0 to start recording if the cam is available

  • MQTT_ENABLE
    1 or 0

  • MQTT_TOPIC_ENABLE
    The publish topic to commit the enabled state 1 or 0

  • MQTT_TOPIC_RECORD
    The publish topic to commit the recording state 1 or 0

  • MQTT_CONTROL_TOPIC_ENABLE
    The subscribed topic to enable or disable the stream with 1 or 0

  • MQTT_CONTROL_TOPIC_RECORD
    The subscribed topic to start or stop the recording with 1 or 0

  • MQTT_TOPIC_VALUE_ON=1

  • MQTT_TOPIC_VALUE_OFF=0

  • MQTT_CONTROL_VALUE_ON=1

  • MQTT_CONTROL_VALUE_OFF=0

  • STORAGE_AGE
    Is an ISO 8601 string. Temporals

Run

simply

chmod +x ./up.sh
./up.sh

or one by one

docker-compose -f docker-compose-dnsmasq.yml up -d
docker-compose -f docker-compose-samba.yml up -d
docker-compose -f docker-compose-app.yml up -d

Hardware

Scenario use case

  • Eth0 on the Raspberry Pi is wired to hour local network router.
  • The second ethernet is connected to the poe switch to provide connected lan clients an ip address.

@TODO

  • fixing build pipeline for binary

Development

start the container - but not the app

  • stop the container: docker-compose -f docker-compose-app.yml down
  • edit docker-compose-app.yml
  • change: command: "--experimental-modules --experimental-json-modules index.js" to command: "tail -f /dev/null"
  • start the container: docker-compose -f docker-compose-app.yml up -d
  • start the app: docker exec -it ffmpeg-rekorder_app sh -c "/usr/local/bin/node --experimental-modules --experimental-json-modules index.js"
  • stop the app: CTRL + C

build binary

  • docker exec -it ffmpeg-rekorder_app sh -c "/rekorder/build.sh"
  • then a file rekorder was created in the app/ folder
  • use this binary

About

Raspberry Pi setup for a ip camera rekorder

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages