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
git clone [email protected]:seekwhencer/ffmpeg-rekorder.git
- 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
chmod +x ./setup.sh
./setup.sh
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 variableENVIRONMENT
- 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
- config file
- .env file
- env variables
Environment variables comes from the docker-compose file.
- from
.env.example
to.env
- from
dnsmasq/example.conf
todnsmasq/dnsmasq.conf
- from
app/config/example.conf
toapp/config/default.conf
- from
app/config/streams/conf.example
toapp/config/streams/mycam1.conf
- all duplicated files with your own settings
- to create multiple stream configs, create
mycam1.conf
,mycam2.conf
,...
inapp/config/streams/
-
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
-
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
-
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
SameSTORE_FILE_PREFIX
from.env
or changed -
STREAM_URL
The reachable stream url from the ip camera. -
AUTO_RECORD
1
or0
to start recording if the cam is available -
MQTT_ENABLE
1
or0
-
MQTT_TOPIC_ENABLE
The publish topic to commit the enabled state1
or0
-
MQTT_TOPIC_RECORD
The publish topic to commit the recording state1
or0
-
MQTT_CONTROL_TOPIC_ENABLE
The subscribed topic to enable or disable the stream with1
or0
-
MQTT_CONTROL_TOPIC_RECORD
The subscribed topic to start or stop the recording with1
or0
-
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
chmod +x ./up.sh
./up.sh
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
- 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.
- fixing build pipeline for binary
- 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"
tocommand: "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
docker exec -it ffmpeg-rekorder_app sh -c "/rekorder/build.sh"
- then a file
rekorder
was created in theapp/
folder - use this binary