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. Issue with VideoWriter
QtWS25 Last Chance

Issue with VideoWriter

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 629 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
    Malikov
    wrote on last edited by Malikov
    #1

    Hi

    I'm trying to create video file using cv VideoWriter class in c++. I'm getting frames convert them to QImage img and display them on GUI well. I want to create video file .avi / .mp4 with the frames when I click on button on GUI.

    Attached procedure to creating the VideoWriter and write frames .

    if(!m_isCreateVideoWriter)
    {
                        QString savedPath = "/home/nvidia/Pictures/";
                        CvSize size = cvSize(2048, 1148);
                        char cur[1024];
                        timespec time;
                        clock_gettime(CLOCK_REALTIME, &time);
                        tm nowtm;
                        localtime_r(&time.tv_sec, &nowtm);
                        sprintf(cur, "%s%04d%02d%02d%02d%02d%02d.avi", savedPath.toLocal8Bit().data(), nowtm.tm_year+1900, nowtm.tm_mon+1, nowtm.tm_mday, nowtm.tm_hour, nowtm.tm_min, nowtm.tm_sec);
                        video = cv::VideoWriter(cur,cv::VideoWriter::fourcc('M','J','P','G'),25.0, size, 1);
                        m_isCreateVideoWriter = true;
    }
    else
    {
                        //Clicked 'Stop Record' button
                        //Close video writer
                        if (CamObject::getInstance()->m_bFinishRec)
                        {
                            video.release();
                            m_isRecording = false;
                            m_isCreateVideoWriter = false;
                            return;
                        }
                        // Recording...
                        else
                        {
                            videoFrame = QImageToCvMat(img); //img = QImage(frame.width, frame.height, QImage::Format_Grayscale8);
                            video.write(videoFrame);
                        }
    }
    
    
    

    Also I created method QImageToCvMat because their is not write method with QImage :

    cv::Mat QImageToCvMat(QImage &inImage)
    {
        cv::Mat mat(inImage.height(), inImage.width(),
                    CV_8UC1, inImage.bits(), inImage.bytesPerLine());
        return mat;
    }
    

    When I debug I'm getting signal aborted error on write frame line and the program collapse.

    video.write(videoFrame);
    

    Any one familiar with this issue or can kindly give advice?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      I haven't used VideoWriter
      But from the documentation:

      cv::VideoWriter::VideoWriter ( const String & filename,
      int fourcc,
      double fps,
      Size frameSize,
      bool isColor = true
      )
      Parameters
      isColor If it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames.

      and

      virtual void cv::VideoWriter::write ( InputArray image )
      Parameters
      image The written frame. In general, color images are expected in BGR format.

      Since you are writing grayscale images, I think you should pass 0 as isColor while currently you are using 1.
      Also I think this may be not quite related to Qt...Wouldn't it be better to find an OpenCV forum to ask this kind of questions?
      (Of course if the crash is due to the image conversion, then it is kind of Qt related.)

      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