Code:
#include <opencv2/opencv.hpp>using namespaceCV; #include<string>using namespacestd; #include<thread>intMain () {//Video SourceVideocapture Cap; Cap.open (0);//from the cameraMat src; Cap>>src; Videowriter writer; //Write video parameter preparation stringfilename ="Output.avi";//Output File name /*Union {int value; Char code[4]; } fourcc;//video encoding format fourcc.code[0] = ' M '; Fourcc.code[1] = ' J '; FOURCC.CODE[2] = ' P '; FOURCC.CODE[3] = ' G '; */ intFOURCC = static_cast<int> (VIDEOWRITER::FOURCC ('P','I','M','1')); Doublefps = -;//number of image frames played per second intDelay = +/fps; Cv::size Size= Cv::size (Cap.Get(Cv_cap_prop_frame_width), CAP.Get(Cv_cap_prop_frame_height));//Video Image size BOOLIsColor =true;//whether it is a color mapwriter.open (filename, FourCC, fps, size, iscolor); while(src.data) {writer<<src; Imshow ("src", SRC); Waitkey (delay); Cap>>src; } return 0;}
The saved video plays with the player, and the playback speed is always unusually fast, but the code logic is true. Search the problem online, found that others have encountered this problem, but did not find an accurate solution.
OpenCV Write a video