Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to record video using QGraphicsView with Overlay text?



  • Hi,

    I want to overlay text on Live video and record video with overlay text. I have tried two ways as per below but not succeed.

    1. Using QGraphicsView:
      Problem: Unable to find a way to record video using QGraphicsView.

      *QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
      foreach (const QCameraInfo &cameraInfo, cameras)
      {
      if (cameraInfo.deviceName() == "/dev/video0")
      pCamera = new QCamera(cameraInfo, this);
      }

      QGraphicsVideoItem *videoItem = new QGraphicsVideoItem;
      scene = new QGraphicsScene(this);
      graphicsView = new QGraphicsView(scene);

      scene->addItem(videoItem);
      text = scene->addText("Hello World"); //Text Overlay
      scene->addItem(text);

      pCamera->setViewfinder(videoItem);
      QVBoxLayout *cBox2 = new QVBoxLayout();
      cBox2->addWidget(graphicsView);
      cBox2->setSpacing(0);

      ui->scrollArea->setLayout(cBox2);

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

      if (pCamera->isCaptureModeSupported(QCamera::CaptureVideo))
      pCamera->setCaptureMode(QCamera::CaptureVideo);
      pMediaRecorder->setOutputLocation(QUrl::fromLocalFile(DATA_STORE_LOCATION"sample.mp4"));
      pMediaRecorder->record();*

      It is not recording video with overlay text.

    2. Using CameraViewfinder:
      Problem: Unable to find a way to add overlay and perform zoom Operations.

      *QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
      foreach (const QCameraInfo &cameraInfo, cameras)
      {
      if (cameraInfo.deviceName() == "/dev/video0")
      pCamera = new QCamera(cameraInfo, this);
      }

      pCameraViewfinder = new QCameraViewfinder(this);
      pCameraImageCapture = new QCameraImageCapture(pCamera, this);
      pVBoxLayout = new QVBoxLayout();

      //Set Camera View
      pCamera->setViewfinder(pCameraViewfinder);
      pVBoxLayout->addWidget(pCameraViewfinder);
      ui->scrollArea->setLayout(pVBoxLayout);

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

      if (pCamera->isCaptureModeSupported(QCamera::CaptureVideo))
      pCamera->setCaptureMode(QCamera::CaptureVideo);
      pMediaRecorder->setOutputLocation(QUrl::fromLocalFile(DATA_STORE_LOCATION"sample.mp4"));
      pMediaRecorder->record();*

    Looking to hearing from you.

    Thanks,
    Nikita Panchal


Log in to reply