しゅれログ

備忘録です。

Raspberry Pi Zero 2 Wでカメラ libcamera-still

https://syurecat.hatenablog.com/entry/2022/06/25/201610

👆ではOSをレガシーに変更してraspstillを利用したけど、bullseyeからは raspstill から libcameraに移行したらしい

www.raspberrypi.com

@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 11 (bullseye)
Release:    11
Codename:   bullseye

メモリがなくて怒られる↓

heyanaohiro@raspberrypi:~ $ libcamera-still -r -o test.jpg
Preview window unavailable
[0:01:35.304669580] [704]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3544-22656360
[0:01:35.413496356] [705]  WARN RPI raspberrypi.cpp:1241 Mismatch between Unicam and CamHelper for embedded data usage!
[0:01:35.414759737] [705]  INFO RPI raspberrypi.cpp:1356 Registered camera /base/soc/i2c0mux/i2c@1/imx219@10 to Unicam device /dev/media3 and ISP device /dev/media0
[0:01:35.415967806] [704]  INFO Camera camera.cpp:1029 configuring streams: (0) 1640x1232-YUV420
[0:01:35.417044417] [705]  INFO RPI raspberrypi.cpp:760 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 1640x1232-SBGGR10_1X10 - Selected unicam format: 1640x1232-pBAA
[0:01:40.550753473] [704]  INFO Camera camera.cpp:1029 configuring streams: (0) 3280x2464-YUV420 (1) 3280x2464-SBGGR10_CSI2P
[0:01:40.556287991] [705]  INFO RPI raspberrypi.cpp:760 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 3280x2464-SBGGR10_1X10 - Selected unicam format: 3280x2464-pBAA
[0:01:40.660953470] [705] ERROR V4L2 v4l2_videodevice.cpp:1211 /dev/video14[14:cap]: Unable to request 1 buffers: Cannot allocate memory
[0:01:40.661161439] [705] ERROR RPI raspberrypi.cpp:1008 Failed to allocate buffers
ERROR: *** failed to start camera ***

/boot/config.txtにdtoverlay=cma,cma-128を追加

heyanaohiro@raspberrypi:~ $ libcamera-still -o test.jpg
Preview window unavailable
[0:00:37.601972848] [699]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3544-22656360
[0:00:37.760509671] [700]  WARN RPI raspberrypi.cpp:1241 Mismatch between Unicam and CamHelper for embedded data usage!
[0:00:37.761834151] [700]  INFO RPI raspberrypi.cpp:1356 Registered camera /base/soc/i2c0mux/i2c@1/imx219@10 to Unicam device /dev/media3 and ISP device /dev/media1
[0:00:37.763132588] [699]  INFO Camera camera.cpp:1029 configuring streams: (0) 1640x1232-YUV420
[0:00:37.763977015] [700]  INFO RPI raspberrypi.cpp:760 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 1640x1232-SBGGR10_1X10 - Selected unicam format: 1640x1232-pBAA
[0:00:42.900641649] [699]  INFO Camera camera.cpp:1029 configuring streams: (0) 3280x2464-YUV420 (1) 3280x2464-SBGGR10_CSI2P
[0:00:42.902535451] [700]  INFO RPI raspberrypi.cpp:760 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 3280x2464-SBGGR10_1X10 - Selected unicam format: 3280x2464-pBAA
Still capture image received

撮れてる

CMAとは gihyo.jp

UDPでストリーミングもできるらしい。

raspberrypi:~ $ libcamera-vid -t 0 --inline -o udp://[クライアントのIPaddr]:9999

クライアントでvlc

$vlc udp://@:9999 :demux=h264

画質はイマイチ。設定を試行錯誤していく必要がありそう?

ドキュメントを読むと色々できるっぽい↓ www.raspberrypi.com

v4l2/ffmepg?にもトライしてみたけどうまく行かなかったので要勉強 (プログラムから呼び出したい)

[video4linux2,v4l2 @ 0x1a20d20] ioctl(VIDIOC_G_PARM): Inappropriate ioctl for device
[video4linux2,v4l2 @ 0x1a20d20] Time per frame unknown
[video4linux2,v4l2 @ 0x1a20d20] ioctl(VIDIOC_STREAMON): Invalid argument
/dev/video0: Invalid argument

と思ったけど、libcameraはv4l2の発展系?みたいなのでOpenっぽいし、これはこれでいいか(?)

libcamera.org