camera deploy script and makefile and readme

This commit is contained in:
shinya 2026-05-21 12:31:08 +02:00
parent d7ad154d20
commit a5e100952c
3 changed files with 53 additions and 0 deletions

17
camera_example/Makefile Normal file
View File

@ -0,0 +1,17 @@
# Build on the device. Needs:
# apt install g++ pkg-config libcamera-dev libevent-dev libjpeg-turbo8-dev
# (Raspberry Pi OS Bullseye+; on older releases the turbo package is libjpeg-dev.)
CXX ?= g++
CXXFLAGS ?= -O2 -std=c++17 -pipe -Wall -Wextra
PKGS = libcamera libevent libevent_pthreads libturbojpeg
camera: camera.cpp event_loop.cpp event_loop.hpp
$(CXX) $(CXXFLAGS) camera.cpp event_loop.cpp \
$(shell pkg-config --cflags --libs $(PKGS)) -lpthread \
-o camera
clean:
rm -f camera
.PHONY: clean

27
camera_example/README.md Normal file
View File

@ -0,0 +1,27 @@
# camera_example
libcamera viewfinder (XRGB8888) -> libjpeg-turbo -> TCP. One client at a time.
Wire format: `[uint32 BE jpeg_size][jpeg_bytes]` repeating.
Knobs are constants at the top of `camera.cpp` (fps, quality, AF mode, lens
position, port, resolution).
## Build on the Pi
apt install g++ pkg-config libcamera-dev libevent-dev libjpeg-turbo8-dev
make
## Cross-build (x86 -> armv6l) on a Nix host
nix build
The resulting binary links against `/nix/store`, so it only runs on a Pi that
has those libs available (i.e. nix installed). For a vanilla Pi OS target,
use the Makefile on the device, or `./deploy.sh user@host` to rsync+build.
## Receive
Any TCP client that reads the framed JPEGs. Quick check:
nc <pi-ip> 5000 | ffplay -f mjpeg -

9
camera_example/deploy.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env sh
# Push sources to the Pi and build there.
# usage: ./deploy.sh me@10.91.51.165
set -eu
host=${1:-me@10.91.51.165}
rsync -az --delete --exclude=camera --exclude=result \
./ "$host:~/camera_example/"
ssh "$host" 'cd ~/camera_example && make -j"$(nproc)"'
echo "built at $host:~/camera_example/camera"