RasPi OS Bullseye で Motion を動かす

はじめに

以前 RasPiZeroW で MotionEye を構築したが,環境整備のため RasPi2 で再構築する.

なお今回は諸般の事情により MotionEye は使わない.

Motion

New Camera Driver

New camera driver ということで,RaspberryPi OS Bullseye からカメラまわりの仕様が変更されている.この変更は RasPi のカメラモジュールを使う OSS に大打撃を与えているようす.

motion はまだこの新しい仕組みに完全対応していない.今後は非推奨となるが,raspi-config から legacy camera support を有効にして,Buster 用にビルドされた motion をインストールすれば一応は動くようにはなるらしい.なお,USB カメラであれば問題なく動きそう.

MotionEye は Python2 で書かれているが,Python2 は既に EOL を迎えている.まだ MotionEye 本家のソースは Python3 の対応もままならない状態なので,当然 Bullseye の変更にも追従できていない.いくつかの Python3 対応パッチも提案されてるものの,まだマージされていない状態.

ということで,諸々諦めて OSS の対応が追いつくまでは Bullseye に Motion だけ動かすことにする.

$ lsb_release --all; cat /sys/firmware/devicetree/base/model
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 11 (bullseye)
Release:	11
Codename:	bullseye
Raspberry Pi 2 Model B Rev 1.1

Motion

最新の 4.4.0 をインストールしていく.

Release Release 4.4.0 · Motion-Project/motion
Release Notes: 4.4.0 The documentation for the 4.4.0 release can be found in the Motion 4.4.0 Guide The following summarizes the changes implemented in version ...
$ wget https://github.com/Motion-Project/motion/releases/download/release-4.4.0/bullseye_motion_4.4.0-1_armhf.deb
$ sudo apt install ./bullseye_motion_4.4.0-1_armhf.deb

カメラの対応フォーマットを確認.YUYV より MJPG の方が軽そうなので,あとで motion.conf からフォーマットを指定する.

$ v4l2-ctl --device /dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT
	Type: Video Capture

	[0]: 'MJPG' (Motion-JPEG, compressed)
	[1]: 'YUYV' (YUYV 4:2:2)

細かい設定値はここを参照.

Motion

stream_preview_method を 3 に設定すると,WEB コントロール画面上に通常の画像と画像処理した動体検知画像を並べて表示できる.動体検知画像を確認しながら環境にあわせて threshold,noise_level などのパラメータを調整する.なお認証設定をしているとうまくストリーミングを表示できないかもしれない.

$ sudo vim /etc/motion/motion.conf
webcontrol_localhost off
stream_localhost off
stream_preview_method 3           # 通常の画像と動体検知画像を並べて表示
$ sudo systemctl restart motion.service

セキュリティ向上,パフォーマンス向上,帯域節約のためのささやかな抵抗をしておく.この辺りも設定はお好みで.

$ sudo vim /etc/motion/motion.conf
target_dir /path/to/capture/save/directory     # 適当にキャプチャ保存先を指定
video_params palette=8                         # MJPG を指定
auto_brightness 2                              # 設定値 1 が相性悪かったようなので 2 に設定
locate_motion_mode on                          # 動体検知エリアを四角く明示
text_scale 3                                   # 画像中の文字を少し大きく
stream_preview_method 1                        # 若干の帯域節約
stream_quality 20                              # ストリームの質を下げて帯域節約(20までなら使用に堪える)
stream_grey on                                 # グレースケールにして帯域節約
webcontrol_localhost off                       # WEBコントロール有効化
stream_localhost off                           # ストリーミング有効化
stream_auth_method 2                           # ダイジェスト認証有効化
stream_authentication ${UserName}:${Password}  # ダイジェスト認証の認証情報を設定
picture_quality 60                             # 画像保存時の IO を若干軽減
$ sudo systemctl restart motion.service

systemd で自動起動の設定をしたら完了.

$ sudo systemctl enable motion.service 

おわりに

MotionEye に比べると Motion 標準の WEB コンソールはやや使いにくいので,なんとか MotionEye 存続してほしいところ.README によると,残念ながらしばらくは開発が停滞しそうな感じ.後継者が見つかるまではマージ作業もなかなか進まないかもしれない.

Due to personal reasons I can no longer be actively involved with this project. If anyone is interested in taking it over, please contact me and we’ll work out together a hand-off plan.

https://github.com/ccrisan/motioneye/blob/dev/README.rst

コメント

タイトルとURLをコピーしました