Incorrect Duration from VideoWriter [closed]

asked 2016-06-09 08:52:00 -0600

QMurphy gravatar image

updated 2016-06-09 17:00:04 -0600

I'm using a VideoWriter object to record from a camera into an AVI file. When I open that AVI file up in VLC, it displays the full length of the video and plays the whole thing. However, Windows and ffprobe only report the video to be ~8 seconds. Furthermore, when I try to use a VideoCapture object to scan the video back in with OpenCV, it stops at the 8 second mark and won't go any further. I'm not sure why some sources report the video to be much shorter than it is. Here's the basic code:

cv::VideoWriter writer;
cv::Mat imageBayer, imageBGR;
int fps = 40;
int width = 1920;
int height = 1080;

writer.open("C:/Users/jsmith/Desktop/file.avi", cv::VideoWriter::fourcc('I', 'Y', 'U', 'V'), fps, cv::Size(width, height), true);
if (!writer.isOpened()) {
    std::cerr << "Unable to open video writer." << std::endl;
    return -1;
}

std::chrono::high_resolution_clock::time_point wakeTime = std::chrono::high_resolution_clock::now();
while (1) {
    std::this_thread::sleep_until(wakeTime);
    cam >> imageBayer;
    cv::cvtColor(imageBayer, imageBGR, cv::COLOR_BayerRG2BGR);
    writer << imageBGR;
    wakeTime = wakeTime + std::chrono::microseconds(1000000 / fps);
}

Any help would be appreciated, I can't figure out what's going on. I'm using OpenCV 3.1.

Edit: Upon more testing, I think it's because I was terminating the program with Ctrl+C and not letting the deconstructor get called.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by QMurphy
close date 2016-06-09 17:00:24.246825