In use on a Pi Zero W and tested on a Pi 3A+. Firefox, Safari, a phone browser and mobile data have not been tried.
Put a Pi and a camera in a nest box, plug it in, and watch from anywhere. That was the first thing this project was built to do, and this app is that program, complete.
You'll need
A Raspberry Pi and a camera (a NoIR camera to see at night)
A bird box to put them in, and a way to power the Pi
To try it first: just a computer, with a test pattern in place of the camera
No Pi yet?
Once you have the code (see Build it), run python birdbox_live.py --test-pattern on your computer. A moving test pattern takes the camera's place, and it streams, records and takes snapshots just like one.
Build it
This project assumes you've registered the device (see Getting Started).
Fit the camera to the Pi (with the Pi switched off), then put them in the box and plug in the power.
Install the SDK, which includes the video pieces: pip install thepihub. (A Pi Zero needs an extra step: see the SDK's README.)
Press View full code above and copy it into a file called birdbox_live.py, or press to copy a command that creates it.
If you use a NoIR camera, run pihub camera setup once: otherwise its picture looks pink.
Running it
Run it:
python birdbox_live.py
Then open your dashboard and press the play button on the camera.
To keep it running, pihub install birdbox_live.py starts it at boot and restarts it if it stops.
Try changing this
Change the picture size, for example python birdbox_live.py --size 1280x720.
Take a snapshot each morning and see how the light changes.
Make it start by itself when the Pi switches on: pihub install birdbox_live.py.
The educational bit
What do you think the birds do at different times of day? What would you like to catch on camera?
A NoIR camera can see in the dark with an invisible infrared light. Why is that kinder to the birds than a bright lamp?
Safety notes
Check the rules before you open or fit anything in a nest box. In some places, disturbing nesting wild birds is against the law, so fit the camera outside the nesting season, or follow the advice of a bird charity.
The Pi's power adapter and cable must stay dry. Use one that is made for the place it lives.
What next
See at night: use a NoIR camera with an infrared light. The Motion Trap shows the wiring.
Record only when something moves: that is the Motion Trap.
Want the same camera in 20 lines to copy? See Live camera.
Under the hood
The rest of this page is for when you want to know how it works.
What you get
A Bird Box section on your dashboard with the live picture and a row of icon buttons: start or stop the stream, take a snapshot, record, go full screen. Nothing runs until you ask: the camera starts when you press Start camera and stops when you stop, close the page or walk away.
Video that does not go through us
The video travels directly from the Pi to your browser (WebRTC, peer to peer), encoded on the Pi. ThePiHub only helps the two find each other. If a direct connection cannot be made, the dashboard says Live video needs a direct connection rather than pretending.
Small enough for a Pi Zero
On a Pi 3A+ at 640x480, 15 frames a second, the Pi's hardware H.264 encoder costs about 5% of the board, against about 56% for encoding on the CPU. The original Pi Zero W has streamed with the same approach at 56% of its single core. That difference is why the app uses the hardware encoder whenever it finds one (--software-encoder is there for Pis without one).
Snapshot and Record, on the Pi
Snapshot saves a JPEG in ~/thepihub-snapshots, from the running stream if there is one.
Record writes video to ~/thepihub-recordings from the same encode as the stream, so recording while you watch costs almost nothing extra. Closing the page never stops a recording. If the power fails mid-recording you lose at most the last second.
The video size, frame rate, bitrate and Orientation (Normal, Rotate 180°, Mirror or Flip, for a camera fitted the wrong way up; a quarter turn is not possible) are settings on the dashboard under Device Information > Camera, and the storage limits and the longest recording are under Device Information > Video. They are remembered on the Pi. A command-line flag such as --size 1280x720 wins over the remembered value.
Getting the files off the Pi
A Files section on the dashboard lists the Photos and Videos folders. Download one at a time, or "Download Selected" (every file starts checked) straight to your own machine - peer to peer, the same as the live picture, so it needs a direct connection. A file is only deleted off the Pi once its full byte count has actually arrived, and that toggle defaults on (the usual reason to open this section is running out of space on the card).
A NoIR camera looks pink
A NoIR camera shows a pink picture until it is told what it is. Run pihub camera setup once and it is remembered. If you skip that, the first time the camera starts with a strongly pink picture the dashboard raises one warning that points at the Camera is NoIR toggle.