Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Camera QML element and multiple QMediaService
Forum Updated to NodeBB v4.3 + New Features

Camera QML element and multiple QMediaService

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
11 Posts 3 Posters 2.7k Views 3 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.
  • P Offline
    P Offline
    PetrM
    wrote on last edited by PetrM
    #1

    Hello,
    I have implemented my own QMediaService providing my own camera (a camera simulator). The service is implemented as a plugin very similarly as the Qt's directshow plugin. Now I want to display my camera in Camera item (QML). The QML is as follows:

    ApplicationWindow {
        visible: true
        width: 640
        height: 480
    
        Camera {
               id: camera		   
           }
    
       VideoOutput {
    	   anchors.fill: parent
    	   source: camera
       }
       ListView {
    	   anchors.fill: parent
    	   model: QtMultimedia.availableCameras
    	   delegate: Text {
    		   text: modelData.displayName
    
    		   MouseArea {
    			   anchors.fill: parent
    			   onClicked: camera.deviceId = modelData.deviceId
    		   }
    	   }
       }
    }
    

    It's an example I found somewhere in the Qt Doc. It allows to switch between cameras connected to the PC and display their outputs (live image) on the screen. I have connected two cameras (the first is built-in camera and the second is and USB live cam). The application correctly displays three camera names: the two connected I mentioned and the third is my camera simulator - the QtMultimedia::availableCameras works well. The problem is that when I click on the item with my own camera (the simulator), nothing happens because QMediaServiceProviderPlugin::create() in my plugin is never called. I investigated the QT source codes and I probably found the problem:

    When the Camera element is created by the QtQuick, the QCamera(QObject *parent) constructor is called and it then calls the FIRST QMediaServiceProviderPlugin loaded (the directshow plugin in this case) to create the QMediaService instance. My QMediaService is never created.

    When I try:

    Camera {
       id: camera
       deviceId: QtMultimedia.availableCameras[2].deviceId
    }
    

    it doesn't work from the same reason - the directshow plugin is used to create the QMediaService.

    My question:
    Is there a way how to make the QML program above work for multiple QMediaServiceProviderPlugin loaded?

    Thanks for any usefull help.

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

      Hi,

      One alternative that you can try is to use a wrapper object that provides the QCamera to your VideoOutput.

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

      P 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        One alternative that you can try is to use a wrapper object that provides the QCamera to your VideoOutput.

        P Offline
        P Offline
        PetrM
        wrote on last edited by
        #3

        @SGaist
        Thanks for reply. Please could you be more concrete? I don't know how to implement it. A hint would help....

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

          You have to create a QObject subclass that has a property called mediaObject that will return you camera instance.

          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
          • P Offline
            P Offline
            PetrM
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • O Offline
              O Offline
              oniongarlic
              wrote on last edited by
              #6

              I'm playing around with the gphoto plugin and this hit me. It seems Qt does not handle the case with multiple QMediaService camera plugins properly.

              SGaistS 1 Reply Last reply
              0
              • P Offline
                P Offline
                PetrM
                wrote on last edited by
                #7

                You're right. I tried some hacks but finally I gave up using QML Camera, QMediaService etc. and implemented my own framework for cameras.

                1 Reply Last reply
                0
                • O oniongarlic

                  I'm playing around with the gphoto plugin and this hit me. It seems Qt does not handle the case with multiple QMediaService camera plugins properly.

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

                  @oniongarlic said in Camera QML element and multiple QMediaService:

                  I'm playing around with the gphoto plugin and this hit me. It seems Qt does not handle the case with multiple QMediaService camera plugins properly.

                  That's a bit too vague. I've written applications using several different custom QtMultimedia backends at the same time and it worked nicely.

                  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
                  • O Offline
                    O Offline
                    oniongarlic
                    wrote on last edited by
                    #9

                    Well, the issue is with camera selection. If the gphoto plugin, https://github.com/dept2/qtmultimedia-gphoto , and Qts own (gst/v4l2)camera plugin are both available it will load them both, QtMultimedia.availableCameras will contain all cameras available. So far so good.

                    But assigning a id to the Camera deviceId property only works for cameras from the first loaded plugin, so for example if gphoto plugin is loaded first it is not possible to switch to a v4l2 camera. Plugins seems to be loaded in a-z order so gphoto will be first in case it is installed.

                    And looking at the code, afaik, it only uses the first QMediaService when the property is changed and does not check other QMediaService camera sources.

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

                      That's clearer now.

                      Do you have the same problem if you provide the devices you select through C++ ?

                      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
                      • O Offline
                        O Offline
                        oniongarlic
                        wrote on last edited by
                        #11

                        I haven't used the camera trough C++ yet.

                        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