video recording in bbb


My aim is to record video from Axis camera using bbb. I have done video streaming in bbb and it worked well. I can watch live video on an output window. I installed opencv in bbb and programs are written in C++. Now i need to record video at 25fps and i coded as shown below.

#include “cv.h”
#include “highgui.h”

using namespace std;
int main (int argc, char *argv[])

cv::VideoCapture vcap;
cv::Mat frame;
cv::VideoWriter video;

// Open the default camera
const std::string videoStreamAddress = “http://USERNAME:PASSWORD@IP ADDRESS/mjpg/video.mjpg”;

// Check if the camera was opened

if(! {
std::cout << “Error opening video stream or file” << std::endl;
return -1;

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

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

// Create a window to show the image
cv::namedWindow (“Capture”, CV_WINDOW_AUTOSIZE);

// Create the video writer“capture.avi”,CV_FOURCC(‘M’,‘J’,‘P’,‘G’, 25, cvSize((int)width,(int)height),true );

// Check if the video was opened
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
// Get frame from capture
vcap >> frame;

// Check if the frame was retrieved
cerr << “Could not retrieve frame.”;
return -1;

// Save frame to video
video << frame;

// Show image
cv::imshow(“Capture”, frame);

// Exit with escape key
if(cv::waitKey(1) == 27)

// Exit
return 0;

This code is working in Eclipse IDE installed in Ubuntu host machine and i got recorded video in the workspace of Eclipse. When i copied this program to bbb, it is not working. It can stream the video and sent the frame properties and the output is “Could not create video.”. What is the problem in this code? Can anyone help me?

Also i want to store this video to the sd card which act as the extra storage in bbb. how i can do it? Please help me.

Thanks in advance.

May be a problem with privileges so that you can’t write the video-file? If not I’d recommend to ask this question on since this seems to be more an OpenCV problem.