Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

VideoWriter unhandled exception

Hi guys,

I was recording my video output combining 6 videos into one and used the DIVX encoding using VideoWriter.

The video recorded fine until it always returned "unhandled exception" at some point. The output video can be played only up to the point it crashed.

Can someone point out what's might be the reason?

int main(int, char**) {

(Contains deleted code lines due to file location for anonymity)

if (!capture1.isOpened() && !capture2.isOpened() && !capture3.isOpened() && !capture4.isOpened() && !capture5.isOpened() && !capture6.isOpened())  // check if we succeeded
    return -1;


struct timeb start, end;
int diff;
int i = 0;
long buffer = 0;


VideoWriter video("Path", CV_FOURCC('D', 'I', 'V', 'X'), 5, Size(1058, 710), true);
bool State = false;

namedWindow("Video", 1);
for (;;)
{

    ftime(&start);
    Mat frame1, frame2, frame3, frame4, frame5, frame6;

    capture1 >> frame1; // get a new frame from camera
    capture2 >> frame2;
    capture3 >> frame3;
    capture4 >> frame4;
    capture5 >> frame5;
    capture6 >> frame6;

    int width = frame1.size().width * 0.5;
    int height = frame1.size().height * 0.7;

    resize(frame1, frame1, Size(height, width), 0, 0, INTER_CUBIC);
    resize(frame2, frame2, Size(height, width), 0, 0, INTER_CUBIC);
    resize(frame3, frame3, Size(height, width), 0, 0, INTER_CUBIC);
    resize(frame4, frame4, Size(height, width), 0, 0, INTER_CUBIC);
    resize(frame5, frame5, Size(height, width), 0, 0, INTER_CUBIC);
    resize(frame6, frame6, Size(height, width), 0, 0, INTER_CUBIC);

    Mat dst_img(cv::Size(frame1.size().width * 3 + 50, frame1.size().height * 2 + 70), frame1.type(), cv::Scalar(0, 0, 0));



    frame1.copyTo(dst_img(Rect(10, 10, frame1.cols, frame1.rows)));
    frame2.copyTo(dst_img(Rect(frame2.size().width + 20, 10, frame2.cols, frame2.rows)));
    frame3.copyTo(dst_img(Rect(30 + frame2.size().width * 2, 10, frame3.cols, frame3.rows)));
    frame4.copyTo(dst_img(Rect(10, frame1.size().height + 20, frame4.cols, frame4.rows)));
    frame5.copyTo(dst_img(Rect(frame2.size().width + 20, frame1.size().height + 20, frame4.cols, frame4.rows)));
    frame6.copyTo(dst_img(Rect(30 + frame2.size().width * 2, frame1.size().height + 20, frame4.cols, frame4.rows)));

    ////////////////////////////////////////////////////////////////////////////////////
    // Calculating Frequency Output Region /////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////
    std::stringstream FreqDisp;
    ftime(&end);
    diff = (int)(1000.0 * (end.time - start.time) + (end.millitm - start.millitm));
    buffer = diff + buffer;


    if (10 + buffer * 0.01 > 20000){
        return 0;
    }

    FreqDisp << std::setprecision(1) << std::to_string(10 + buffer * 0.01);


    putText(dst_img, FreqDisp.str() + " MHz", Point(20, dst_img.size().height - 20), FONT_HERSHEY_PLAIN, 1, Scalar::all(255), 2, 8);
    putText(dst_img, "Control", Point(dst_img.size().width - 100, dst_img.size().height - 20), FONT_HERSHEY_PLAIN, 1, Scalar::all(255), 2, 8);

    imshow("Video", dst_img);
    video.write(dst_img);

    if (waitKey(30) >= 0) break;
}

return 0;

}