AUDIO STREAMING UPDATE 2020 SEE AT THE END.
My version of a RaspberryPi Bird Box
On the Raspberry Pi Homepage I found a tutorial about a bird box watching camera. As I had a Pi NoIR camera and a Raspberry Pi 2 at hand for no other purposes, I started this project in mid February 2017. I hoped this won't be to late for some birds to find a home in the box.
Here I'll describe the several steps that led me to the final box...
As the Box is (of course) located outside, and the Pi too, a weather-proofed case was needed. I found the
To fit all components (Pi, wiring, WiFi and microphone connectors) into the case a quick (and dirty) hack was done, as you can see in the pictures. Thanks to an adapting plate (see below) the case suits well to the Pi.
But the WiFi antenna and the USB connector stick out. The only solid connection to the outer world is a four lines shielded wire.
- 2 lines are for 5 V power
- 1 line is Serial TX for data from the Pi
- 1 line is Serial RX for data to the Pi
- Shield is GND
The serial lines were chosen to get access to the hidden Raspberry Pi, if wireless access fails.
The only disadvantage of the small case was: the microUSB supply plug didn't fit (even a small angled one, but I knew that before). So I soldered two small wires to the bottom side of the PI's PCB at the socket pads.
In the end all openings (USB, wirings for camera, LEDs and supply voltage) were sealed with silicone for outside purposes and the case screwed onto the bird box.
In the beginning I asked myself to use either a RPi3 with WiFi onboard or an older RPi2 with an external WLAN stick. After a few measurements of the WiFi range I decided to order a new WLAN USB stick with a real antenna to use it with the RPi2.
It's dark inside the box. Two Infrared (IR) LEDs are used to illuminate what's happening with the birds. I sanded down the LEDs a bit to get a more diffuse light. And they are not directly pointing to the birds but to the walls of the bird box.
I think it is a good idea not to power the IR-LEDs all the time. There may be times no birds are living in the box or the whole streaming/pi/camera stuff is down due to reasonsTM. So I added a NPN-transistor to the two LEDs in line, to be triggered by a GPIO of the Pi.
From internet sources about streaming out of a bird box I found they all were using the video stream only. What about sound? To get the option of experimenting with and later adding sound from the birds inside the box, I mounted a small USB ready microphone into the box too.
As the Pi has no sound/mic input, I bought one of this kind:
So far, I have no idea, if and how it'll work. But the ALSA recording tool that comes with the Raspian distro indicated different sound levels from the mic though nothing useful was recorded yet.
As I hadn't have much time for a proper assembly after business hours and family needs, it became really a rather quick and dirty hack. See the following pictures...
###The completed case###
The breakthrough for the camera cable and the LED supply
The Raspberry Pi fits
USB dongles (WiFi, microphone) sticking out
Wired RPi in the case on the bird box
###The box electrics###
Pi NoIR camera, IR LEDs and microphone on a single board for the bird box's ceiling
Electronics mounted in the bird box
Wires (mic, LEDs, cam) sticking out of the box.
It streams ...
... under construction!
For some tests I used streaming to YouTube with following command, which basics I found in Part 2 of the Bird Box Worksheets.
raspivid -o - -t 0 -w 480 -h 360 -vf -hf -sa -100 -br 60 -rot 270 -fps 25 -b 400000 -g 75 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 75 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/<access-key-here>
Major changes are
-w 480 -h 360 -vf -hf -sa -100 -br 60 -rot 270 -fps 25 -b 400000 -g 75
where I reduced the video width and height to 480 by 360 pixels, vertically and horizontally flipped the image, reduced the colour saturation to get a greyscaled picture, enhanced brightness, rotated the image by 270 degrees for correct orientation, fixed the frames per second to 25, limited the bandwidth to 400 kbps, and told the codec to transmit a full image every 75 frames (g 75/25 fps = 3 s).
I really didn't notice the entry of birds. Today (mid June 2017) my son came in and shouted "Dad, turn the bird cam on". And yes there were some just hatched titmice with one of their parents in the box.
When bandwidth and power constraints allow streaming, the system will be turned on.
Actual links to the streams will be published via my Twitter account with HashTag #BirdCamDL6DBN.
Find a playlist of streamed videos
After two bird seasons I thought it might be interesting to monitor temperature and humidity inside the bird box. So I added a combined sensor DHT22 into the box. Unfortunately the measurements aren't still public available and overlayed into the video.
It took another two bird seasons to get audio from mic into the stream (there were too many other intersting projects). Here is the code I put together after diving into several RasPi communities to get inspiration and a lot of experimenting what works for me and what doesn't:
raspivid -o - -t 0 -w 480 -h 360 -vf -hf -sa -100 -br 60 -rot 270 -fps 25 -b 400000 -g 75 | ffmpeg -re -thread_queue-size 4096 -itsoffset 1 -ar 22050 -ac 2 -f alsa -thread_queue-size 4096 -itsoffset 0 -ac 2 -i plughw:CARD=AK5371,DEV=0 -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 75 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/<access-key-here>
ffmpeg -re -thread_queue-size 4096 -ar 22050 -ac 2 -f alsa -thread_queue-size 4096 -ac 2 -i plughw:CARD=AK5371,DEV=0
I added the audio source
which I found with
Replace it with your audio source.
I noticed the sample rate should be at least
otherwise the bird's sound maybe to high for proper sampling. And occasionally there occured a buffer error, so I increased the buffer size
As video and audio were off-sync, I played a bit with the settings of an offset
Please respect all licenses.
All my additions to the project or own creations for the project are for use under the
Beer-Ware License (Revision 42.fs): "email@example.com made this stuff. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer (or another drink I like) in return."
Frank Sperber (DL6DBN) with thanks to PHK for writing down this beautiful kind of license.
as of: May 2020