Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

Software/README.md gives the exact Pi commands for hardware H.264 renditions on :8082-8084 (GOP of 1 s or less, no B-frames), beside the MJPEG ustreamer #268

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

quill/arm:quill/262-software-readme-md-gives-the-exact-pi-co → main 2 commits fork 1 thread · 1 unresolved

  • Merged. quill/262-software-readme-md-gives-the-exact-pi-co was merged into main as befb8c7.

Review

Sign in to review this change.
1 file changed +104 −0
Software/README.md +104
@@ -770,6 +770,110 @@ The vision kit in `Software/vision` works against this server and stream:
770770 `SO101_ARM=http://<pi>:8101 SO101_CAMERA=http://<pi>:8080/stream`, then the
771771 `just vision-*` recipes. See `Software/vision/QUEST.md`.
772772
773 ### H.264 renditions on 8082-8084
774
775 Beside the MJPEG stream, the Pi 4's hardware encoder (`/dev/video11`, the
776 M2M encoder) serves camera 1 as H.264 in three sizes, one port each:
777
778 | Rung | Port | Size | fps | Bit rate |
779 | --- | --- | --- | --- | --- |
780 | 720p | 8082 | 1280x720 | 20 | ~1.5 Mb/s |
781 | 480p | 8083 | 848x480 | 15 | ~600 kb/s |
782 | 240p | 8084 | 432x240 | 10 | ~200 kb/s |
783
784 Each port answers `GET /h264` with a raw Annex-B stream: baseline profile
785 (`-profile:v 66`), so no B-frames; one keyframe a second (`-g` equals the
786 frame rate); and the SPS and PPS in front of every keyframe, so a viewer can
787 start at any of them. The widths are multiples of 16 for the encoder.
788
789 MJPEG on 8080 stays as it is and stays the fallback: the page uses it when
790 the browser has no WebCodecs or no H.264 picture comes. Each rung reads the
791 MJPEG stream from `127.0.0.1:8080`, since the camera can only be opened once,
792 so `so101-camera@1` must be running.
793
794 Each rung is one `ffmpeg` that serves one client at a time and exits when that
795 client leaves; systemd starts it again within half a second, and the relay
796 reconnects every second. A rung nobody is watching is idle: no client means
797 no MJPEG read and no encoding. It listens only on the Tailscale address, not
798 the LAN.
799
800 On the Pi, check that the encoder is there:
801
802 ```sh
803 sudo apt-get install ffmpeg
804 ffmpeg -hide_banner -encoders | grep h264_v4l2m2m
805 ```
806
807 Create one settings file per rung:
808
809 ```sh
810 sudo mkdir -p /etc/so101/h264
811 printf 'PORT=8082\nSIZE=1280:720\nFPS=20\nRATE=1500k\n' | sudo tee /etc/so101/h264/720p
812 printf 'PORT=8083\nSIZE=848:480\nFPS=15\nRATE=600k\n' | sudo tee /etc/so101/h264/480p
813 printf 'PORT=8084\nSIZE=432:240\nFPS=10\nRATE=200k\n' | sudo tee /etc/so101/h264/240p
814 ```
815
816 Then one template unit for all three:
817
818 ```sh
819 sudo tee /etc/systemd/system/so101-h264@.service <<'EOF'
820 [Unit]
821 Description=SO-101 camera 1, H.264 %i
822 [email protected] tailscaled.service
823 [email protected]
824
825 [Service]
826 EnvironmentFile=/etc/so101/h264/%i
827 ExecStart=/usr/bin/ffmpeg -hide_banner -loglevel warning -nostdin \
828 -fflags nobuffer -flags low_delay -probesize 32 -analyzeduration 0 \
829 -use_wallclock_as_timestamps 1 -f mpjpeg -i http://127.0.0.1:8080/stream \
830 -an -vf fps=${FPS},scale=${SIZE},format=yuv420p \
831 -c:v h264_v4l2m2m -profile:v 66 -b:v ${RATE} -g ${FPS} -bf 0 \
832 -bsf:v dump_extra=freq=keyframe -flush_packets 1 \
833 -f h264 -listen 1 http://100.89.95.68:${PORT}/h264
834 Restart=always
835 RestartSec=0.5
836
837 [Install]
838 WantedBy=multi-user.target
839 EOF
840 sudo systemctl daemon-reload
841 sudo systemctl enable --now so101-h264@720p so101-h264@480p so101-h264@240p
842 ```
843
844 Check each port from the app's side of the tailnet. A port serves one client
845 at a time, so check before the app is pointed at it, or while nobody is
846 watching that rung:
847
848 ```sh
849 curl -sI http://100.89.95.68:8080/stream | head -1 # MJPEG: HTTP/1.0 200 OK
850 for port in 8082 8083 8084; do
851 curl -s --max-time 3 -o /tmp/rung-$port.h264 http://100.89.95.68:$port/h264
852 ls -l /tmp/rung-$port.h264 # ~3 s of video, not empty
853 done
854 ```
855
856 `curl` ends with exit code 28 once its 3 s are up; that is expected. Where
857 `ffprobe` is installed, it shows the profile, the size, and the frame types.
858 Expect `Baseline`, the rung's size, `has_b_frames=0`, an `I` about every
859 second and nothing but `P` between:
860
861 ```sh
862 ffprobe -v error -show_entries stream=profile,width,height,has_b_frames /tmp/rung-8082.h264
863 ffprobe -v error -show_entries frame=pict_type -of csv=p=0 /tmp/rung-8082.h264 | uniq -c
864 ```
865
866 `sudo journalctl -u so101-h264@720p -f` shows a rung's errors. Then give
867 the app the three URLs, in the form `ARM_H264_1` expects:
868
869 ```
870 ARM_H264_1=720p=http://100.89.95.68:8082/h264,480p=http://100.89.95.68:8083/h264,240p=http://100.89.95.68:8084/h264
871 ```
872
873 The app reaches the Pi through the forge's egress list; 100.89.95.68:8082,
874 :8083 and :8084 are in `forge.json`'s `egress`. Camera 2 would need
875 another three ports, and those ports in the egress list too.
876
773877 ## Metrics
774878
775879 `GET /metrics.prom` on the relay answers Prometheus text (`text/plain; version=0.0.4`, `no-store`, with the usual

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs