Generating an RTSP stream of a USB mic with a pi is harder than it should be. (just griping here, not BIrdNetPi's fault)) #1039
PeterMescher
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My current home hardware setup is a PiZero W (not the PiZero W 2), and a ProxMox server (you can get anything with a Gen7 Intel for a steal these days because they can't be upgraded to Win11... 4C 16GB and a 128GB SSD for under $150, shipped, w/ 1 yr warranty.)
Anyway, I can't run BirdNetPi on a Zero W, and I could not get my USB mic into an LXC Container running BirdNetPi using MatthewBCooke's fork. This might have been fixable, but my knowledge of Linux and Proxmox internals is limited, to say the least. All I accomplished was adding a bunch of crap that my hypervisor now doesn't need, and getting the container in such a state that BirdNetPi wouldn't even start.
My next thought was to connect the USB mic to my Pi Zero W, and then run an RTSP stream to the LXC Container. Well... most of the tutorials around RTSP streaming are for cameras, so those were no good. (My Pi distro, DietPi, even has easy-to-install software to do that exact thing.) Of the tutorials that did mention USB microphones, most revolve around VLC... which no longer has an RTSP server on Debian-derived builds due to licensing issues.
There was another discussion here that put me on the right track with FFMPEG, but combined with mediamtx, which I don't know how to use. In the end, the FFMPEG docs pointed to a decade-old perl script that can couple with FFMPEG to generate an RTSP stream.
Anyway, here's my final script that starts the mic:
#! /bin/sh
/root/rtsp-server/rtsp-server.pl &
sleep 30
ffmpeg -f alsa -acodec pcm_s24le -ac 1 -ar 48000 -i hw:1,0 -listen 1 -content_type 'audio/mpeg' -f rtsp rtsp://localhost:5545/birdmic -rtsp_transport tcp &
EDIT: My pi micro-SD card died and on re-install, it didn't like the -ac 1 option any longer; -channels 1 worked.
The rtsp-server is available here I got a lot of scary-looking error messages when it was pulling the necessary stuff from CPAN, but in the end, it worked without a hitch; the program doesn't even have any command-line options, much less a config file... doesn't get any easier to use than that! And it takes pretty much no CPU during operation. (The "sleep" afterwards is to give time for the program to run before trying to initiate the stream.)
For the ffmpeg command line: do an arecord --dump-hw-params to find out the format available and the bitrate. The format was s24le, which mapped to that pcm_s24le. And the -ar is where the bitrate goes. FFMPEG takes up about half the poor pi's CPU, but the only other thing it runs is pi-hole, which requires pretty much no CPU at all for steady-state operation.
BirdNetPi is now up and running, and pretty happy. It's not detecting quite as much as I'd like, but I'm sure I have more tweaking to do there. It barely even causes a blip in the CPU; takes 0.3 seconds to analyze 15 sec of audio. (In case anyone's curious, the container needed 2GB of RAM to initially set up (downloading the tensor package chewed up a lot of memory), but 1Gb with a moderate swap (which doesn't get used often) seems to be plenty for steady-state. I've given it 2 cores, which it never uses fully, but over-subscribing CPUs doesn't really hurt anything on a VM server.)
Beta Was this translation helpful? Give feedback.
All reactions