Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 ..

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.code:


// Include standard OpenCV headers

include <iostream>

include <opencv cv.h="">

include <opencv highgui.h="">

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

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

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 The information about camera is as follows.


$ v4l2-ctl --all

--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


value=0

Please help me how to solve this problem ..