Ask Your Question

Revision history [back]

VideoWriter problem - video not playable (java)

Hi experts,

i am new here and don't find something simular. I have a Webcam (later 2) and want to get the stream saved as a video an my disk. I thought it would be very simple, but i have the problem, that the VideoWriter saves a video but it has no size and i can't play it.... Here is my source code

import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;

import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.videoio.VideoCapture;
import org.opencv.videoio.VideoWriter;
import org.opencv.videoio.Videoio;

public class main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.load(new File("lib/opencv_java341.dll").getAbsolutePath());
        System.load(new File("lib/opencv_ffmpeg341_64.dll").getAbsolutePath());
        System.load(new File("lib/opencv_world341.dll").getAbsolutePath());

        Mat mat = new Mat();

        VideoCapture videoCapture = new VideoCapture("http://192.168.0.90/mjpg/video.mjpg");
        Size frameSize = new Size((int) videoCapture.get(Videoio.CAP_PROP_FRAME_WIDTH), (int)   videoCapture.get(Videoio.CAP_PROP_FRAME_HEIGHT));
        VideoWriter videoWriter = new VideoWriter("test.avi", VideoWriter.fourcc('x', '2','6','4'),
                        videoCapture.get(Videoio.CAP_PROP_FPS), frameSize, true);
        while (videoCapture.read(mat)) {
                    videoWriter.write(mat);         
                }
                videoCapture.release();
                videoWriter.release();
        }   
}

do i have to make a cut and let it work on the release or is it enough to press the stop button? Later i want to start it by pressing a key and stop it with an other key... But as long as it don't produce a playable video it makes no sense.

Do you have an idea?

Thank you ;)

rom