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. Record video with Overlay
Forum Updated to NodeBB v4.3 + New Features

Record video with Overlay

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
15 Posts 4 Posters 2.6k Views 1 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.
  • N Offline
    N Offline
    nikita.panchal09
    wrote on last edited by
    #1

    Hi,

    I want to record Video with Overlay.

    I have created QGrphicsView and added QGraphicsScene contaning QGraphicsVideoItem(Video) and QGraphicsTextItem(Overlay Text).
    When I record video with "QMediaRecorder" It records only video data not overlay text.

    I am able to CaptureImage with "Overlay Text" using below code but unable to capture video.
    QPixmap pixMap = graphicsView->grab(graphicsView->sceneRect().toRect());
    pixMap.save(fileName);

    I am testing the code with Linux PC and webcam.
    Let me know the ways to record video with overlay.

    Thanks,
    Nikita

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

      Hi,

      What exactly is on that overlay ?

      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
      • N Offline
        N Offline
        nikita.panchal09
        wrote on last edited by
        #3

        Hi,

        Thanks for your time.
        An overlay is just like text which contains current date-time, location etc.

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

          I know what an overlay is. My question was: what are you putting on said overlay ?

          Depending on that and how you put your overlay on top of your video, it might be more or less complex to record it.

          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
          • N Offline
            N Offline
            nikita.panchal09
            wrote on last edited by
            #5

            Hi,

            Thank you for your support. I have added QGraphicsVideoItem and QGraphicsTextItem in QGrahicsScene to generate overlay text.

            Actually, I am new to QT Multimedia. Please go through below code, and if it is not a proper way then let me know another way.

            void MainWindow::Init()
            {

            videoItem = new QGraphicsVideoItem();      //Video Item
            
            scene = new QGraphicsScene(this);
            scene->addItem(videoItem);
            text = scene->addText("Hello World");   //Overlay Text
            
            graphicsView = new QGraphicsView(scene);
            pCamera->setViewfinder(videoItem);
            
            pCameraImageCapture = new QCameraImageCapture(pCamera, this);
            CamRecordInit();
            pCamera->start();
            

            }

            //Init QMediaRecorder
            void MainWindow::CamRecordInit()
            {

            pMediaRecorder = new QMediaRecorder(pCamera);
            updateRecorderState(pMediaRecorder->state());
            connect(pMediaRecorder, SIGNAL(stateChanged(QMediaRecorder::State)), this, SLOT(updateRecorderState(QMediaRecorder::State)));
            

            }

            //Start video recording
            void MainWindow::StartCamRecord()
            {

            if (pCamera->isCaptureModeSupported(QCamera::CaptureVideo))
                pCamera->setCaptureMode(QCamera::CaptureVideo);
            
            pMediaRecorder->setOutputLocation(QUrl::fromLocalFile("/home/user/sample"));
            pMediaRecorder->record();		//This records only live video without Overlay
            

            }

            //Capture Image
            void MainWindow::CaptureImage()
            {

                static int count = 0;
                QString fileName = DATA_STORE_LOCATION"ImageCaptured_" + QString::number(count) + ".png";
                QPixmap pixMap = graphicsView->grab(graphicsView->sceneRect().toRect());
                pixMap.save(fileName);
                count++;
            

            }

            Thanks

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

              That's because the recorder acts on the camera itself. It doesn't care about whatever you put on top of the preview content.

              One way would be to modify the gstreamer backend so it produces the overlay you want on top of your video.

              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
              • N Offline
                N Offline
                nikita.panchal09
                wrote on last edited by
                #7

                Hi,

                Thanks for the answer. I searched but didn't get the idea to modify gstreamer backend.
                Let me know the method or some reference link/site to modify gstreamer backend to perform overlay.

                Thanks!

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

                  Did you first check whether GStreamer capabilities fill your need in term of overlay ?

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

                  N 1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    Kane78
                    wrote on last edited by Kane78
                    #9

                    Yes facing same issue here...Hopefully will find an appropriate answer from here..As no proper source on google regarding gstreamer backend is available.Thanks MySchoolBucks

                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Did you first check whether GStreamer capabilities fill your need in term of overlay ?

                      N Offline
                      N Offline
                      nikita.panchal09
                      wrote on last edited by
                      #10

                      @SGaist
                      Hi Gaist,

                      Thank you for your time.

                      I have checked capabilities of Gstreamer to record video with overlay text using below gstreamer command:
                      gst-launch-1.0 -e v4l2src ! textoverlay text="Name" valignment=top halignment=left font-desc="Sans, 24" ! queue ! x264enc ! h264parse ! queue ! qtmux ! filesink location=testVideo

                      I have tried below methods with QT but didn't work out:

                      1. Create Object of "QGstreamerVideoOverlay", but it gives declaration error.

                      2. Do Gstreamer modification with below code, but didn't know how to set overlay text. It gives only live video in "grahicsview".

                        *gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY("autovideosink"),graphicsView->viewport()->effectiveWinId());
                        GstMessage msg = new GstMessage();
                        gst_is_video_overlay_prepare_window_handle_message(msg);

                      Thanks,
                      Nikita

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

                        I was rather thinking about the textoverlay plugin of GStreamer.

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

                        N 1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          vladstelmahovsky
                          wrote on last edited by
                          #12

                          use QAbstractVideoFilter for overlaying and recording

                          N 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            I was rather thinking about the textoverlay plugin of GStreamer.

                            N Offline
                            N Offline
                            nikita.panchal09
                            wrote on last edited by
                            #13

                            @SGaist
                            I didn't know how to integrate "textoverlay plugin" with QMediaRecorder.

                            It would be great if you can provide a reference document or link to use it.

                            Thanks,
                            Nikita

                            1 Reply Last reply
                            0
                            • V vladstelmahovsky

                              use QAbstractVideoFilter for overlaying and recording

                              N Offline
                              N Offline
                              nikita.panchal09
                              wrote on last edited by
                              #14

                              @vladstelmahovsky
                              Let me know how to use "QAbstractVideoFilter" to write text and use it with QMediaRecorder.

                              It would be great if you can provide a reference document or link to use it.

                              Thanks,
                              Nikita

                              V 1 Reply Last reply
                              0
                              • N nikita.panchal09

                                @vladstelmahovsky
                                Let me know how to use "QAbstractVideoFilter" to write text and use it with QMediaRecorder.

                                It would be great if you can provide a reference document or link to use it.

                                Thanks,
                                Nikita

                                V Offline
                                V Offline
                                vladstelmahovsky
                                wrote on last edited by
                                #15

                                @nikita.panchal09
                                you can read https://blog.qt.io/blog/2015/03/20/introducing-video-filters-in-qt-multimedia/
                                to get an idea about how to handle frames
                                each frame can be converted to QImage and each QImage can be used to draw text on it and provided to media recorder

                                1 Reply Last reply
                                1

                                • Login

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