Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Regarding the saving the image in Android using QVideoProbe
QtWS25 Last Chance

Regarding the saving the image in Android using QVideoProbe

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.6k 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.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    Hi,

    I want to get the frames in video mode, i have used QML Camera, and QVideoProbe Class to get the frames. I am getting the frames but all the images are blank, i saw the size it is not 0 kb size, it was of 51.14 kb.

    And retreived the image and displayed in QLabel.
    It is blank.

    Here is the image

    https://postimg.org/image/ircprtnd7/

    Guidance is required.

    Thanks,

    Pradeep Kumar
    Qt,QML Developer

    raven-worxR 1 Reply Last reply
    0
    • Pradeep KumarP Pradeep Kumar

      Hi,

      I want to get the frames in video mode, i have used QML Camera, and QVideoProbe Class to get the frames. I am getting the frames but all the images are blank, i saw the size it is not 0 kb size, it was of 51.14 kb.

      And retreived the image and displayed in QLabel.
      It is blank.

      Here is the image

      https://postimg.org/image/ircprtnd7/

      Guidance is required.

      Thanks,

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Pradeep-Kumar said in Regarding the saving the image in Android using QVideoProbe:

      Guidance is required.

      code is required ;)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by Pradeep Kumar
        #3

        Hi the code snippet

        void className::funcName(){ 
                cam_ = new QQuickWidget();
                context_ = cam_->engine()->rootContext();
                context_->setContextProperty("MyWidget", this);
                cam_->setSource(QUrl("qrc:///declarative-camera.qml"));
                m_qmlCameraQObject = cam_->rootObject()->children().at(0)->findChild<QObject*>("CameraObject");
                QVariant mediaObject = m_qmlCameraQObject->property("mediaObject");
        
                if(mediaObject.isValid()){
        
                    qDebug()<<"----Variant object is valid----- \n";
        
                    m_QCameraObj = mediaObject.value<QCamera*>();
                
               if(m_QCameraObj && m_QCameraObj->availability() == QMultimedia::Available){
        
                        m_videoProbe = new QVideoProbe(this);
                        if(m_videoProbe->setSource(m_QCameraObj)){
        
         connect(m_videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(manageVideoFrame(QVideoFrame)));
        
                          }
                   }
              }
        }
        

        And in the slot:

        void ClassName::manageVideoFrame(QVideoFrame frame)
        {
                QVideoFrame cloneFrame(frame);
                cloneFrame.map(QAbstractVideoBuffer::ReadOnly);
        
                QImage::Format imageFormat;
                if((imageFormat = QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat())) == QImage::Format_Invalid)
                {
        
                    QImage image(cloneFrame.size(), QImage::Format_ARGB32);
        
                    if (!image.isNull())
                    {
        
                        QDateTime dateTime = dateTime.currentDateTime();
                        QString dateTimeString = dateTime.toString("yyyyMMddhhmmss");
        
                        QString appendString = "image_";
                        appendString.append(dateTimeString);
        
                        QString str = "/storage/sdcard1/DCIM/";
                        str.append(appendString+".jpg");
                }
           }
        }
        

        Pradeep Kumar
        Qt,QML Developer

        jsulmJ 1 Reply Last reply
        0
        • Pradeep KumarP Pradeep Kumar

          Hi the code snippet

          void className::funcName(){ 
                  cam_ = new QQuickWidget();
                  context_ = cam_->engine()->rootContext();
                  context_->setContextProperty("MyWidget", this);
                  cam_->setSource(QUrl("qrc:///declarative-camera.qml"));
                  m_qmlCameraQObject = cam_->rootObject()->children().at(0)->findChild<QObject*>("CameraObject");
                  QVariant mediaObject = m_qmlCameraQObject->property("mediaObject");
          
                  if(mediaObject.isValid()){
          
                      qDebug()<<"----Variant object is valid----- \n";
          
                      m_QCameraObj = mediaObject.value<QCamera*>();
                  
                 if(m_QCameraObj && m_QCameraObj->availability() == QMultimedia::Available){
          
                          m_videoProbe = new QVideoProbe(this);
                          if(m_videoProbe->setSource(m_QCameraObj)){
          
           connect(m_videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(manageVideoFrame(QVideoFrame)));
          
                            }
                     }
                }
          }
          

          And in the slot:

          void ClassName::manageVideoFrame(QVideoFrame frame)
          {
                  QVideoFrame cloneFrame(frame);
                  cloneFrame.map(QAbstractVideoBuffer::ReadOnly);
          
                  QImage::Format imageFormat;
                  if((imageFormat = QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat())) == QImage::Format_Invalid)
                  {
          
                      QImage image(cloneFrame.size(), QImage::Format_ARGB32);
          
                      if (!image.isNull())
                      {
          
                          QDateTime dateTime = dateTime.currentDateTime();
                          QString dateTimeString = dateTime.toString("yyyyMMddhhmmss");
          
                          QString appendString = "image_";
                          appendString.append(dateTimeString);
          
                          QString str = "/storage/sdcard1/DCIM/";
                          str.append(appendString+".jpg");
                  }
             }
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Pradeep-Kumar said in Regarding the saving the image in Android using QVideoProbe:

          if((imageFormat = QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat())) == QImage::Format_Invalid)

          Shouldn't it be != instead of == here:

          if((imageFormat = QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat())) == QImage::Format_Invalid)
          

          You create a image:

          QImage image(cloneFrame.size(), QImage::Format_ARGB32);
          

          but you do not write any data into that image and I cannot see where you actualy save the image.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Pradeep KumarP Offline
            Pradeep KumarP Offline
            Pradeep Kumar
            wrote on last edited by
            #5

            Hi,

            Sorry about that , i have used save method.

                   if (!image.isNull())
                    {
            
                        QDateTime dateTime = dateTime.currentDateTime();
                        QString dateTimeString = dateTime.toString("yyyyMMddhhmmss");
            
                        QString appendString = "image_";
                        appendString.append(dateTimeString);
            
                        QString str = "/storage/sdcard1/DCIM/";
                        str.append(appendString+".jpg");
            
                        if (image.save(str, "JPG"))
                        {
                            qDebug()<<"Image saved successfully \n";
                        }
                        else
                        {
                            qDebug()<<"There is problem in image saving \n";
                        }
                }
            

            Image is inserted successfully.

            Thanks,

            Pradeep Kumar
            Qt,QML Developer

            1 Reply Last reply
            0
            • Pradeep KumarP Offline
              Pradeep KumarP Offline
              Pradeep Kumar
              wrote on last edited by
              #6

              Hi,

              Is the code not valid or am i missing something?.

              Thanks,

              Pradeep Kumar
              Qt,QML Developer

              jsulmJ 1 Reply Last reply
              0
              • Pradeep KumarP Pradeep Kumar

                Hi,

                Is the code not valid or am i missing something?.

                Thanks,

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

                @Pradeep-Kumar As I said before I cannot see where you're writing anything into image.
                You only create one:

                QImage image(cloneFrame.size(), QImage::Format_ARGB32);
                

                but never write any pixel data into it.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • Pradeep KumarP Offline
                  Pradeep KumarP Offline
                  Pradeep Kumar
                  wrote on last edited by
                  #8

                  Can u clarify and correct the previous code snippet .
                  Correct me if i am wrong , i didnt assign the frames captured to QImage, is that the point?.

                  Thanks,

                  Pradeep Kumar
                  Qt,QML Developer

                  jsulmJ 1 Reply Last reply
                  0
                  • Pradeep KumarP Pradeep Kumar

                    Can u clarify and correct the previous code snippet .
                    Correct me if i am wrong , i didnt assign the frames captured to QImage, is that the point?.

                    Thanks,

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

                    @Pradeep-Kumar Yes, you do not write anything into the image.
                    QVideoFrame documentation says:
                    "The pixel contents of a video frame can be mapped to memory using the map() function. While mapped, the video data can accessed using the bits() function, which returns a pointer to a buffer."
                    So, first you need to map the frame data into memory calling http://doc.qt.io/qt-5/qvideoframe.html#map, then you can access the frame data using http://doc.qt.io/qt-5/qvideoframe.html#bits and write the data into the image via http://doc.qt.io/qt-5/qimage.html#loadFromData.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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