I am attempting to using the OpenCV VideoWriter class to save a two camera video feed to a single video file. I am using the FFMPEG API to ahcieve the desired outcome and am trying to generate an .mkv file with the Fourcc code FFV1 for lossless frame writing. Currently I am expriencing upon launching of the pipeline the file writer is creating a file in the directory specified and upon completion of the pipeline the writer is transformed into a video file .mkv however no frames are being written to said file. My constructor:
cv::VideoWriter writer(out_vid_name + ".mkv", cv::VideoWriter::fourcc('F','F','V','1'), cam_fps,frame_double_size, true);
Note that cv::Size(3840,1080) = frame_double_size and cam_fps is a param
My video capture:
cv::VideoCapture cap(out_vid_name + ".mkv", cv::CAP_FFMPEG);
and my writer:
while (controller->running && ros::ok()) //Shutdown race condition exists. One thread will have to be SIGTERM'ed
{
std::shared_lock<std::shared_mutex> guard(doubleSaveFrame->mtx);
doubleSaveFrame->cond_var.wait(guard, [&]{ return doubleSaveFrame->cond_bool_save; });
doubleSaveFrame->cond_bool_save = false;
std_msgs::String msg;
msg.data = std::to_string(frame_count);
frame_count++;
frame_pub.publish(msg);
writer.write(doubleSaveFrame->getHost());
cv::Mat frame = doubleSaveFrame->getHost();
int rows = frame.rows;
int cols = frame.cols;
std::cout << "rows: " << std::to_string(rows) << " cols: "<< std::to_string(cols) << std::endl;
cv::imwrite("home/Documents/camera/imwritefun"+ std::to_string(frame_count) +".JPG", doubleSaveFrame->getHost());
}
writer.release();
Note that this code above produced successfully the camera frames to file when cv::imwrite was executed, however the the writer failed to write to video file. I am very new to OpenCV and the associated methods used here, if anyone has an idea on what is causing the issue that would be extremely helpful as research has not prevailed a solution.