Ask Your Question

niteshuc's profile - activity

2019-05-08 11:04:13 -0600 received badge  Famous Question (source)
2017-03-16 17:45:40 -0600 received badge  Student (source)
2016-09-19 02:02:10 -0600 received badge  Notable Question (source)
2016-01-16 01:11:59 -0600 received badge  Popular Question (source)
2014-02-27 07:14:38 -0600 received badge  Teacher (source)
2014-02-27 01:25:27 -0600 received badge  Self-Learner (source)
2014-02-26 22:22:12 -0600 answered a question Unable to create video with CV_FOURCC('Y','U','Y','V')

I solved the problem by compiling opencv with "WITH_FFMPEG=ON" option and changing FOURCC to CV_FOURCC('M','J','P','G').

2014-02-19 22:22:50 -0600 commented answer Unable to create video with CV_FOURCC('Y','U','Y','V')

I had already tried with -1 in place of FOURCC ,but still the problem is the same.

2014-02-19 22:20:21 -0600 commented question Unable to create video with CV_FOURCC('Y','U','Y','V')

Well i changed the includes from opencv to opencv2 , but still problem is not solved.

2014-02-19 06:22:40 -0600 asked a question Unable to create video with CV_FOURCC('Y','U','Y','V')

Hi,

I am working on opencv version 2.4.8 under Ubuntu 12.04 LTS environment.

I am facing problem while creating a video ,while capturing from a webcam (UVC compatible).

It is giving error

"Could not create video."

Here is my code:

// Include standard OpenCV headers
#include <iostream>
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace std;

// All the new API is put into "cv" namespace
using namespace cv;

int main (int argc, char *argv[])
{
    // Open the default camera
    VideoCapture capture(0); 

    // Check if the camera was opened
    if(!capture.isOpened())
    {
        cerr << "Could not create capture";
        return -1;
    }

    // Get the properties from the camera
    double width = capture.get(CV_CAP_PROP_FRAME_WIDTH);
    double height = capture.get(CV_CAP_PROP_FRAME_HEIGHT);

    cout << "Camera properties\n";
    cout << "width = " << width << endl <<"height = "<< height << endl;

    // Create a matrix to keep the retrieved frame
    Mat frame;

    // Create a window to show the image
    namedWindow ("Capture", CV_WINDOW_AUTOSIZE);

    // Create the video writer
    VideoWriter video("capture.avi", CV_FOURCC('Y', 'U', 'Y', 'V'), 30, cvSize((int)width,(int)height));
    //video.open("capture.avi", -1, 30, cvSize((int)width,(int)height));

    // Check if the video was opened
    if(!video.isOpened())
    {
        cerr << "Could not create video.";
        return -1;
    }

    cout << "Press Esc to stop recording." << endl;

    // Get the next frame until the user presses the escape key
    while(true)
    {
        // Get frame from capture
        capture >> frame;

        // Check if the frame was retrieved
        if(!frame.data)
        {
            cerr << "Could not retrieve frame.";
            return -1;
        }

        // Save frame to video
        video << frame;

        // Show image
        imshow("Capture", frame);

        // Exit with escape key
        if(waitKey(1) == 27)
            break;
    }

    // Exit
    return 0;
}

The information about camera is as follows.

$ v4l2-ctl --all

Driver Info (not using libv4l2):
    Driver name   : uvcvideo
    Card type     : USB2.0 Camera
    Bus info      : usb-0000:00:1d.0-1.5
    Driver version: 3.2.40
    Capabilities  : 0x04000001
        Video Capture
        Streaming
Video input : 0 (Camera 1: ok)
Format Video Capture:
    Width/Height  : 640/480
    Pixel Format  : 'YUYV'
    Field         : None
    Bytes per Line: 1280
    Size Image    : 1045178410
    Colorspace    : SRGB
Crop Capability Video Capture:
    Bounds      : Left 0, Top 0, Width 640, Height 480
    Default     : Left 0, Top 0, Width 640, Height 480
    Pixel Aspect: 1/1
Streaming Parameters Video Capture:
    Capabilities     : timeperframe
    Frames per second: 0.004 (1381/377737)
    Read buffers     : 0
                     brightness (int)    : min=-127 max=127 step=1 default=0 value=0
                       contrast (int)    : min=0 max=127 step=1 default=64 value=64
                     saturation (int)    : min=0 max=255 step=1 default=64 value=64
                            hue (int)    : min=-16000 max=16000 step=1 default=0 value=0
                          gamma (int)    : min=16 max=500 step=1 default=100 value=100
           power_line_frequency (menu)   : min=0 max=2 default=1 value=1
                      sharpness (int)    : min=1 max=29 step=1 default=9 value=9
         backlight_compensation (int)    : min=0 max=1 step=1 default=0 value=0

Please help me how to solve this problem ..