'cv::VideoWriter isn't saving any video
I'm trying to get cv::VideoWriter to work but I'm having trouble.
if (recording)
{
vid.write(imagecl);
std::cout << "\trecording..." << std::endl;
}
cv::imshow(CAMERA_TOPIC, imagecl);
rec_key = cv::waitKey(1);
imagecl.release();
if (rec_key == 114 && !recording)
{
std::cout << "\t\tStarted Recording" << std::endl;
auto now = std::chrono::system_clock::now();
now_time = std::chrono::system_clock::to_time_t(now);
vidname = VIDEO_PATH + date_str(std::ctime(&now_time)) + ".mp4";
std::cout << "\tSaving video to -> " << vidname << std::endl;
codec = cv::VideoWriter::fourcc('a','v','c','1');
vid = cv::VideoWriter(vidname, codec, 30, cv::Size(frame_width, frame_height), true);
recording = true;
}
else if (rec_key == 115 && recording)
{
std::cout << "\t\tEnded recording" << std::endl;
vid.release();
recording = false;
}
This code is part of a video_recorder function what is executing inside an infinite loop. I'm using another thread to fill the imagecl with the frames I want to record. The cv::imshow is working properly (it opens a window and displays the frames), but I can't get to save videos with cv::VideoWriter. The 'r' and 's' keys are triggering the conditions as I get the terminal messages of "started recording" and then "recording" each loop and then "ended recording". I double checked the path and it is correct. I'm saving to "/home/username/videoname.mp4". What am I doing wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
