Work Home lab & side projects

A Pi camera that previews live while recording 1080p

I wrote Pi camera scripts for a small live preview while recording 1080p video, plus night-sky timelapses and still-image bursts. The main fix was sizing the capture buffer for the padded camera frame.

Raspberry Pi camera module
Raspberry Pi camera module Photo: Raspberry Pi Foundation, CC BY-SA 4.0

Results

1088rows per frame the buffer had to fit
10 minper night timelapse run
5stills per burst

The problem

The first scripts recorded at low resolution behind an on-screen button. Raising the resolution to 1080p crashed the preview with a buffer write error, and once it ran, the full-size preview window covered the whole screen.

What I did

  • Traced the 1080p crash to the camera's frame padding and sized the capture buffer to the padded frame.
  • A recorder that captures 1080p at 30 fps while showing a scaled 640×480 preview, with Enter to record a one-minute clip and Ctrl+C to stop cleanly.
  • A night timelapse script: night exposure mode, fixed white balance, raised brightness, one frame per second, saved under a time-stamped name.
  • A burst mode that grabs a set of night-exposure stills into a time-stamped folder.
Pi camera scripts A camera module on a Raspberry Pi 4B feeds Python scripts built on picamera and pygame. They produce a live preview window scaled to 640 by 480, one-minute 1080p H.264 clips, a night timelapse at one frame a second, and bursts of night-exposure stills. Camera module on a Pi 4B Python picamera, pygame Live preview window scaled to 640 × 480 1080p clips H.264, one minute each Night timelapse one frame a second Burst stills night-exposure JPEGs
One camera, four scripts: preview, clips, timelapse and bursts.

What I took from it

The 1080p preview failed because the camera padded the frame to a multiple of 16 rows. The warning already described the mismatch. Correcting the buffer size fixed it.

Privacy