RTSP + USB Audio - Simultaneous Sources? #1006
Replies: 14 comments 20 replies
-
I think you're right, the way the code is currently set-up I think it's either-or. Though in theory it shouldn't be too much re-architecting to allow both. At the moment I use Pi Zero to push audio to my main general-purpose house server with the following gstreamer pipeline:
I chose gstreamer just because it seemed to pull in far fewer dependencies than ffmpeg, but it shouldn't be hard to do with ffmpeg either. I use mediamtx to push the RTSP to, though in theory the icecast instance that BNPI already creates could be used as well I think (although maybe not with RTSP.) If you did want to mix local and remote audio, the quickest hack would probably be to present even the local audio as an RTSP/HTTP stream to birdnet. Probably adds a little overhead moving the data around unnecessarily, but hopefully not much. |
Beta Was this translation helpful? Give feedback.
-
This is a brilliant idea! I can just create RTSP Steam 1 from my existing BirdNET Pi and loop it back locally and then throw in a Pi zero with a second mic as RTSP 2.
I am a little confused however in terms as how you are implementing it. So above you have you gstreamer command line you are using. So how does mediamtx fit in? Can you reply with your full recipe?
Thanks!
|
Beta Was this translation helpful? Give feedback.
-
Manny thanks & take your time. So gstreamer (or ffmpeg) creates the audio then mediamtx takes that feed and creates the RTSP stream that would be pulled from the BirdNET pi? In my case my BirdNET pi is a RP 4 (where I am plaining on looping back the local audio as you suggested) and I found an older RP 3 I am going to connect the new mic thus producing the second RTSP feed to BirdNet. |
Beta Was this translation helpful? Give feedback.
-
So does the above ffmpeg command both encode the audio from the local USB sound card mic and produce the RTSP stream itself? I am confused how you are mediamtx fits in. I got my old RP 3 going but jut need the microphone to arrive from Micbooster. I can probably test however in the meantime somewhat. |
Beta Was this translation helpful? Give feedback.
-
I think I have all of this figured out! Just to recap my goal is to utilize the local USB microphone installed on my BirdNET Pi (lets call it RP1) PLUS add a second remote USB microphone located on a secondary Pi, not running BirdNET (lets call it RP2). Net result is to have multiple microphones simultaneously feeding the single instance of BirdNET audio so detections can be made originating from either microphone which are located at separate locations. In a perfect world I would want to have multiple independent "nodes" or instances of BirdNET running at each location somehow consolidated into a "master" BirdNET Pi. This however does seem to work but I just got it working and I need to let it run for a few days in production to make sure the wheels don't fall off or at least the steering wheel doesn't shake too much. So here is my final (pending tweaks) recipe. Many thanks to srd424 for his suggestions above. Secondary USB microphone connected to secondary Pi (RP2) Step 1 - Install the Raspberry Pi OS Lite (64-bit) as per the official BirdNET instructions but just do not install BirNET. Pro Tip - For reliability & speed purposes install the OS on an external SATA drive using a SATA to USB 3 adapter. A 512GB drive is only about $25-$30 on Amazon these days with the adapter cable running $8. Step 2 - (still operating on RP2) Install ffmpeg & mediamtx
Step 3 - Reconfigure your BirdNET Pi (RP1)
Everything should now be working! To verify hit the Spectrogram on the main BirdNET menu select each each of your RTSP feeds which should be showing in a drop down menu. As long as you hear audio from each you are in business. My secondary microphone is a couple of weeks out shipping from the UK but in the meantime I am going to monitor performance and make sure the microphone on RP1 performs just as well as when it was "natively" connected as now its looped back via RTSP. |
Beta Was this translation helpful? Give feedback.
-
Brilliant... Why not use "default" as Hardware... if the HW parameter float randomly, the default can be a solution... do you have these steps also for docker ? I do not want to install ffmpeg and mediamtx, easier and faster is to set up a docker compose file and fire them up.... I like BirdNet-Pi but it is a shame that it does not have a docker image, or the install script supports only Debian 11 and not 12... |
Beta Was this translation helpful? Give feedback.
-
Not sure if I ever tried "default"... Also when I was working with this that was before my "Docker awakening"... I would LOVE a docker version of all of this. |
Beta Was this translation helpful? Give feedback.
-
That's really great! Is there an impact on sound quality to perform this additional encoding to rtsp ? thanks ! |
Beta Was this translation helpful? Give feedback.
-
that looks interesting, I'm also playing with mediamtx & go2rtc, I've just replaced pulseaudio/arecord/ffmpeg(livestream) by one ffmpeg instance doing the wav recordings directly from alsa and also the opus audio encoding to mediamtx. That makes it more efficient to stream video and audio to frigate for instance. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the guide! I've adapted the code to use pcm : |
Beta Was this translation helpful? Give feedback.
-
Thanks for the guide! Here is the config I used for RPI Zero W2 with BOYA BY-LM40 microphone. ./mediamtx & |
Beta Was this translation helpful? Give feedback.
-
Thanks for this information. I use Birdnet-Pi in the docker. I set up AudioMoth as a USB Miktofon. For me this code works very well: Recently there is also BattyBirdnet-PI in the docker from @alexbelgium. Of course, I would like to use AudioMoth with a sample rate of 384kHz. Can someone say how I can use the full sample rate? |
Beta Was this translation helpful? Give feedback.
-
I still have a problem.
Mediamtx starts. But FFMPEG does not start or ends. I think someone has already described the problem here. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, I have some tools that I've built and have tested on multiple raspberry pi's and multiple USB mics/ sound cards that I think can help the people in this thread that just want to add a USB mic to an RPI and get an audio RTSP stream up and running that will survive reboots. I think this will help simplify:
I separated the tools into two projects as I think the usb-audio-mapper stands on it's own, but please take a look and try them out. I have it working on a few RPI's but have not tested beyond that. So far it has been more stable than anything I manually stitched together before. The ideal starting install situation would be with a dedicated freshly imaged Raspberry Pi that you have SSH access to and at least one USB microphone attached to it and nothing else running/ installed.
Any feedback, GH stars and contribution is welcome, but please do it via the respective project's issues (in other words - I will not handle support in this thread). I may create a dedicated post to this somewhere else, but as this thread is still somewhat alive and was the main place I looked when getting started, I figured there may still be some eyes on it. Essentially, I have a "microphone Pi" that I setup with multiple mics and used these tools to generate RTSP streams which I added to a dedicated pi running BirdNET-Pi which allows me to add more mics in other places which has resulted in way more species. PS - Shout out to @alexbelgium as they seem to be active in this thread and also adopting this project elsewhere so a GH alert might save you some time in troubleshooting or testing deployments if you find these tools helpful |
Beta Was this translation helpful? Give feedback.
-
Based on the text from the RTSP Stream box in the Advanced Settings page I don't think this is possible but thought I would ask anyway...
I have a second microphone in a different area of my yard I want to "merge" into the system. My idea is to place a second Pi with only a microphone in the secondary location and (TBD) figure out how to output it via an RTSP stream. If I could then ADD that source to BirdNET I would be in business.
Unfortunately again the text below seems clear that its an either or situation but it does say multiple RTSP streams can be added simultaneously so perhaps a couple of cheap Pi zeros as "audio servers" is the answer and simply not using the USB sound card on the BirdNET at all?
If you place an RTSP stream URL here, BirdNET-Pi will use that as its audio source.
Multiple streams are allowed but may have a impact on rPi performance.
Analyze ffmpeg CPU/Memory usage with top or htop if necessary.
To remove all and use the soundcard again, just delete the RTSP entries and click Save at the bottom.
Beta Was this translation helpful? Give feedback.
All reactions