c++ - Trouble writing video to file using opencv -
i trying write captured video file using opencv in c++ inside visualstudio 2013. programs seems capture video webcam on laptop , able save each frame image when write frames video file, end 6kb file. program gives me no error have followed instruction opencv document.
i pasting program review. please suggest how may make successful program.
thank you.
#include <stdio.h> #include <iostream> #include "opencv2\core\core.hpp" #include "opencv2\highgui\highgui.hpp" using namespace std; using namespace cv; int main() { videocapture video_capture(0); if (!video_capture.isopened()) { cout << "error in opening video feed!" << endl; getchar(); return -1; } // creating window view video feed string window_name = "video_feed"; namedwindow(window_name, cv_window_autosize); // mat frame; // filename string filename = "...\\first_recording.avi"; // 4 character code int fcc = cv_fourcc('m', 'p', '4', '2'); // frames per sec int fps = 10; // frame size size frame_size(cv_cap_prop_frame_width, cv_cap_prop_frame_height); videowriter video_writer = videowriter(filename,fcc,fps,frame_size,true); if (!video_writer.isopened())// || video_writer.isopened == null) { cout << "error in opening video writer feed!" << endl; getchar(); return -1; } int frame_count = 0; while (frame_count < 100) { bool cap_success = video_capture.read(frame); if (!cap_success) { cout << "error in capturing image camera feed!" << endl; getchar(); break; } imshow(window_name, frame); //imwrite("cap.jpg", frame); video_writer.write(frame); switch (waitkey(10)) { case 27: return 0; break; } frame_count++; } //scvreleasevideowriter; destroywindow(window_name); return 0; }
please find below piece of code write video file.
int main(int argc, char* argv[]) { // load input video cv::videocapture input_cap("test8.avi"); if (!input_cap.isopened()) { std::cout << "!!! input video not opened" << std::endl; return -1; } // setup output video cv::videowriter output_cap("output.avi", input_cap.get(cv_cap_prop_fourcc), input_cap.get(cv_cap_prop_fps), cv::size(input_cap.get(cv_cap_prop_frame_width), input_cap.get(cv_cap_prop_frame_height))); if (!output_cap.isopened()) { std::cout << "!!! output video not opened" << std::endl; return -1; } // loop read frames input capture , write output capture cv::mat frame; while (true) { if (!input_cap.read(frame)) break; output_cap.write(frame); } // release capture interfaces input_cap.release(); output_cap.release(); return 0; }
Comments
Post a Comment