record: Add RTSP support (to be continued)

This commit is contained in:
Samuel Ortion 2022-08-20 08:33:54 +02:00
parent 933b635bf2
commit cf0de2d4bc
5 changed files with 38 additions and 13 deletions

7
.gitignore vendored
View File

@ -1,6 +1,5 @@
var/ var/
/.venv/ /.venv/
/analyzer/
.env .env
@ -8,6 +7,8 @@ species_list.txt
push.sh push.sh
config/*.conf /config/*.conf
!/config/*.conf.example
/config/stations/*.conf
!/config/stations/*.conf.example
.vscode/ .vscode/

View File

@ -0,0 +1,3 @@
# Config file for a distant recording station
RTSP_URL=rtsp://host:1000/birdnet/stream
STATION_NAME=garden

View File

@ -27,12 +27,20 @@ record_loop() {
done 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 DEVICE=$1
DURATION=$2 DURATION=$2
debug "Recording from $DEVICE for $DURATION seconds" 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" config_filepath="./config/analyzer.conf"
@ -53,4 +61,13 @@ if [[ -z $AUDIO_DEVICE ]]; then
exit 1 exit 1
fi 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

View File

@ -1,5 +1,5 @@
#! /usr/bin/env bash #! /usr/bin/env bash
# SQLite library to deal with BirdNET-stream database # SQLite library to deal with BirdNET-stream observations database
set -e set -e
@ -10,27 +10,31 @@ source ./config/analyzer.conf
DATABASE=${DATABASE:-"./var/db.sqlite"} DATABASE=${DATABASE:-"./var/db.sqlite"}
query() {
sqlite3 -cmd ".timeout 1000" $DATABASE "$1"
}
get_location_id() { 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() { 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() { 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() { 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() { 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 # Check if the observation already exists in the database
observation_exists() { 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')"
} }