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. qt creator using QMediaRecorder with usb cam in raspberrypi
Forum Updated to NodeBB v4.3 + New Features

qt creator using QMediaRecorder with usb cam in raspberrypi

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
14 Posts 3 Posters 2.4k Views
  • 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.
  • M Offline
    M Offline
    mouaiad salaas
    wrote on last edited by
    #1

    i am trying to use usb cam with raspberry pi 3 to creat program that stream video from cam and record it . i am using qt creator to do that but there is a problem in QMediaRecorder after i record a video the video is just show one image please can any one help me to solve this problem . the code is here

    #include "widget.h"
    #include "ui_widget.h"
    #include <QCamera>
    #include <QCameraViewfinder>
    #include <QCameraImageCapture>
    #include <QVBoxLayout>
    #include <QFileDialog>
    #include <QMediaRecorder>
    #include <QMediaService>
    #include <QCameraInfo>
    #include <QMediaMetaData>
    
    #include <QMessageBox>
    #include <QPalette>
    
    #include <QtWidgets>
        
    ui->setupUi(this);
    mCamera             = new QCamera(this);
    
    mCameraViewfinder   = new QCameraViewfinder(this);
    mCameraImageCapture = new QCameraImageCapture(mCamera,this);
    mCameraVideoRecord  = new QMediaRecorder(mCamera,this);
    mLayout             = new QVBoxLayout;
    
    mCamera->setViewfinder(mCameraViewfinder);
    mLayout->addWidget(mCameraViewfinder);
    ui->frame->setLayout(mLayout); 
    }
    
    Widget::~Widget()
    {
    delete ui;
    }
    
    void Widget::on_PushButton_clicked(){
    mCamera->setCaptureMode(QCamera::CaptureVideo);
    mCamera->start();
    mCameraVideoRecord->record();
    }
    
    
    void Widget::on_pushButton_clicked()
    {
    mCamera->setCaptureMode(QCamera::CaptureStillImage);
    mCamera->start(); // Viewfinder frames start flowing
    mCamera->searchAndLock();
    mCameraImageCapture->capture();
    mCamera->unlock();
    }
    
    void Widget::on_pushButton_2_clicked()
    {
    mCameraVideoRecord->stop();
    }
    
    jsulmJ 1 Reply Last reply
    0
    • M mouaiad salaas

      i am trying to use usb cam with raspberry pi 3 to creat program that stream video from cam and record it . i am using qt creator to do that but there is a problem in QMediaRecorder after i record a video the video is just show one image please can any one help me to solve this problem . the code is here

      #include "widget.h"
      #include "ui_widget.h"
      #include <QCamera>
      #include <QCameraViewfinder>
      #include <QCameraImageCapture>
      #include <QVBoxLayout>
      #include <QFileDialog>
      #include <QMediaRecorder>
      #include <QMediaService>
      #include <QCameraInfo>
      #include <QMediaMetaData>
      
      #include <QMessageBox>
      #include <QPalette>
      
      #include <QtWidgets>
          
      ui->setupUi(this);
      mCamera             = new QCamera(this);
      
      mCameraViewfinder   = new QCameraViewfinder(this);
      mCameraImageCapture = new QCameraImageCapture(mCamera,this);
      mCameraVideoRecord  = new QMediaRecorder(mCamera,this);
      mLayout             = new QVBoxLayout;
      
      mCamera->setViewfinder(mCameraViewfinder);
      mLayout->addWidget(mCameraViewfinder);
      ui->frame->setLayout(mLayout); 
      }
      
      Widget::~Widget()
      {
      delete ui;
      }
      
      void Widget::on_PushButton_clicked(){
      mCamera->setCaptureMode(QCamera::CaptureVideo);
      mCamera->start();
      mCameraVideoRecord->record();
      }
      
      
      void Widget::on_pushButton_clicked()
      {
      mCamera->setCaptureMode(QCamera::CaptureStillImage);
      mCamera->start(); // Viewfinder frames start flowing
      mCamera->searchAndLock();
      mCameraImageCapture->capture();
      mCamera->unlock();
      }
      
      void Widget::on_pushButton_2_clicked()
      {
      mCameraVideoRecord->stop();
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mouaiad-salaas Which of the two slots, which have almost identical names (which is bad!) do you mean? Because one of them records still images...

      M 1 Reply Last reply
      0
      • jsulmJ jsulm

        @mouaiad-salaas Which of the two slots, which have almost identical names (which is bad!) do you mean? Because one of them records still images...

        M Offline
        M Offline
        mouaiad salaas
        wrote on last edited by
        #3

        @jsulm thank you very much for your reply .
        yes it is right that bad but this is just a test .
        the first one which has
        mCamera->setCaptureMode(QCamera::CaptureVideo);
        mCamera->start();
        mCameraVideoRecord->record();
        is to start record and the last one is to stop the recording

        jsulmJ 1 Reply Last reply
        0
        • M Offline
          M Offline
          mouaiad salaas
          wrote on last edited by
          #4

          the first one is to start recording
          the second is to capture image and save it
          the last one is to stop recording

          the image capture and save is working but video recording is not
          please can you help me to solve it

          jsulmJ 1 Reply Last reply
          0
          • M mouaiad salaas

            @jsulm thank you very much for your reply .
            yes it is right that bad but this is just a test .
            the first one which has
            mCamera->setCaptureMode(QCamera::CaptureVideo);
            mCamera->start();
            mCameraVideoRecord->record();
            is to start record and the last one is to stop the recording

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • M mouaiad salaas

              the first one is to start recording
              the second is to capture image and save it
              the last one is to stop recording

              the image capture and save is working but video recording is not
              please can you help me to solve it

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @mouaiad-salaas Please connect a slot to https://doc.qt.io/qt-5/qmediarecorder.html#error-1 and check what https://doc.qt.io/qt-5/qmediarecorder.html#errorString returns. You should always have error handling in your apps!

              M 1 Reply Last reply
              0
              • jsulmJ jsulm

                @mouaiad-salaas Please connect a slot to https://doc.qt.io/qt-5/qmediarecorder.html#error-1 and check what https://doc.qt.io/qt-5/qmediarecorder.html#errorString returns. You should always have error handling in your apps!

                M Offline
                M Offline
                mouaiad salaas
                wrote on last edited by
                #7

                @jsulm
                the code i add:
                connect(mCameraVideoRecord, QOverloadQMediaRecorder::Error::of(&QMediaRecorder::error),
                ={
                qDebug() <<"test error";
                qDebug() << mCameraVideoRecord->errorString();
                });

                application output :
                11:09:36: Starting /home/pi/build-CameraTest-Desktop-Debug/CameraTest...
                libEGL warning: DRI2: failed to authenticate
                qt5ct: using qt5ct plugin
                test error
                "Service has not been started"

                jsulmJ 1 Reply Last reply
                0
                • M mouaiad salaas

                  @jsulm
                  the code i add:
                  connect(mCameraVideoRecord, QOverloadQMediaRecorder::Error::of(&QMediaRecorder::error),
                  ={
                  qDebug() <<"test error";
                  qDebug() << mCameraVideoRecord->errorString();
                  });

                  application output :
                  11:09:36: Starting /home/pi/build-CameraTest-Desktop-Debug/CameraTest...
                  libEGL warning: DRI2: failed to authenticate
                  qt5ct: using qt5ct plugin
                  test error
                  "Service has not been started"

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @mouaiad-salaas You should take a look at https://doc.qt.io/qt-5/qtmultimedia-multimediawidgets-camera-example.html

                  M 2 Replies Last reply
                  0
                  • jsulmJ jsulm

                    @mouaiad-salaas You should take a look at https://doc.qt.io/qt-5/qtmultimedia-multimediawidgets-camera-example.html

                    M Offline
                    M Offline
                    mouaiad salaas
                    wrote on last edited by
                    #9

                    @jsulm i used the example but now i cannot click on video button it seems like not activated
                    and i got this in application output :

                    Unsupported media type: "{32595559-0000-0010-8000-00AA00389B71}"
                    Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"
                    Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"
                    Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"
                    Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"
                    Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"
                    Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"

                    jsulmJ 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @mouaiad-salaas You should take a look at https://doc.qt.io/qt-5/qtmultimedia-multimediawidgets-camera-example.html

                      M Offline
                      M Offline
                      mouaiad salaas
                      wrote on last edited by
                      #10

                      @jsulm what is the problem how can i solve it?

                      1 Reply Last reply
                      0
                      • M mouaiad salaas

                        @jsulm i used the example but now i cannot click on video button it seems like not activated
                        and i got this in application output :

                        Unsupported media type: "{32595559-0000-0010-8000-00AA00389B71}"
                        Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"
                        Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"
                        Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"
                        Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"
                        Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"
                        Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @mouaiad-salaas said in qt creator using QMediaRecorder with usb cam in raspberrypi:

                        Unsupported media type: "{47504A4D-0000-0010-8000-00AA00389B71}"

                        What media type did you configure?

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mouaiad salaas
                          wrote on last edited by
                          #12

                          i did not change any thing in the code just enabled the tabs where should i edit the media type??

                          jsulmJ 1 Reply Last reply
                          0
                          • M mouaiad salaas

                            i did not change any thing in the code just enabled the tabs where should i edit the media type??

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @mouaiad-salaas I posted the link to the example...

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              lambinator
                              wrote on last edited by lambinator
                              #14

                              Is there any resolution to the Unsupported media type issue? It appears the camera is returning a list of pixel formats and it doesn't like the YUY2 {32595559-0000-0010-8000-00AA00389B71} and Motion JPEG {47504A4D-0000-0010-8000-00AA00389B71} formats.

                              I'm still trying to wrap my head around how to do camera configurations, and looking at the code in dscamerasession.cpp it doesn't look like there's much one can do to fix this issue but I haven't dug too deep in yet.

                              I should note that the camera is working correctly, but the terminal is full of these messages when I hit QCamera::load() function, so I guess I'm just wondering if there's a way to hint to the camera class to ignore these formats ahead of time.

                              Appears this works just fine in QT6 and QT5 doesn't support recording video anyway :P

                              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