Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9098209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:18:23+00:00 2026-06-17T00:18:23+00:00

I am using opencv to capture a video directly from webcam and saving it

  • 0

I am using opencv to capture a video directly from webcam and saving it to a avi file. I have used the following code:

 #include "StdAfx.h"


using namespace std;
using namespace cv;


int _tmain()
{
    VideoCapture src;
    src.open(1);
    if(!src.isOpened())
    {
        cout<<"could not open camera\n";
        return -1;
    }
    else
    {
        cout<<"camera opened\n";
    }

    int ex=static_cast<int>(src.get(CV_CAP_PROP_FOURCC));
    Size s(Size((int)src.get(CV_CAP_PROP_FRAME_WIDTH),(int)src.get((CV_CAP_PROP_FRAME_HEIGHT))));
    VideoWriter out;
    out.open("out.avi",ex,20,s);
    while(1)
    {
        Mat im;
        src>>im;
        imshow("vid",im);
        out<<im;
        char c;
        c=cvWaitKey(50);
        if(c==27)
            break;
    }

    system("pause");
}

all the headers are included in stdafx.h.
But actually I am getting a avi file of size 0bite. How to fix this thing? I need to record the webcam video without displaying.


Note: I’m new in openCV and I am using Visual Studio 2010

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:18:25+00:00Added an answer on June 17, 2026 at 12:18 am

    Actually there is no logical error in your program. The only problem is the FOUR_CC Codec you are using to write the video.

    When I ran your code, I faced the exact problem as yours. When I added the error checking to the out.open() function, I found the problem.

    Most probably, the FOUR_CC codec of the camera is not supported by the avi container.

    As you are using Windows, a good option is to use CV_FOURCC_PROMPT in the 2nd argument of out.open.

    This will open a pop up list box containing different FOUR_CC codecs available. If you don’t know which one to choose, just select Full Frames (Uncompressed). It is the most compatible option but will increase the size of the output video file.

    The final code should look like this:

    if(!out.open("out.avi",CV_FOURCC_PROMPT,20,s))
    {
        cout<<"Writer Not Opened"<<endl;
        return -1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to play a video using opencv (the video is an avi file
I have been porting some video processing code to C++ using OpenCV 2.4.3. The
Hi I am trying to play a video using the following code: //#include <stdio.h>
In my C/C++ program, I'm using OpenCV to capture images from my webcam. The
I am trying to read an AVI file using openCV. After getting the capture,
I am using the following code from the samples folder of OpenCV for face-detection
Using OpenCV, saving a CvMat structure into a YAML file on the disk is
I'm using OpenCV v2.4.1 And this is the code I'm using #include opencv2/opencv.hpp #include
Hi I am trying to detect web cam in opencv using following code I
I am using OpenCV 2.2 compiled and built from source for iOS. I used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.