Ask Your Question

Revision history [back]

Hi Berak,

Based on you suggestion of passing an image into cv::Mat and using Video Writer, I am trying to do that but the video file generated is 0 bytes always. Could you have a look at the code and tell me where I am going wrong?

//initiate video writer settings
    Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));
    QString dateTime = QDateTime::currentDateTime().toString("dddd dd MMMM yyyy, hh-mm-ss ");
    QString fileNameVideo = "Video_" + dateTime + ".avi";
    QDir::setCurrent("Recordings/");
    VideoWriter temp_writer(fileNameVideo.toStdString().c_str(), CV_FOURCC('D', 'I', 'V', 'X'), 30, frameSize, true);//DIVX or XVID or MJPG

    m_videoWriter = temp_writer;

//passing QImage into cv::Mat continuously
cv::Mat frame(qimg.height(), qimg.width(),CV_8UC3, (void *)(qimg.constBits()), (qimg.bytesPerLine()));
if(!m_videoWriter.isOpened())
    qDebug()<<"Failed to write the video";
m_videoWriter.write(frame);

// with the help of a button releasing video writer
m_videoWriter.release();

When I try to check if the cv::Mat frame has received an image by passing it to QLabel, it shows the image that means QImage is getting passed into cv::Mat frame but it is not getting written inside VideoWriter and I don't know why.

Any suggestion would be helpful. Thank you for your time and knowledge.