Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problem with implementing some streaming, QML, CPP
Forum Updated to NodeBB v4.3 + New Features

Problem with implementing some streaming, QML, CPP

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
10 Posts 6 Posters 399 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.
  • V Offline
    V Offline
    vgvg
    wrote last edited by
    #1

    How can I implement some classes on cpp side, which can handle camera stream, and then put it something in QML to watch it?

    VideoOutput - unavailable in cpp
    MediaPlayer - source only by url

    How can I achieve this goal? Any help, please. Any help appreciated even without code. Where should I dig into docs?

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

      Hi and welcome to devnet,

      Which version of Qt are you using ?
      On which OS ?

      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
      • mrdebugM Offline
        mrdebugM Offline
        mrdebug
        wrote last edited by mrdebug
        #3

        Hi. If you need an object to manage rtsp and webcam stream you can use this:
        https://github.com/denisgottardello/QtFFmpegPlayer

        The object emits some events:

        CONNECTION_STATE_CONNECTED,
        CONNECTION_STATE_CONNECTED_DATA_RECEIVED,
        CONNECTION_STATE_CONNECTING,
        CONNECTION_STATE_IDLE,

        so you can create a machine state to resume the connection after a the remote device disconnection.
        The example is based on widgets but, to use it in qml is easy.

        Need programmers to hire?
        www.labcsp.com
        www.denisgottardello.it
        GMT+1
        Skype: mrdebug

        1 Reply Last reply
        0
        • V vgvg

          How can I implement some classes on cpp side, which can handle camera stream, and then put it something in QML to watch it?

          VideoOutput - unavailable in cpp
          MediaPlayer - source only by url

          How can I achieve this goal? Any help, please. Any help appreciated even without code. Where should I dig into docs?

          Ronel_qtmasterR Offline
          Ronel_qtmasterR Offline
          Ronel_qtmaster
          wrote last edited by
          #4

          @vgvg this is how you should proceed
          On the cpp side, create a new class e.g CameraFilter , that inherits from QAbstractVideoFilter that will return a filter Runnable.
          Still on the header create a new class that represent the filter Runnable. That class will inherit from QVideoFilterRunnable. inside the filter runnable class reimplement the run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags); function, that will return the current QVideoFrame. So your filter class should be something like this:

          class MyFilter : public QAbstractVideoFilter {
          Q_OBJECT
          public:
          QVideoFilterRunnable *createFilterRunnable();
          ~MyFilter();
          signals:
          private:
          };
          class MyFilterRunnable : public QVideoFilterRunnable {

          public:
          MyFilterRunnable(MyFilter *creator) {filter = creator;}
          QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags);
          private:
          MyFilter *filter;

          };
          uses qmlRegisterType to register your filter in main.cpp

          Now on the QML side, create a Camera element. Add Also a VideoOutput element. as the source of the VideoOutput set the camera. The VideoOutput has a property called filter. There you can put your custom filter. Something like this.

          MyFilter
          {
              id:myfilter
              
          }
          

          Camera
          {
          id:camera
          }
          VideoOutput{
          width: parent.width - 50
          height: parent.height -50
          anchors.centerIn: parent
          autoOrientation: false
          source:camera
          id:video
          filters: [myfilter]

               }
          
          1 Reply Last reply
          0
          • V Offline
            V Offline
            vgvg
            wrote last edited by
            #5

            Thank you for your all answers. I guess VideoOutput has no source member in Qt 6.10.

            The main idea is - I create custom class, which inherited from some class from Video section. Then, I register qml type and it's done?

            Thank you very much!

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vgvg
              wrote last edited by
              #6

              I am still confused:

                 QMediaCaptureSession* captureSession;
                  QCamera* camera;
                  QVideoSink* videoSink;
              

              I have class with this fields. How should I show what will be in my videoSink in QML?

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vgvg
                wrote last edited by
                #7

                In other words I need to create custom video output. How to do that?

                1 Reply Last reply
                0
                • GrecKoG Online
                  GrecKoG Online
                  GrecKo
                  Qt Champions 2018
                  wrote last edited by
                  #8

                  In c++, you'll need to create and expose to QML a QVideoSink.

                  Here's a overview of how you could do that : https://doc.qt.io/qt-6/qtqml-cppintegration-overview.html

                  QVideoSink has a setVideoFrame method if you want to pass it a custom frame.

                  If you only need to display the frames from a normal camera you don't need that.

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vgvg
                    wrote last edited by
                    #9

                    // Main.qml

                    import QtCore
                    import QtMultimedia
                    import QtQuick
                    import QtQuick.Controls
                    import VWC 1.0

                    ApplicationWindow {
                    width: Screen.width
                    height: Screen.height
                    visible: true
                    title: qsTr("VWC: Virtual Web Camera")

                    Switch {
                        id: toggleCameraSwtich
                        onCheckedChanged: {
                            if (checked) {
                                videoOutput.visible = true
                                Controller.cameraStart()
                            } else {
                                Controller.cameraStop()
                                videoOutput.visible = false
                            }
                        }
                    }
                    
                    VideoOutput {
                        id: videoOutput
                        anchors.fill: parent
                        Component.onCompleted: {
                            Controller.setVideoOutput(videoOutput)
                        }
                    }
                    
                    CameraPermission {
                        id: permissionController
                        Component.onCompleted: {
                            if (permissionController.status !== Qt.PermissionStatus.Granted) {
                                permissionController.request()
                            }
                        }
                    }
                    

                    }

                    // Controller.h
                    class Controller : public QObject
                    {
                    Q_OBJECT
                    public:
                    explicit Controller(QObject *parent = nullptr);

                    Q_INVOKABLE void setVideoOutput(QObject* videoOutput);
                    Q_INVOKABLE void cameraStart();
                    Q_INVOKABLE void cameraStop();
                    

                    signals:

                    public slots:

                    private:
                    QMediaCaptureSession* captureSession;
                    QCamera* camera;
                    };

                    // main.cpp
                    int main(int argc, char *argv[])
                    {
                    QGuiApplication app(argc, argv);

                    QQmlApplicationEngine engine;
                    
                    Controller* controller = new Controller{&app};
                    
                    qmlRegisterSingletonInstance("VWC", 1, 0, "Controller", controller);
                    
                    QObject::connect(
                        &engine, &QQmlApplicationEngine::objectCreationFailed,
                        &app, []() { QCoreApplication::exit(-1); },
                        Qt::QueuedConnection);
                    
                    engine.loadFromModule("VWC", "Main");
                    
                    return app.exec();
                    

                    }

                    I need to get frames from QCamera in the same time when stream is turned on. How?

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      JolianD
                      Banned
                      wrote last edited by JolianD
                      #10
                      This post is deleted!
                      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