record: Add RTSP support (to be continued)
This commit is contained in:
parent
933b635bf2
commit
cf0de2d4bc
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,6 +1,5 @@
|
||||
var/
|
||||
/.venv/
|
||||
/analyzer/
|
||||
|
||||
.env
|
||||
|
||||
@ -8,6 +7,8 @@ species_list.txt
|
||||
|
||||
push.sh
|
||||
|
||||
config/*.conf
|
||||
|
||||
/config/*.conf
|
||||
!/config/*.conf.example
|
||||
/config/stations/*.conf
|
||||
!/config/stations/*.conf.example
|
||||
.vscode/
|
3
config/stations/station.conf.example
Normal file
3
config/stations/station.conf.example
Normal file
@ -0,0 +1,3 @@
|
||||
# Config file for a distant recording station
|
||||
RTSP_URL=rtsp://host:1000/birdnet/stream
|
||||
STATION_NAME=garden
|
@ -27,12 +27,20 @@ record_loop() {
|
||||
done
|
||||
}
|
||||
|
||||
FFMPEG_OPTIONS="-nostdin -hide_banner -loglevel error -nostats -vn -acodec pcm_s16le -ac 1 -ar 48000 "
|
||||
|
||||
record() {
|
||||
record_stream() {
|
||||
local STREAM=$1
|
||||
local DURATION=$2
|
||||
local debug "Recording from $STREAM for $DURATION seconds"
|
||||
ffmpeg $FFMPEG_OPTIONS -f -i ${DEVICE} -t ${DURATION} file:${CHUNK_FOLDER}/in/birdnet_$(date "+%Y%m%d_%H%M%S").wav
|
||||
}
|
||||
|
||||
record_device() {
|
||||
DEVICE=$1
|
||||
DURATION=$2
|
||||
debug "Recording from $DEVICE for $DURATION seconds"
|
||||
ffmpeg -nostdin -hide_banner -loglevel error -nostats -f pulse -i ${DEVICE} -t ${DURATION} -vn -acodec pcm_s16le -ac 1 -ar 48000 -af "volume=$RECORDING_AMPLIFY" file:${CHUNK_FOLDER}/in/birdnet_$(date "+%Y%m%d_%H%M%S").wav
|
||||
ffmpeg $FFMPEG_OPTIONS -f pulse -i ${DEVICE} -t ${DURATION} -af "volume=$RECORDING_AMPLIFY" file:${CHUNK_FOLDER}/in/birdnet_$(date "+%Y%m%d_%H%M%S").wav
|
||||
}
|
||||
|
||||
config_filepath="./config/analyzer.conf"
|
||||
@ -53,4 +61,13 @@ if [[ -z $AUDIO_DEVICE ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
record_loop $AUDIO_DEVICE $RECORDING_DURATION
|
||||
if [[ $AUDIO_RECORDING = "true" ]]; then
|
||||
record_loop $AUDIO_DEVICE $RECORDING_DURATION &
|
||||
fi
|
||||
|
||||
if [[ $AUDIO_STATIONS = "true" ]]; then
|
||||
for station in $(ls ./config/stations/*.conf); do
|
||||
source $station
|
||||
record_stream $STATION_URL $RECORDING_DURATION &
|
||||
done
|
||||
fi
|
@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env bash
|
||||
# SQLite library to deal with BirdNET-stream database
|
||||
# SQLite library to deal with BirdNET-stream observations database
|
||||
|
||||
set -e
|
||||
|
||||
@ -10,27 +10,31 @@ source ./config/analyzer.conf
|
||||
|
||||
DATABASE=${DATABASE:-"./var/db.sqlite"}
|
||||
|
||||
query() {
|
||||
sqlite3 -cmd ".timeout 1000" $DATABASE "$1"
|
||||
}
|
||||
|
||||
get_location_id() {
|
||||
sqlite3 -cmd ".timeout 1000" $DATABASE "SELECT location_id FROM location WHERE latitude=$1 AND longitude=$2"
|
||||
query "SELECT location_id FROM location WHERE latitude=$1 AND longitude=$2"
|
||||
}
|
||||
|
||||
get_taxon_id() {
|
||||
sqlite3 -cmd ".timeout 1000" $DATABASE "SELECT taxon_id FROM taxon WHERE scientific_name='$1'"
|
||||
query "SELECT taxon_id FROM taxon WHERE scientific_name='$1'"
|
||||
}
|
||||
|
||||
insert_taxon() {
|
||||
sqlite3 -cmd ".timeout 1000" $DATABASE "INSERT INTO taxon (scientific_name, common_name) VALUES (\"$1\", \"$2\")"
|
||||
query $DATABASE "INSERT INTO taxon (scientific_name, common_name) VALUES (\"$1\", \"$2\")"
|
||||
}
|
||||
|
||||
insert_location() {
|
||||
sqlite3 -cmd ".timeout 1000" $DATABASE "INSERT INTO location (latitude, longitude) VALUES ($1, $2)"
|
||||
query "INSERT INTO location (latitude, longitude) VALUES ($1, $2)"
|
||||
}
|
||||
|
||||
insert_observation() {
|
||||
sqlite3 -cmd ".timeout 1000" $DATABASE "INSERT INTO observation (audio_file, start, end, taxon_id, location_id, confidence, date) VALUES ('$1', '$2', '$3', '$4', '$5', '$6', '$7')"
|
||||
query "INSERT INTO observation (audio_file, start, end, taxon_id, location_id, confidence, date) VALUES ('$1', '$2', '$3', '$4', '$5', '$6', '$7')"
|
||||
}
|
||||
|
||||
# Check if the observation already exists in the database
|
||||
observation_exists() {
|
||||
sqlite3 -cmd ".timeout 1000" $DATABASE "SELECT EXISTS(SELECT observation_id FROM observation WHERE audio_file='$1' AND start='$2' AND end='$3' AND taxon_id='$4' AND location_id='$5')"
|
||||
query "SELECT EXISTS(SELECT observation_id FROM observation WHERE audio_file='$1' AND start='$2' AND end='$3' AND taxon_id='$4' AND location_id='$5')"
|
||||
}
|
Loading…
Reference in New Issue
Block a user