CameraBin error: "Failed to allocate required memory." with QCamera
-
@p1ng i suppose these are the libraries that i need to compile from source and install?
https://packages.debian.org/source/stretch/qt-gstreamer
https://launchpad.net/ubuntu/+source/qt-gstreameris that correct? and do they get compiled when i compile entire qt from source?
when could I expect the qt-gstreamer 1.22.1 be included in the binary in the package repository for Raspberry Pi OS? so I can install it with
sudo apt-get install libqt5multimedia5-plugins
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamermm-1.0-devI found the qt-gstreamer source code also. Do I need to build this as well?
https://gstreamer.freedesktop.org/data/src/qt-gstreamer/I am currently in the process of building the binaries, if Im successful is it possible for me to uplaod them to apt package repository so that they will be available for everyone?
-
@SGaist I see. Yes i just checked dependencies
henri@henri-MS-7A72:~$ apt-cache depends libqt5multimedia5-plugins
libqt5multimedia5-plugins
Depends: libqt5multimedia5
Depends: libasound2
Depends: libc6
Depends: libglib2.0-0
Depends: libgstreamer-plugins-base1.0-0
Depends: libgstreamer1.0-0
Depends: libpulse0
Depends: libqt5core5a
|Depends: libqt5gui5
Depends: libqt5gui5-gles
Depends: libqt5multimediagsttools5
Depends: libqt5network5
Depends: libstdc++6This means i have to
-
Remove libraries
sudo apt-get remove libqt5multimedia5-plugins
sudo apt-get remove libgstreamer1.0 libgstreamer-plugins-base1.0 libgstreamermm-1.0
just in case
sudo apt-get remove libgstreamer1.0 libgstreamer-plugins-base1.0-dev libgstreamermm-1.0 -
Build and install gstreamer 1.22.1 from source following this guide in README:
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/tree/1.22.1 -
Install the libq5multimedia5-plugins again
sudo apt-get install libqt5multimedia5-plugins -
Cross my fingers and pray
Is this correct?
-
-
So this is where im at right now
sudo apt-get remove libqt5multimedia5-plugins
sudo apt-get remove libgstreamer1.0 libgstreamer-plugins-base1.0 libgstreamermm-1.0Just in case
sudo apt-get remove libgstreamer*
VERY IMPORTNANT TO INSTALL meson as root otherwise will get build issue
$sudo pip3 install meson
$sudo pip3 install markdow typogrify
$sudo apt-get update
$sudo apt-get install ninja-build
$sudo apt install -y build-essential autotools-dev automake autoconf
libtool autopoint libxml2-dev zlib1g-dev libglib2.0-dev
pkg-config bison flex python3 git gtk-doc-tools libasound2-dev
libgudev-1.0-dev libxt-dev libvorbis-dev libcdparanoia-dev
libpango1.0-dev libtheora-dev libvisual-0.4-dev iso-codes
libgtk-3-dev libraw1394-dev libiec61883-dev libavc1394-dev
libv4l-dev libcairo2-dev libcaca-dev libspeex-dev libpng-dev
libshout3-dev libjpeg-dev libaa1-dev libflac-dev libdv4-dev
libtag1-dev libwavpack-dev libpulse-dev libsoup2.4-dev libbz2-dev
libcdaudio-dev libdc1394-22-dev ladspa-sdk libass-dev
libcurl4-gnutls-dev libdca-dev libdvdnav-dev \Make sure to get the tarball because checkout out 1.22.1 tag from git gave me problems i could not resolve.
$wget https://gitlab.freedesktop.org/gstreamer/gstreamer/-/archive/1.21.1/gstreamer-1.21.1.tar.gz
$tar -xf gstreamer-1.21.1.tar.gz
$cd gstreamer-1.21.1.tar.gzFFmpeg didnt compile on my RPI4 (32-it OS), so to disable it cause got some ARMv proessor arhcitecture errors.
$meson builddir -Dgst-plugins-base:gl_winsys=egl -Dlibav=disabled
$ninja -C builddir
$meson setup builddir
$meson compile -C buildir$sudo meson install -C builddir$ gst-launch-1.0 --version
gst-launch-1.0: error while loading shared libraries: libgstreamer-1.0.so.0: cannot open shared object file: No such file or directory$sudo gedit /etc/ld.so.conf.d/randomLibs.conf
#add this line to the file or if the ibgstreamer-1.0.so.0 was installed somewhere else add that path
/usr/local/lib/arm-linux-gnueabihf
sudo ldconfig$gst-launch-1.0 --version
gst-launch-1.0 version 1.21.1
GStreamer 1.21.1
Unknown package originWhen i try to run my app that uses QCamera this is the error i get:
Error: cannot create camera service, the 'camerabin' plugin is missing for GStreamer 1.18.
Please install the 'bad' GStreamer plugin package.I will now try to compile and install the bad plugin package with -Dbad=enabled. But im not sure if it will fix this because it seems to me that when i install sudo apt-get install qtmultimedia5-dev this will automatically install and try to use the 1.18 gstreamer - this is what i conclude from that error message.
-
$meson builddir --reconfigure -Dbad=enabled -Dgst-plugins-base:gl_winsys=egl,wayland -Dlibav=disabled -Dgst-plugins-bad:camerabin2=enabled
$meson compile -C builddir
$meson install -C builddirAnd now my QCamera cant even detect the camera....
Can you reccommend me some other class I could use for this camera? I see some people have used the qcam code from lib-camera. Anybody have a working project setup with that code?
All i need is to have the cameras to be able to capture pictures and control zoom from my Qt application.
-
@p1ng
So I just found out that the fix in gstreamer 1.22.1 that makes camera work with Qt is just one line in gstreamer source code. What i will try next is to check out gstreamer 1.18 source code, put that fix in it, compile and install since my qt app was able to reqonize camera when gstreamer 1.18 was installed. This is the fix if im not mistaken: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/commit/67df248270491116af6099bf3bec5c740dfe3042
67df2482
v4l2h264dec: Fix Raspberry Pi4 will not play video in applicationand if that doesent work ill probably try to use qcam source from libcamera examples instead of QCamera
-
That didnt work out.
# On my Ubuntu 22.04 PC wget https://downloads.raspberrypi.org/raspios_armhf/images/raspios_armhf-2022-01-28/2022-01-28-raspios-bullseye-armhf.zip git clone https://github.com/raspberrypi/usbboot.git cd usbboot # Flip the BOOT switch on RPI to ON sudo ./rpiboot wget https://github.com/balena-io/etcher/releases/download/v1.18.4/balenaEtcher-1.18.4-x64.AppImage chmod +x balenaEtcher-1.18.4-x64.AppImage ./balenaEtcher-1.18.4-x64.AppImage # Flashed to my RPi4 CM4 # On my RPI4 CM4 wget -O install_pivariety_pkgs.sh https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/install_pivariety_pkgs.sh chmod +x install_pivariety_pkgs.sh 2. Install libcamra-dev ./install_pivariety_pkgs.sh -p libcamera_dev 3. Install libcamera-apps ./install_pivariety_pkgs.sh -p libcamera_apps 4. Install the kernel driver ./install_pivariety_pkgs.sh -p 64mp_pi_hawk_eye_kernel_driver 5. Configuration Open /boot/config.txt, under [all], add the following line: dtoverlay=vc4-kms-v3d,cma-512 Example: [all] # Run as fast as firmware / board allows arm_boost=1 dtoverlay=vc4-kms-v3d,cma-512 # Enabled i2c under interfaces sudo raspi-config reboot # Compiling gstreamer 1.18 sudo pip3 install meson sudo apt-get update # have to use gst-build for v<19 https://gstreamer.freedesktop.org/documentation/installing/building-from-source-using-meson.html?gi-language=c git clone https://gitlab.freedesktop.org/gstreamer/gst-build.git cd gst-build $sudo apt install -y build-essential autotools-dev automake autoconf \ libtool autopoint libxml2-dev zlib1g-dev libglib2.0-dev \ pkg-config bison flex python3 git gtk-doc-tools libasound2-dev \ libgudev-1.0-dev libxt-dev libvorbis-dev libcdparanoia-dev \ libpango1.0-dev libtheora-dev libvisual-0.4-dev iso-codes \ libgtk-3-dev libraw1394-dev libiec61883-dev libavc1394-dev \ libv4l-dev libcairo2-dev libcaca-dev libspeex-dev libpng-dev \ libshout3-dev libjpeg-dev libaa1-dev libflac-dev libdv4-dev \ libtag1-dev libwavpack-dev libpulse-dev libsoup2.4-dev libbz2-dev \ libcdaudio-dev libdc1394-22-dev ladspa-sdk libass-dev \ libcurl4-gnutls-dev libdca-dev libdvdnav-dev \ meson build --buildtype=release -Dgst-plugins-good:qt5=disabled -Dbad=enabled -Dgst-plugins-base:gl_winsys=egl -Dlibav=disabled -Dgst-plugins-bad:camerabin2=enabled # At this point i installed gstreamer tools to see if standalone gstreamer tools will play my cameras # install a missing dependency $ sudo apt-get install libx264-dev libjpeg-dev # install the remaining plugins $ sudo apt-get install libgstreamer1.0-dev \ libgstreamer-plugins-base1.0-dev \ libgstreamer-plugins-bad1.0-dev \ gstreamer1.0-plugins-ugly \ gstreamer1.0-tools \ gstreamer1.0-gl \ gstreamer1.0-gtk3 # Confirmed that current standalone gsteamer plays video. gst-launch-1.0 libcamerasrc ! video/x-raw, width=640, height=480, framerate=30/1 ! videoconvert ! videoscale ! clockoverlay time-format="%D %H:%M:%S" ! autovideosink # This made me curious to install qt and try to run camera example project to confirm it dosent work before i try to compile & install the 1.18.6 version sudo apt-get install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools sudo apt-get install cmake sudo apt-get install clan sudo apt-get install qtmultimedia5-dev sudo apt-get install qtcreator ~/Qt/5.14.2/Examples/Qt-5.14.2$ scp -r multimediawidgets pi@192.168.88.249:/home/pi/Desktop/Examples ~/Qt/5.14.2/Examples/Qt-5.14.2$ scp -r multimediawidgets pi@192.168.88.249:/home/pi/Desktop/multimedia # Built and compiled the Examples/camera in qtcreator but got error "CameraService is missing" sudo apt-get install libqt5multimedia5-plugins # Now i get the CameraBin error: "Failed to allocate memory". So proceed with meson compilation # I also checked the version of different gstreamer libraries/tools i currenlty have installed pi@raspberrypi:~/devdirs/gst-1.18.6/gst-build $ dpkg -l | grep gstream* ii gir1.2-gstreamer-1.0:armhf 1.18.4-2.1 armhf GObject introspection data for the GStreamer library ii gstreamer1.0-alsa:armhf 1.18.4-2 armhf GStreamer plugin for ALSA ii gstreamer1.0-gl:armhf 1.18.4-2 armhf GStreamer plugins for GL ii gstreamer1.0-gtk3:armhf 1.18.4-2+deb11u1+rpt1 armhf GStreamer plugin for GTK+3 ii gstreamer1.0-libav:armhf 1.18.4-3 armhf ffmpeg plugin for GStreamer ii gstreamer1.0-omx 1.0.0.1-0+rpi12+jessiepmg armhf GStreamer OpenMAX plugins ii gstreamer1.0-plugins-bad:armhf 1.18.4-3 armhf GStreamer plugins from the "bad" set ii gstreamer1.0-plugins-base:armhf 1.18.4-2 armhf GStreamer plugins from the "base" set ii gstreamer1.0-plugins-good:armhf 1.18.4-2 armhf GStreamer plugins from the "good" set ii gstreamer1.0-plugins-ugly:armhf 1.18.4-2 armhf GStreamer plugins from the "ugly" set ii gstreamer1.0-tools 1.18.4-2.1 armhf Tools for use with GStreamer ii gstreamer1.0-x:armhf 1.18.4-2 armhf GStreamer plugins for X11 and Pango ii libgstreamer-gl1.0-0:armhf 1.18.4-2 armhf GStreamer GL libraries ii libgstreamer-opencv1.0-0:armhf 1.18.4-3 armhf GStreamer OpenCV libraries ii libgstreamer-plugins-bad1.0-0:armhf 1.18.4-3 armhf GStreamer libraries from the "bad" set ii libgstreamer-plugins-bad1.0-dev:armhf 1.18.4-3 armhf GStreamer development files for libraries from the "bad" set ii libgstreamer-plugins-base1.0-0:armhf 1.18.4-2 armhf GStreamer libraries from the "base" set ii libgstreamer-plugins-base1.0-dev:armhf 1.18.4-2 armhf GStreamer development files for libraries from the "base" set ii libgstreamer1.0-0:armhf 1.18.4-2.1 armhf Core GStreamer libraries and elements ii libgstreamer1.0-dev:armhf 1.18.4-2.1 armhf GStreamer core development files ii libqt5gstreamer-1.0-0:armhf 1.2.0-5.1 armhf C++ bindings library for GStreamer with a Qt-style API - Qt 5 build pi@raspberrypi:~/devdirs/gst-1.18.6/gst-build $ apt list | grep libqt5multimedia5-plugins libqt5multimedia5-plugins/stable,now 5.15.2-3 armhf [installed] # Compile pi@raspberrypi:~/devdirs/gst-1.18.6/gst-build $ cp subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c_backup pi@raspberrypi:~/devdirs/gst-1.18.6/gst-build $ nano subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c #Search for method gst_v4l2_object_stop and replace it with gboolean gst_v4l2_object_stop (GstV4l2Object * v4l2object) { GstBufferPool *pool; GST_DEBUG_OBJECT (v4l2object->dbg_obj, "stopping"); if (!GST_V4L2_IS_OPEN (v4l2object)) goto done; if (!GST_V4L2_IS_ACTIVE (v4l2object)) goto done; pool = gst_v4l2_object_get_buffer_pool (v4l2object); if (pool) { if (!gst_v4l2_buffer_pool_orphan (v4l2object)) { GST_DEBUG_OBJECT (v4l2object->dbg_obj, "deactivating pool"); gst_buffer_pool_set_active (pool, FALSE); { GstBufferPool *old_pool; GST_OBJECT_LOCK (v4l2object->element); old_pool = v4l2object->pool; v4l2object->pool = NULL; GST_OBJECT_UNLOCK (v4l2object->element); if (old_pool) gst_object_unref (old_pool); } } gst_object_unref (pool); } GST_V4L2_SET_INACTIVE (v4l2object); done: return TRUE; } # Add gst_v4l2_object_get_buffer_pool methdo to the end of the file GstBufferPool * gst_v4l2_object_get_buffer_pool (GstV4l2Object * v4l2object) { GstBufferPool *ret = NULL; g_return_val_if_fail (v4l2object != NULL, NULL); GST_OBJECT_LOCK (v4l2object->element); if (v4l2object->pool) ret = gst_object_ref (v4l2object->pool); GST_OBJECT_UNLOCK (v4l2object->element); return ret; } # Add this line to subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.h at the end of /* probing */ block GstBufferPool * gst_v4l2_object_get_buffer_pool (GstV4l2Object * v4l2object); # Now compile gstreamer 1.18.6 ninja -C build sudo ninja -C build install pi@raspberrypi:~/devdirs/gst-1.18.6/gst-build $ dpkg -l | grep gstream* ii gir1.2-gstreamer-1.0:armhf 1.18.4-2.1 armhf GObject introspection data for the GStreamer library ii gstreamer1.0-alsa:armhf 1.18.4-2 armhf GStreamer plugin for ALSA ii gstreamer1.0-gl:armhf 1.18.4-2 armhf GStreamer plugins for GL ii gstreamer1.0-gtk3:armhf 1.18.4-2+deb11u1+rpt1 armhf GStreamer plugin for GTK+3 ii gstreamer1.0-libav:armhf 1.18.4-3 armhf ffmpeg plugin for GStreamer ii gstreamer1.0-omx 1.0.0.1-0+rpi12+jessiepmg armhf GStreamer OpenMAX plugins ii gstreamer1.0-plugins-bad:armhf 1.18.4-3 armhf GStreamer plugins from the "bad" set ii gstreamer1.0-plugins-base:armhf 1.18.4-2 armhf GStreamer plugins from the "base" set ii gstreamer1.0-plugins-good:armhf 1.18.4-2 armhf GStreamer plugins from the "good" set ii gstreamer1.0-plugins-ugly:armhf 1.18.4-2 armhf GStreamer plugins from the "ugly" set ii gstreamer1.0-tools 1.18.4-2.1 armhf Tools for use with GStreamer ii gstreamer1.0-x:armhf 1.18.4-2 armhf GStreamer plugins for X11 and Pango ii libgstreamer-gl1.0-0:armhf 1.18.4-2 armhf GStreamer GL libraries ii libgstreamer-opencv1.0-0:armhf 1.18.4-3 armhf GStreamer OpenCV libraries ii libgstreamer-plugins-bad1.0-0:armhf 1.18.4-3 armhf GStreamer libraries from the "bad" set ii libgstreamer-plugins-bad1.0-dev:armhf 1.18.4-3 armhf GStreamer development files for libraries from the "bad" set ii libgstreamer-plugins-base1.0-0:armhf 1.18.4-2 armhf GStreamer libraries from the "base" set ii libgstreamer-plugins-base1.0-dev:armhf 1.18.4-2 armhf GStreamer development files for libraries from the "base" set ii libgstreamer1.0-0:armhf 1.18.4-2.1 armhf Core GStreamer libraries and elements ii libgstreamer1.0-dev:armhf 1.18.4-2.1 armhf GStreamer core development files ii libqt5gstreamer-1.0-0:armhf 1.2.0-5.1 armhf C++ bindings library for GStreamer with a Qt-style API - Qt 5 build # So the packages i compiled were not replace with packages from remote repo i installed with apt-get sudo apt-get remove gstreamer1.0-plugins-good # Now when i do pi@raspberrypi:~ $ gst-launch-1.0 --version gst-launch-1.0 version 1.18.6 GStreamer 1.18.6 Unknown package origin # But after that removal the gst-launch-1.0 cant play back camera anymore. Maybe it was my "fix" in code that broke it. Ill roll that back and rebuild # So what i did now is that i uninstalled everything related to gstreamer sudo apt-get remove libgstreamer* libqt5gstreamer* gstreamer1.0*
at this point i give up and work on some other stuff. maybe over time somebody will fix it for qt5 or ill try to use libcamera https://git.libcamera.org/libcamera/libcamera.git/tree/src/apps/qcam instead of QCamera or ill see if my camera works in qt6.
-
@p1ng I gave it one more try. Compiled qt5.15.2 from source, then cross-compiled it for RPI4, 32-bit bullseye 6.1.xx
Compiled gstreamer 1.22.1 from source that i thought has fix for it.
Then ran my qt app that uses Camera, i get the same failed to allocate required memory error.
Running gstreamer from command line gives the same error:
gst-launch-1.0 -v v4l2src device=/dev/video0 ! fbdevsinkFrom this i conclude that the issue has not been fixed in gstreamer and i have to use libcamera qcam example to get qt into my raspberry qt app.
-
I managed to convert libcamera simple-cam meson example to QT project. I used chatgpt to convert meson.build to .pro file. For those in the future who are struggling integrating libcamera to qt i have uploaded the project to https://github.com/henrihallik/simple-cam-qt.
Also chatgpt proved vital working through various linker errors that occured. So if u need more help , just ask OpenAIs chatgpt. https://chat.openai.com/chat -
@p1ng so the simple-cam-qt was too difficult to figure out how to modify to capture an image with set resoluton. So I converted libcameras qcam project to qt project that already has image capture functionality in it.
U can get it here if u want to: -
@p1ng The qcam was still too difficult to integrate. I found edwards libcamera-cpp-demo by far the simplest example to integrate libcamera to my own code:
https://github.com/edward-ardu/libcamera-cpp-demoMy slightly modified version of this that specifies multiple cameras:
https://github.com/edward-ardu/libcamera-cpp-demo/tree/7b3f9b97a479fb49beb01db1ddd77f5090fa52dc -
-
@p1ng Try 1.22.3 and it has more bug fixes.
the steps(order) to install the latest gstreamer
- you may need to get the latest libva and build it.
- build gstreamer and make sure all needed plugins are built.
- build the driver of graphics card(for examples: media driver from Intel).
- build camera llib and Qt multimedia plugin
- set lib/bin path for installed gstreamer and export new driver path LIBVA_DRIVERS_PATH
Since it is easy to make mistakes in gstreamer build, do not try to install it in default dirs like /usr/lib etc. Instead install all packages under /opt/gstreamer. In case anything goes wrong, you can remove the whole installation and redo it. Otherwise, you may have difficulty to use videos on your machine later on. Some installations can not be removed automatically and you have to remove them manually. Things can get very messy.