はじめに
猫の監視体制を強化すべくウェブカメラを作ろうと思う。
その用途にはustreamerが使えるらしい。
このアプリはOpemEmbedded-Core互換のレシピが提供されていないようなので今回は自作してみる。
ビルドホストはUbuntu26.04を使用する。
また、動作確認のためターゲットとしてラズベリーパイ(初代)に、UVCのカメラを接続したものを使用する。
環境構築
作業ディレクトリ
~/yocto/wrynoseを作業ディレクトリとする。
$ mkdir -p ~/yocto/wrynose $ cd ~/yocto/wrynose
bitbake-setupの導入
bitbake-setupをインストールしていない場合は「bitbake-setupをpip3でインストールする」を参考にインストールする。
作業環境(=セットアップ)の作成
bitbake-setup initを実行してセットアップを作成する
setup-dir-nameを「poky-wrynose-webcam」に設定する。
$ source ~/yocto/wrynose/yocto-venv/bin/activate
$ bitbake-setup \
init --non-interactive poky-wrynose poky distro/poky machine/qemuarm64 \
--setup-dir-name poky-wrynose-webcam
$ deactivate
bitbakeや、関連ツールが参照するPythonのライブラリの参照に支障をきたすケースがあるのでPython仮想環境から抜けておく。
BitBake環境を設定する
$ source bitbake-builds/poky-wrynose-webcam/build/init-build-env
meta-raspberrypiの追加
$ bitbake-layers layerindex-fetch -f ../layers meta-raspberrypi
MACHINEの変更
MACHINEをRaspberry Pi向けに変更する。
$ bitbake-config-build enable-fragment machine/raspberrypi
rootルートログインの許可
現在のPokyはdebug-tweaks相当の機能はデフォルトでオフになっているので、これを有効化する。
$ bitbake-config-build enable-fragment core/yocto/root-login-with-empty-password
ビルド
core-image-baseをビルドする。
$ bitbake core-image-base
ustreamのレシピ化
レイヤの作成
作業用レイヤをmeta-webcamとして作成する。
$ bitbake-layers create-layer -a -p 10 ../layers/meta-webcam
レシピの雛形の作成
ustreamerのレシピの雛形を作成する。
$ recipetool create https://github.com/pikvm/ustreamer.git
雛形の確認
生成された時点での雛形は下記。
# Recipe created by recipetool # This is the basis of a recipe and may need further editing in order to be fully functional. # (Feel free to remove these comments when editing.) # WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is # your responsibility to verify that the values are complete and correct. LICENSE = "GPL-3.0-only" LIC_FILES_CHKSUM = "file://LICENSE;md5=d32239bcb673463ab874e80d47fae504" SRC_URI = "git://github.com/pikvm/ustreamer.git;protocol=https;branch=master" # Modify these as desired PV = "1.0+git" SRCREV = "296639a2acd06f8f39131e2d27170caccf8fd63a" # NOTE: the following library dependencies are unknown, ignoring: systemd event_pthreads gpiod event speexdsp jansson opus # (this is based on recipes that have previously been built and packaged) # NOTE: some of these dependencies may be optional, check the Makefile and/or upstream documentation DEPENDS = "libbsd libjpeg-turbo alsa-lib" # NOTE: this is a Makefile-only piece of software, so we cannot generate much of the # recipe automatically - you will need to examine the Makefile yourself and ensure # that the appropriate arguments are passed in. do_configure () { # Specify any needed configure commands here : } do_compile () { # You will almost certainly need to add additional arguments here oe_runmake } do_install () { # This is a guess; additional arguments may be required oe_runmake install 'DESTDIR=${D}' }
レイヤへの配置
作成したレシピの雛形をレイヤに配置する。
$ mkdir -p ../layers/meta-webcam/recipes-app/ustreamer $ mv ustreamer_git.bb ../layers/meta-webcam/recipes-app/ustreamer/
ビルド
ビルドを実行してみる。
pkg-configのエラー
pkg-configがsysrootに存在しないためエラーになっている。
| Makefile:45: *** "No pkg-config found in /home/mickey/yocto/wrynose/bitbake-builds/poky-wrynose-webcam/build/tmp/sysroots-uninative/x86_64-linux/usr/bin:/home/mickey/yocto/wrynose/bitbake-builds/poky-wrynose-webcam/layers/openembedded-core/scripts:/home/mickey/yocto/wrynose/bitbake-builds/poky-wrynose-webcam/build/tmp/work/arm1176jzfshf-vfp-poky-linux-gnueabi/ustreamer/1.0+git/recipe-sysroot-native/usr/bin/arm-poky-linux-gnueabi:/home/mickey/yocto/wrynose/bitbake-builds/poky-wrynose-webcam/build/tmp/work/arm1176jzfshf-vfp-poky-linux-gnueabi/ustreamer/1.0+git/recipe-sysroot/usr/bin/crossscripts:/home/mickey/yocto/wrynose/bitbake-builds/poky-wrynose-webcam/build/tmp/work/arm1176jzfshf-vfp-poky-linux-gnueabi/ustreamer/1.0+git/recipe-sysroot-native/usr/sbin:/home/mickey/yocto/wrynose/bitbake-builds/poky-wrynose-webcam/build/tmp/work/arm1176jzfshf-vfp-poky-linux-gnueabi/ustreamer/1.0+git/recipe-sysroot-native/usr/bin:/home/mickey/yocto/wrynose/bitbake-builds/poky-wrynose-webcam/build/tmp/work/arm1176jzfshf-vfp-poky-linux-gnueabi/ustreamer/1.0+git/recipe-sysroot-native/sbin:/home/mickey/yocto/wrynose/bitbake-builds/poky-wrynose-webcam/build/tmp/work/arm1176jzfshf-vfp-poky-linux-gnueabi/ustreamer/1.0+git/recipe-sysroot-native/bin:/home/mickey/yocto/wrynose/bitbake-builds/poky-wrynose-webcam/layers/bitbake/bin:/home/mickey/yocto/wrynose/bitbake-builds/poky-wrynose-webcam/build/tmp/hosttools". Stop.
下記で解決できる。
inherit pkgconfig
libeventのエラー
次は下記のエラーが発生する。これはsysrootにlibeventパッケージ関連のファイルがないために発生する。
| ustreamer/http/mime.c:27:10: fatal error: event2/util.h: No such file or directory | 27 | #include <event2/util.h> | | ^~~~~~~~~~~~~~~
依存関係にlibeventを追加すると解決できる。
DEPENDS += "libevent"
インストール場所のエラー
デフォルトのままでは/usr/localにインストールされる。これはOSのパッケージ管理外のソースをビルドする場合の一般的な挙動。
ERROR: ustreamer-1.0+git-r0 do_package: QA Issue: ustreamer: Files/directories were installed but not shipped in any package: /usr/local/share /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man1/ustreamer-dump.1.gz /usr/local/share/man/man1/ustreamer.1.gz /usr/local/bin/ustreamer /usr/local/bin/ustreamer-dump Please set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.
Yocto Projectのビルド環境ではパッケージを作成するので、/usrに入るようにする。
EXTRA_OEMAKE += "PREFIX=${prefix}"
最終的なレシピ
最終的なustreamer_git.bbは以下のようになる。
LICENSE = "GPL-3.0-only" LIC_FILES_CHKSUM = "file://LICENSE;md5=d32239bcb673463ab874e80d47fae504" SRC_URI = "git://github.com/pikvm/ustreamer.git;protocol=https;branch=master" inherit pkgconfig PV = "1.0+git" SRCREV = "296639a2acd06f8f39131e2d27170caccf8fd63a" DEPENDS = "libjpeg-turbo alsa-lib libevent libbsd" EXTRA_OEMAKE += "PREFIX=${prefix}" do_configure () { : } do_compile () { oe_runmake } do_install () { oe_runmake install 'DESTDIR=${D}' }
local.confの修正
local.confに以下を追加してイメージにustreamerを追加する。
IMAGE_INSTALL:append = " ustreamer"
イメージのビルド
イメージをビルドする。
$ bitbake core-image-base
動作確認
ラズベリーパイにログインして以下のコマンドでustreamerを実行する。
$ ustreamer --device=/dev/video0 --format=yuyv --resolution=320x240 --host=0.0.0.0 --desired-fps=15
core-image-baseではデフォルトでzeroconfが有効化されているので、「http://raspberrypi.local:8080/stream」でアクセスできる。
まとめ
今回はustreamerをレシピ化した。
recipetool createによりレシピの雛形を作成できるが、そのままでは動かないこともあるといういい実例になった。
一からレシピを自作するよりも非常に効率が良いということがわかったと思う。