From 0d7374c45d80383e5b8f9e95c97e655f8bd4cb12 Mon Sep 17 00:00:00 2001 From: Nate Contino Date: Fri, 1 Mar 2024 10:11:12 -0500 Subject: [PATCH 1/4] update libcamera build instructions --- .../camera/rpicam_apps_building.adoc | 217 +++++++++++------- .../camera/rpicam_apps_packages.adoc | 12 +- 2 files changed, 143 insertions(+), 86 deletions(-) diff --git a/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc b/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc index 87dff3b2bc..cb50994266 100644 --- a/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc +++ b/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc @@ -1,172 +1,235 @@ === Building `libcamera` and `rpicam-apps` -Building `libcamera` and `rpicam-apps` for yourself can bring the following benefits. +Build `libcamera` and `rpicam-apps` for yourself for the following benefits: -* You can pick up the latest enhancements and features +* You can pick up the latest enhancements and features. -* `rpicam-apps` can be compiled with extra optimisation for Raspberry Pi 3 and Raspberry Pi 4 devices running a 32-bit OS +* `rpicam-apps` can be compiled with extra optimisation for Raspberry Pi 3 and Raspberry Pi 4 devices running a 32-bit OS. -* You can include the various optional OpenCV and/or TFLite post-processing stages (or add your own) +* You can include optional OpenCV and/or TFLite post-processing stages, or add your own. * You can customise or add your own applications derived from `rpicam-apps` -NOTE: When building on a Raspberry Pi with 1GB RAM or less, there is a risk that the device may run out of swap and fail. We recommend either increasing the amount of swap, or building with fewer threads (the `-j` option to `ninja` and to `make`). +==== Building `rpicam-apps` without building `libcamera` -==== Building `rpicam-apps` without rebuilding `libcamera` - -You can rebuild `rpicam-apps` _without_ first rebuilding the whole of `libcamera` and `libepoxy`. If you do not need support for the GLES/EGL preview window then `libepoxy` can be omitted entirely. Raspberry Pi OS Lite users must be sure to use `-Denable_egl=false` when running `meson setup` later: +To build `rpicam-apps` without first rebuilding `libcamera` and `libepoxy`, install `libcamera`, `libepoxy` and their dependencies with `apt`: +[source,console] ---- -sudo apt install -y libcamera-dev libjpeg-dev libtiff5-dev libpng-dev +$ sudo apt install -y libcamera-dev libepoxy-dev libjpeg-dev libtiff5-dev libpng-dev ---- -All other users should execute: +TIP: If you do not need support for the GLES/EGL preview window, omit `libepoxy-dev`. + +To use the Qt preview window, install the following additional dependencies: +[source,console] ---- -sudo apt install -y libcamera-dev libepoxy-dev libjpeg-dev libtiff5-dev libpng-dev +$ sudo apt install -y qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5 ---- -If you want to use the Qt preview window: +For xref:camera_software.adoc#libav-integration-with-rpicam-vid[`libav`] support in `rpicam-vid`, install the following additional dependencies: +[source,console] ---- -sudo apt install -y qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5 +$ sudo apt install libavcodec-dev libavdevice-dev libavformat-dev libswresample-dev ---- -If you want xref:camera_software.adoc#libav-integration-with-rpicam-vid[`libav`] support in `rpicam-vid`, additional libraries must be installed: +If you run Raspberry Pi OS Lite, install `git`: +[source,console] ---- -sudo apt install libavcodec-dev libavdevice-dev libavformat-dev libswresample-dev +$ sudo apt install -y git ---- -Now proceed directly to the instructions for xref:camera_software.adoc#building-rpicam-apps[building `rpicam-apps`]. Raspberry Pi OS Lite users should check that git is installed first (`sudo apt install -y git`). +Next, xref:camera_software.adoc#building-rpicam-apps[build `rpicam-apps`]. ==== Building `libcamera` -Rebuilding `libcamera` from scratch should be necessary only if you need the latest features that may not yet have reached the `apt` repositories, or if you need to customise its behaviour in some way. +NOTE: Only build `libcamera` from scratch if you need custom behaviour or the latest features that have not yet reached `apt` repositories. -First install all the necessary dependencies for `libcamera`. Raspberry Pi OS Lite users will first need to install the following additional packages if they have not done so previously: +[NOTE] +====== +If you run Raspberry Pi OS Lite, begin by installing the following packages: +[source,console] ---- -sudo apt install -y python3-pip git python3-jinja2 +$ sudo apt install -y python3-pip git python3-jinja2 ---- +====== -All users should then install the following: +First, install the following `libcamera` dependencies: +[source,console] ---- -sudo apt install -y libboost-dev -sudo apt install -y libgnutls28-dev openssl libtiff5-dev pybind11-dev -sudo apt install -y qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5 -sudo apt install -y meson cmake -sudo apt install -y python3-yaml python3-ply +$ sudo apt install -y libboost-dev +$ sudo apt install -y libgnutls28-dev openssl libtiff5-dev pybind11-dev +$ sudo apt install -y qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5 +$ sudo apt install -y meson cmake +$ sudo apt install -y python3-yaml python3-ply +$ sudo apt install -y libglib2.0-dev libgstreamer-plugins-base1.0-dev ---- -In the `meson` commands below we have enabled the gstreamer plugin. If you do not need this, you can set `-Dgstreamer=disabled` instead and the next pair of dependencies will not be required. But if you do leave _gstreamer_ enabled, then you will need the following: +Now we're ready to build `libcamera` itself. + +Download a local copy of Raspberry Pi's fork of `libcamera` from GitHub: +[source,console] ---- -sudo apt install -y libglib2.0-dev libgstreamer-plugins-base1.0-dev +$ git clone https://github.com/raspberrypi/libcamera.git ---- -Now we can check out and build `libcamera` itself. We check out Raspberry Pi's fork of `libcamera`, which tracks the official repository but lets us control exactly when we pick up new features. +Navigate into the root directory of the repository: +[source,console] ---- -cd -git clone https://github.com/raspberrypi/libcamera.git -cd libcamera +$ cd libcamera ---- -Now run: +Next, run `meson` to configure the build environment: +[source,console] ---- -meson setup build --buildtype=release -Dpipelines=rpi/vc4,rpi/pisp -Dipas=rpi/vc4,rpi/pisp -Dv4l2=true -Dgstreamer=enabled -Dtest=false -Dlc-compliance=disabled -Dcam=disabled -Dqcam=disabled -Ddocumentation=disabled -Dpycamera=enabled +$ meson setup build --buildtype=release -Dpipelines=rpi/vc4,rpi/pisp -Dipas=rpi/vc4,rpi/pisp -Dv4l2=true -Dgstreamer=enabled -Dtest=false -Dlc-compliance=disabled -Dcam=disabled -Dqcam=disabled -Ddocumentation=disabled -Dpycamera=enabled ---- -To complete the `libcamera` build, use: +NOTE: You can disable the `gstreamer` plugin by replacing `-Dgstreamer=enabled` with `-Dgstreamer=disabled` during the `meson` build configuration. If you disable `gstreamer`, there is no need to install the `libglib2.0-dev` and `libgstreamer-plugins-base1.0-dev` dependencies. +Now, you can build `libcamera` with `ninja`: + +[source,console] ---- -ninja -C build # use -j 2 on Raspberry Pi 3 or earlier devices -sudo ninja -C build install +$ ninja -C build ---- -NOTE: At the time of writing, `libcamera` does not yet have a stable binary interface. Therefore, if you have rebuilt `libcamera`, we recommend continuing and rebuilding `rpicam-apps` from scratch too. +Finally, run the following command to install your freshly-built `libcamera` binary: -==== Building `libepoxy` +[source,console] +---- +$ sudo ninja -C build install +---- -Rebuilding `libepoxy` should not normally be necessary as this library changes only very rarely. If you do want to build it from scratch, however, please follow the instructions below. +TIP: On devices with 1GB of memory or less, the build may exceed available memory. Append the `-j 1` flag to `ninja` commands to limit the build to a single process. This should prevent the build from exceeding available memory on devices like the Raspberry Pi Zero and the Raspberry Pi 3. -Start by installing the necessary dependencies. +`libcamera` does not yet have a stable binary interface. Always build `rpicam-apps` after you build `libcamera`. + +==== Building `rpicam-apps` +First fetch the necessary dependencies for `rpicam-apps`. + +[source,console] ---- -sudo apt install -y libegl1-mesa-dev +$ sudo apt install -y cmake libboost-program-options-dev libdrm-dev libexif-dev +$ sudo apt install -y meson ninja-build ---- -Next, check out and build `libepoxy`. +Download a local copy of Raspberry Pi's fork of `rpicam-apps` from GitHub: +[source,console] ---- -cd -git clone https://github.com/anholt/libepoxy.git -cd libepoxy -mkdir _build -cd _build -meson -ninja -sudo ninja install +$ git clone https://github.com/raspberrypi/rpicam-apps.git ---- -==== Building `rpicam-apps` +Navigate into the root directory of the repository: -First fetch the necessary dependencies for `rpicam-apps`. +[source,console] +---- +$ cd rpicam-apps +---- + +For desktop-based operating systems like Raspberry Pi OS, configure the `rpicam-apps` build with the following `meson` command: + +[source,console] +---- +$ meson setup build -Denable_libav=true -Denable_drm=true -Denable_egl=true -Denable_qt=true -Denable_opencv=false -Denable_tflite=false +---- +For headless operating systems like Raspberry Pi OS Lite, configure the `rpicam-apps` build with the following `meson` command: + +[source,console] ---- -sudo apt install -y cmake libboost-program-options-dev libdrm-dev libexif-dev -sudo apt install -y meson ninja-build +$ meson setup build -Denable_libav=false -Denable_drm=true -Denable_egl=false -Denable_qt=false -Denable_opencv=false -Denable_tflite=false ---- -The `rpicam-apps` build process begins with the following: +[TIP] +====== + +* Use `-Dneon_flags=armv8-neon` to enable optimisations for 32-bit OSes on Raspberry Pi 3 or Raspberry Pi 4. +* Use `-Denable_opencv=true` if you have installed OpenCV and wish to use OpenCV-based post-processing stages. +* Use `-Denable_tflite=true` if you have installed TensorFlow Lite and wish to use it in post-processing stages. + +====== +You can now build `rpicam-apps` with the following command: + +[source,console] ---- -cd -git clone https://github.com/raspberrypi/rpicam-apps.git -cd rpicam-apps +$ meson compile -C build ---- -At this point you will need to run `meson setup` after deciding what extra flags to pass it. The valid flags are: +TIP: On devices with 1GB of memory or less, the build may exceed available memory. Append the `-j 1` flag to `meson` commands to limit the build to a single process. This should prevent the build from exceeding available memory on devices like the Raspberry Pi Zero and the Raspberry Pi 3. -* `-Dneon_flags=armv8-neon` - you may supply this when building for Raspberry Pi 3 or Raspberry Pi 4 devices running a 32-bit OS. Some post-processing features may run more quickly. +Finally, run the following command to install your freshly-built `rpicam-apps` binary: -* `-Denable_libav=true` or `-Denable_libav=false` - this enables or disables the libav encoder integration. +[source,console] +---- +$ sudo meson install -C build +---- -* `-Denable_drm=true` or `-Denable_drm=false` - this enables or disables the DRM/KMS preview rendering. This is what implements the preview window when a desktop environment is not running. +Open a new terminal window after installation to ensure that you use the new binary. -* `-Denable_egl=true` or `-Denable_egl=false` - this enables or disables the desktop environment-based preview. You should disable this if your system does not have a desktop environment installed. +Finally, follow the `dtoverlay` and display driver instructions in the xref:camera_software.adoc#getting-started[Getting Started section]. -* `-Denable_qt=true` or `-Denable_qt=false` - this enables or disables support for the Qt-based implementation of the preview window. You should disable it if you do not have a desktop environment installed, or if you have no intention of using the Qt-based preview window. The Qt-based preview is normally not recommended because it is computationally very expensive, however it does work with X display forwarding. +==== Building `libepoxy` -* `-Denable_opencv=true` or `-Denable_opencv=false` - you may choose one of these to force OpenCV-based post-processing stages to be linked (or not). If you enable them, then OpenCV must be installed on your system. Normally they will be built by default if OpenCV is available. +Rebuilding `libepoxy` should not normally be necessary as this library changes only very rarely. If you do want to build it from scratch, however, please follow the instructions below. -* `-Denable_tflite=true` or `-Denable_tflite=false` - choose one of these to enable TensorFlow Lite post-processing stages (or not). By default they will not be enabled. If you enable them then TensorFlow Lite must be available on your system. Depending on how you have built and/or installed TFLite, you may need to tweak the `meson.build` file in the `post_processing_stages` directory. +Start by installing the necessary dependencies. -For Raspberry Pi OS users we recommend the following `meson setup` command: +[source,console] +---- +$ sudo apt install -y libegl1-mesa-dev +---- +Next, download a local copy of the `libepoxy` repository from GitHub: + +[source,console] +---- +$ git clone https://github.com/anholt/libepoxy.git +---- + +Navigate into the root directory of the repository: + +[source,console] ---- -meson setup build -Denable_libav=true -Denable_drm=true -Denable_egl=true -Denable_qt=true -Denable_opencv=false -Denable_tflite=false +$ cd libepoxy ---- -and for Raspberry Pi OS Lite users: +Create a build directory at the root level of the repository, then navigate into that directory: +[source,console] ---- -meson setup build -Denable_libav=false -Denable_drm=true -Denable_egl=false -Denable_qt=false -Denable_opencv=false -Denable_tflite=false +$ mkdir _build +$ cd _build ---- -In both cases, consider `-Dneon_flags=armv8-neon` if you are using a 32-bit OS on a Raspberry Pi 3 or Raspberry Pi 4. Consider `-Denable_opencv=true` if you have installed OpenCV and wish to use OpenCV-based post-processing stages. Finally also consider `-Denable_tflite=true` if you have installed TensorFlow Lite and wish to use it in post-processing stages. +Next, run `meson` to configure the build environment: -After executing the `meson setup` command of your choice, the whole process concludes with the following: +[source,console] +---- +$ meson +---- + +Now, you can build `libexpoxy` with `ninja`: +[source,console] ---- -meson compile -C build # use -j1 on Raspberry Pi 3 or earlier devices -sudo meson install -C build -sudo ldconfig # this is only necessary on the first build +$ ninja ---- -NOTE: If you are using an image where `rpicam-apps` have been previously installed as an `apt` package, and you want to run the new `rpicam-apps` executables from the same terminal window where you have just built and installed them, you may need to run `hash -r` to be sure to pick up the new executables over the system supplied ones. +Finally, run the following command to install your freshly-built `libepoxy` binary: -Finally, if you have not already done so, please be sure to follow the `dtoverlay` and display driver instructions in the xref:camera_software.adoc#getting-started[Getting Started section] (and rebooting if you changed anything there). +[source,console] +---- +$ sudo ninja install +---- diff --git a/documentation/asciidoc/computers/camera/rpicam_apps_packages.adoc b/documentation/asciidoc/computers/camera/rpicam_apps_packages.adoc index 3229ed554d..2652445a47 100644 --- a/documentation/asciidoc/computers/camera/rpicam_apps_packages.adoc +++ b/documentation/asciidoc/computers/camera/rpicam_apps_packages.adoc @@ -1,12 +1,12 @@ === `libcamera` and `rpicam-apps` packages -A number of `apt` packages are provided for convenience. In order to access them, we recommend keeping your OS up to date xref:../computers/os.adoc#using-apt[in the usual way]. +Raspberry Pi OS provides a number of `apt` packages for convenience. In order to access them, we recommend xref:../computers/os.adoc#using-apt[keeping your OS up to date]. ==== Binary packages There are two `rpicam-apps` packages available, containing the necessary executables: -* `rpicam-apps` contains the full applications with support for previews using a desktop environment. This package is pre-installed in Raspberry Pi OS. +* `rpicam-apps` contains full applications with support for previews using a desktop environment. This package is pre-installed in Raspberry Pi OS. * `rpicam-apps-lite` omits desktop environment support, and only makes the DRM preview available. This package is pre-installed in Raspberry Pi OS Lite. @@ -22,10 +22,4 @@ These will be installed automatically when needed. ==== Dev packages -`rpicam-apps` can be rebuilt on their own without installing and building `libcamera` and `libepoxy` from scratch. To enable this, the following packages should be installed: - -* `libcamera-dev` contains the necessary `libcamera` header files and resources. - -* `libepoxy-dev` contains the necessary `libepoxy` header files and resources. You will only need this if you want support for the GLES/EGL preview window. - -Subsequently `rpicam-apps` can be xref:camera_software.adoc#building-rpicam-apps-without-rebuilding-libcamera[checked out from GitHub and rebuilt]. +You can rebuild `rpicam-apps` without building `libcamera` and `libepoxy` from scratch. For more information, see xref:camera_software.adoc#building-rpicam-apps-without-building-libcamera[Building `rpicam-apps` without rebuilding `libcamera`]. From a28fe4ab6dc34100b162bdd8694bbd59971ea26a Mon Sep 17 00:00:00 2001 From: Nate Contino Date: Fri, 1 Mar 2024 10:32:25 -0500 Subject: [PATCH 2/4] Add rpicam-apps meson build configuration flag reference --- .../camera/rpicam_apps_building.adoc | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc b/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc index cb50994266..820761d768 100644 --- a/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc +++ b/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc @@ -180,6 +180,27 @@ Open a new terminal window after installation to ensure that you use the new bin Finally, follow the `dtoverlay` and display driver instructions in the xref:camera_software.adoc#getting-started[Getting Started section]. +===== `rpicam-apps` meson flag reference + +The `meson` build configuration for `rpicam-apps` supports the following flags: + +`-Dneon_flags=armv8-neon`:: Speeds up certain post-processing features on Raspberry Pi 3 or Raspberry Pi 4 devices running a 32-bit OS. + +`-Denable_libav=true`:: Enables or disables `libav` encoder integration. + +`-Denable_drm=true`:: Enables or disables **DRM/KMS preview rendering**, a preview window used in the absence of a desktop environment. + +`-Denable_egl=true`:: Enables or disables the non-Qt desktop environment-based preview. Disable if your system lacks a desktop environment. + +`-Denable_qt=true`:: Enables or disables support for the Qt-based implementation of the preview window. Disable if you do not have a desktop environment installed or if you have no intention of using the Qt-based preview window. The Qt-based preview is normally not recommended because it is computationally very expensive, however it does work with X display forwarding. + +`-Denable_opencv=true`:: Forces OpenCV-based post-processing stages to link or not link. Requires OpenCV to enable. Defaults to `true` when OpenCV is installed, `false` otherwise. + +`-Denable_tflite=true`:: Enables or disables TensorFlow Lite post-processing stages. Disabled by default. Requires Tensorflow Lite to enable. Depending on how you have built and/or installed TFLite, you may need to tweak the `meson.build` file in the `post_processing_stages` directory. + +NOTE: To disable any of the flags shown above with `true` as a value, replace `true` with `false`. + + ==== Building `libepoxy` Rebuilding `libepoxy` should not normally be necessary as this library changes only very rarely. If you do want to build it from scratch, however, please follow the instructions below. From 9160afdc70f19cb53d8637253c4d19f6958bb2fb Mon Sep 17 00:00:00 2001 From: Nate Contino Date: Fri, 1 Mar 2024 10:35:31 -0500 Subject: [PATCH 3/4] Fix header level --- .../asciidoc/computers/camera/rpicam_apps_building.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc b/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc index 820761d768..af0c10cfbe 100644 --- a/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc +++ b/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc @@ -180,7 +180,7 @@ Open a new terminal window after installation to ensure that you use the new bin Finally, follow the `dtoverlay` and display driver instructions in the xref:camera_software.adoc#getting-started[Getting Started section]. -===== `rpicam-apps` meson flag reference +==== `rpicam-apps` meson flag reference The `meson` build configuration for `rpicam-apps` supports the following flags: From 09cc40fed72864c323b6ee9d3f902531fa122164 Mon Sep 17 00:00:00 2001 From: nate contino Date: Sun, 10 Mar 2024 23:48:54 +0000 Subject: [PATCH 4/4] Update documentation/asciidoc/computers/camera/rpicam_apps_building.adoc --- .../asciidoc/computers/camera/rpicam_apps_building.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc b/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc index af0c10cfbe..bd8ef286ee 100644 --- a/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc +++ b/documentation/asciidoc/computers/camera/rpicam_apps_building.adoc @@ -123,7 +123,7 @@ $ sudo apt install -y cmake libboost-program-options-dev libdrm-dev libexif-dev $ sudo apt install -y meson ninja-build ---- -Download a local copy of Raspberry Pi's fork of `rpicam-apps` from GitHub: +Download a local copy of Raspberry Pi's `rpicam-apps` GitHub repository: [source,console] ----