Live Camera Showing Black Screen
-
->Goal: Have my app run on devices without QT installed!
Issue: QVideoWidget displaying black screen for live USB Camera when devices does NOT have QT Installed
Device: NVIDIA Jetson Orin Nano with JetPack 6.1
O.S.: ARM 64 Ubuntu 22.0.4I am able to get this to work if I have QT Development environment installed but not when the device has no QT. All other parts of the app works.
Folder Structure Within the Install Directory:
- myapp
- /lib
- /platforms
- /multimedia
where platforms sub-directory contains plugins.
I have tried using qt6.conf
[Paths] Prefix = . Documentation = doc Headers = include Libraries = lib LibraryExecutables = lib Binaries = bin Plugins = platforms QmlImports = qml ArchData = . Data = . Translations = translations Examples = examples Tests = tests Settings = .and replacing qt6.conf with a bash script which includes:
export LD_LIBRARY_PATH=$myapp_dir/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=$myapp_dir/platforms:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=$myapp_dir/multimedia:$LD_LIBRARY_PATH exportI confirmed that the USB Camera is working by running from the terminal:
nvgstcapture-1.0 --camsrc=0 --cap-dev-node=0More information:
v4l2-ctl --list-devices NVIDIA Tegra Video Input Device (platform:tegra-camrtc-ca): /dev/media0 HD Camera: HD Camera (usb-3610000.usb-2.2): /dev/video0 /dev/video1 /dev/media1Code Snippet:
const QList<QCameraDevice> CAM_DEVICES = QMediaDevices::videoInputs(); qDebug() << this << "Number of video inputs found: " << CAM_DEVICES.count(); int indexForDefaultCd=0; for ( int i=0; i < CAM_DEVICES.count(); i++ ) { qDebug() << this << "Found Media Device #" << i << ": " << CAM_DEVICES[i].description() << ". Is default? " << CAM_DEVICES[i].isDefault(); if ( CAM_DEVICES[i].isDefault() == true ) { indexForDefaultCd=i; qDebug() << this << "Default camera: " << CAM_DEVICES[i].description(); } } if ( CAM_DEVICES.count() > 0 ) { Q_ASSERT(CAM_DEVICES[indexForDefaultCd].isNull() == false); qDebug() << this << "Is QCameraDevice object null? " << CAM_DEVICES[indexForDefaultCd].isNull(); QCamera *qCam = new QCamera(CAM_DEVICES[indexForDefaultCd]); qCam->setObjectName("qCam"); Q_ASSERT(qCam->isAvailable()); qDebug() << this << "Is QCamera object available? " << qCam->isAvailable(); qDebug() << this << "Reset QScopedPointer to QCamera object " << qCam->objectName(); m_camera.reset(qCam); qDebug() << this << "Is QScopedPointer pointing to qCam QCamera object? " << m_camera->isAvailable(); Q_ASSERT(m_camera->objectName() == "qCam"); Q_ASSERT(m_camera->isAvailable()); if ( m_camera->isAvailable() == false ) { qWarning() << this << "startCamera() - Camera is not available for use."; } Q_ASSERT(m_camera->error() == QCamera::NoError); if ( m_camera->error() == QCamera::CameraError ) { qDebug() << this << "QCamera error occurred: " << m_camera->errorString(); } m_captureSession.setCamera(m_camera.data()); Q_ASSERT(m_camera->error() == QCamera::NoError); if ( m_camera->error() == QCamera::CameraError ) { qDebug() << this << "QCamera error occurred: " << m_camera->errorString(); } m_ui->liveCamera->update(); m_camera->start(); Q_ASSERT(m_camera->isActive()); qDebug() << "VideoWidget - Starting camera... Is camera active? " << m_camera->isActive(); } else { qDebug() << "VideoWidget::startCamera() - no camera found."; }Debug Output
VideoWidget(0xffffdf3c2ea0, name="VideoWidget") Attempting to find then start camera... VideoWidget(0xffffdf3c2ea0, name="VideoWidget") Number of video inputs found: 1 VideoWidget(0xffffdf3c2ea0, name="VideoWidget") Found Media Device # 0 : "HD Camera: HD Camera" . Is default? true VideoWidget(0xffffdf3c2ea0, name="VideoWidget") Default camera: "HD Camera: HD Camera" VideoWidget(0xffffdf3c2ea0, name="VideoWidget") Is QCameraDevice object null? false VideoWidget(0xffffdf3c2ea0, name="VideoWidget") Is QCamera object available? true VideoWidget(0xffffdf3c2ea0, name="VideoWidget") Reset QScopedPointer to QCamera object "qCam" VideoWidget(0xffffdf3c2ea0, name="VideoWidget") Is QScopedPointer pointing to qCam QCamera object? true VideoWidget - Starting camera... Is camera active? true -
SOLUTION
Hello, my ultimate solution that appears to be working is update my CMakeLists.txt file to copy all directories and files from within ~/Qt/6.7.3/gcc_arm64 to the INSTALL directory. Of course, it makes the install directory unnecessarily large (because some of the extra files that aren't needed by my app), but this appears to get all the plugins working (virtualkeyboard, xcb, etc.), and I don't have to waste time following and finding all dependencies.
Now, I am going to have my teammate try to run my app without QT installed.
qt6.conf
[Paths] Prefix = . Documentation = doc Headers = include Libraries = lib LibraryExecutables = libexec Binaries = bin Plugins = plugins QmlImports = qml ArchData = . Data = . Translations = translations Examples = examples Tests = tests Settings = .Helpful Application Environment Variables:
QT_DEBUG_PLUGINS=1
QT_QPA_PLATFORM_PLUGIN_PATH=1 -
Hi,
Set the QT_DEBUG_PLUGINS environnement variable to 1 and start your application. You'll see what is being loaded.
I am suspecting you are deploying all the required plugins along your application. -
Hi,
Set the QT_DEBUG_PLUGINS environnement variable to 1 and start your application. You'll see what is being loaded.
I am suspecting you are deploying all the required plugins along your application.@SGaist hi Thank you for the reply!
I added QT_DEBUG_PLUGINS=1 environment variable like you suggested.
When I try to start the application....
Output:
qt.core.plugin.factoryloader: checking directory path "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/platforms/accessiblebridge" ... qt.core.plugin.factoryloader: checking directory path "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/accessiblebridge" ... "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/multimedia/libffmpegmediaplugin.so" unloaded library "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/platforms/libqxcb.so" unloaded libraryThe plugins exist within the install directory under subdirectories "multimedia" and "platforms":
find multimedia -iname libffmpegmediaplugin.so multimedia/libffmpegmediaplugin.sofind platforms -iname libqxcb.so platforms/libqxcb.soHow do I resolve "unloaded library"?
Thank you
-
@SGaist hi Thank you for the reply!
I added QT_DEBUG_PLUGINS=1 environment variable like you suggested.
When I try to start the application....
Output:
qt.core.plugin.factoryloader: checking directory path "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/platforms/accessiblebridge" ... qt.core.plugin.factoryloader: checking directory path "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/accessiblebridge" ... "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/multimedia/libffmpegmediaplugin.so" unloaded library "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/platforms/libqxcb.so" unloaded libraryThe plugins exist within the install directory under subdirectories "multimedia" and "platforms":
find multimedia -iname libffmpegmediaplugin.so multimedia/libffmpegmediaplugin.sofind platforms -iname libqxcb.so platforms/libqxcb.soHow do I resolve "unloaded library"?
Thank you
@QtFriend2024 maybe you need others plugin platforms like x11 installed
-
First thing I would do:
Follow the default folder structure for a Qt Application. Plugins are searched in specific folders that you have to respect. Qt does not scan every folder for a chance to find plugins. -
@SGaist hi Thank you for the reply!
I added QT_DEBUG_PLUGINS=1 environment variable like you suggested.
When I try to start the application....
Output:
qt.core.plugin.factoryloader: checking directory path "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/platforms/accessiblebridge" ... qt.core.plugin.factoryloader: checking directory path "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/accessiblebridge" ... "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/multimedia/libffmpegmediaplugin.so" unloaded library "/home/xyz/QtProjects/myapp/build/Desktop_Qt_6_7_3-Debug/platforms/libqxcb.so" unloaded libraryThe plugins exist within the install directory under subdirectories "multimedia" and "platforms":
find multimedia -iname libffmpegmediaplugin.so multimedia/libffmpegmediaplugin.sofind platforms -iname libqxcb.so platforms/libqxcb.soHow do I resolve "unloaded library"?
Thank you
@QtFriend2024 said in Live Camera Showing Black Screen:
My installation has this path:
/opt/Qt6/6.9.0/gcc_64/plugins/multimedia/libffmpegmediaplugin.soYours is different. Therefore, the path of Qt plugins seems not to be set correctly. It is good that you can build Qt, but it may be better to install Qt and you will get the right path for plugins.
-
@QtFriend2024 said in Live Camera Showing Black Screen:
My installation has this path:
/opt/Qt6/6.9.0/gcc_64/plugins/multimedia/libffmpegmediaplugin.soYours is different. Therefore, the path of Qt plugins seems not to be set correctly. It is good that you can build Qt, but it may be better to install Qt and you will get the right path for plugins.
@JoeCFD Hi Thanks. I agree, it's easier for the devices have QT installed, but eventually, all the devices that have my app need to exist and run without QT installed.
-
@JoeCFD Hi Thanks. I agree, it's easier for the devices have QT installed, but eventually, all the devices that have my app need to exist and run without QT installed.
@QtFriend2024 as I suggested: use the standard layout to provide the Qt dependencies along your application.
-
SOLUTION
Hello, my ultimate solution that appears to be working is update my CMakeLists.txt file to copy all directories and files from within ~/Qt/6.7.3/gcc_arm64 to the INSTALL directory. Of course, it makes the install directory unnecessarily large (because some of the extra files that aren't needed by my app), but this appears to get all the plugins working (virtualkeyboard, xcb, etc.), and I don't have to waste time following and finding all dependencies.
Now, I am going to have my teammate try to run my app without QT installed.
qt6.conf
[Paths] Prefix = . Documentation = doc Headers = include Libraries = lib LibraryExecutables = libexec Binaries = bin Plugins = plugins QmlImports = qml ArchData = . Data = . Translations = translations Examples = examples Tests = tests Settings = .Helpful Application Environment Variables:
QT_DEBUG_PLUGINS=1
QT_QPA_PLATFORM_PLUGIN_PATH=1 -
Q QtFriend2024 has marked this topic as solved on
-
First thing I would do:
Follow the default folder structure for a Qt Application. Plugins are searched in specific folders that you have to respect. Qt does not scan every folder for a chance to find plugins.@SGaist Thank you!