App - run it as it is

Bird Box Live: a camera you can leave running

Source:
apps/birdbox_live.py
Widgets:
Camera, Gauge, Files
Hardware:
A Raspberry Pi and a camera (a NoIR camera for night)
Status:
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.

Bird Box Live: a camera you can leave running

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.

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 and bitrate 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.

Running it

Register the Pi the first time (pihub setup, or --register TOKEN with a token from the dashboard's Register a device button), then just run it:

python apps/birdbox_live.py

No camera to hand? --test-pattern streams, records and takes snapshots from a moving test pattern. To have it start at boot and restart itself if it stops, pihub install apps/birdbox_live.py registers it and installs it as a service in one go.

Where to go next

For a version that records only when something moves, see Motion Trap. For the same camera in 20 lines to copy, see Put a camera on your dashboard.

← Back to Projects