Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Live Camera Showing Black Screen
Forum Updated to NodeBB v4.3 + New Features

Live Camera Showing Black Screen

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
10 Posts 4 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • QtFriend2024Q Offline
    QtFriend2024Q Offline
    QtFriend2024
    wrote on last edited by QtFriend2024
    #1

    ->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.4

    I 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
    export
    

    I confirmed that the USB Camera is working by running from the terminal:

    nvgstcapture-1.0 --camsrc=0 --cap-dev-node=0
    

    More 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/media1
    

    Code 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
    
    1 Reply Last reply
    0
    • QtFriend2024Q Offline
      QtFriend2024Q Offline
      QtFriend2024
      wrote on last edited by QtFriend2024
      #9

      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

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        QtFriend2024Q 1 Reply Last reply
        1
        • SGaistS SGaist

          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.

          QtFriend2024Q Offline
          QtFriend2024Q Offline
          QtFriend2024
          wrote on last edited by QtFriend2024
          #3

          @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 library
          

          The plugins exist within the install directory under subdirectories "multimedia" and "platforms":

          find multimedia -iname libffmpegmediaplugin.so
          multimedia/libffmpegmediaplugin.so
          
          find platforms -iname libqxcb.so
          platforms/libqxcb.so
          

          How do I resolve "unloaded library"?

          Thank you

          Ronel_qtmasterR JoeCFDJ 2 Replies Last reply
          0
          • QtFriend2024Q QtFriend2024

            @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 library
            

            The plugins exist within the install directory under subdirectories "multimedia" and "platforms":

            find multimedia -iname libffmpegmediaplugin.so
            multimedia/libffmpegmediaplugin.so
            
            find platforms -iname libqxcb.so
            platforms/libqxcb.so
            

            How do I resolve "unloaded library"?

            Thank you

            Ronel_qtmasterR Offline
            Ronel_qtmasterR Offline
            Ronel_qtmaster
            wrote on last edited by
            #4

            @QtFriend2024 maybe you need others plugin platforms like x11 installed

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              QtFriend2024Q 1 Reply Last reply
              1
              • QtFriend2024Q QtFriend2024

                @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 library
                

                The plugins exist within the install directory under subdirectories "multimedia" and "platforms":

                find multimedia -iname libffmpegmediaplugin.so
                multimedia/libffmpegmediaplugin.so
                
                find platforms -iname libqxcb.so
                platforms/libqxcb.so
                

                How do I resolve "unloaded library"?

                Thank you

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by
                #6

                @QtFriend2024 said in Live Camera Showing Black Screen:

                libffmpegmediaplugin.so

                My installation has this path:
                /opt/Qt6/6.9.0/gcc_64/plugins/multimedia/libffmpegmediaplugin.so

                Yours 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.

                QtFriend2024Q 1 Reply Last reply
                0
                • JoeCFDJ JoeCFD

                  @QtFriend2024 said in Live Camera Showing Black Screen:

                  libffmpegmediaplugin.so

                  My installation has this path:
                  /opt/Qt6/6.9.0/gcc_64/plugins/multimedia/libffmpegmediaplugin.so

                  Yours 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.

                  QtFriend2024Q Offline
                  QtFriend2024Q Offline
                  QtFriend2024
                  wrote on last edited by
                  #7

                  @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.

                  SGaistS 1 Reply Last reply
                  0
                  • QtFriend2024Q QtFriend2024

                    @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.

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @QtFriend2024 as I suggested: use the standard layout to provide the Qt dependencies along your application.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • QtFriend2024Q Offline
                      QtFriend2024Q Offline
                      QtFriend2024
                      wrote on last edited by QtFriend2024
                      #9

                      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

                      1 Reply Last reply
                      0
                      • QtFriend2024Q QtFriend2024 has marked this topic as solved on
                      • SGaistS SGaist

                        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.

                        QtFriend2024Q Offline
                        QtFriend2024Q Offline
                        QtFriend2024
                        wrote on last edited by
                        #10

                        @SGaist Thank you!

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved