Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

i can't try (no java here), but i guess, you wanted something like this:

VideoCapture camera = new VideoCapture(filePath);
if (!camera.isOpened()) {
    System.out.println("Error! Camera can't be opened!");
    return;
}
int w=camera.get(CAP_PROP_FRAME_WIDTH);
int h=camera.get(CAP_PROP_FRAME_HEIGHT);
VideoWriter writer = new VideoWriter("my.avi",
                                     VideoWriter.fourcc('M','J','P','G'), 25, new Size(w,h));

Mat frame = new Mat();
while (true) {
    if (camera.read(frame)) {
    writer.write(frame);
    ...
    }
}
writer.release();

please also see docs

i can't try (no java here), but i guess, you wanted something like this:

VideoCapture camera = new VideoCapture(filePath);
if (!camera.isOpened()) {
    System.out.println("Error! Camera can't be opened!");
    return;
}
int w=camera.get(CAP_PROP_FRAME_WIDTH);
int h=camera.get(CAP_PROP_FRAME_HEIGHT);
VideoWriter writer = new VideoWriter("my.avi",
                              VideoWriter.fourcc('M','J','P','G'), 25, new Size(w,h));

Mat frame = new Mat();
while (true) {
    if (camera.read(frame)) {
    writer.write(frame);
    ...
    }
}
writer.release();

please also see docs

i can't try (no java here), but i guess, you wanted something like this:

VideoCapture camera = new VideoCapture(filePath);
if (!camera.isOpened()) {
    System.out.println("Error! Camera can't be opened!");
    return;
}
int w=camera.get(CAP_PROP_FRAME_WIDTH);
int h=camera.get(CAP_PROP_FRAME_HEIGHT);
int fourcc = VideoWriter.fourcc('M','J','P','G');
VideoWriter writer = new VideoWriter("my.avi",
                             VideoWriter.fourcc('M','J','P','G'), fourcc, 25, new Size(w,h));
Size(w,h), false); 
// the false is for writing grayscale (1 channel) images

Mat frame = new Mat();
while (true) {
    if (camera.read(frame)) {
    writer.write(frame);
...

    writer.write(binary_img);
    ...
    }
}
writer.release();

please also see docs