OpenCV Write a video

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.