Recherche…


Introduction

Chaque fois que vous travaillez avec des flux vidéo, vous pouvez éventuellement enregistrer votre résultat de traitement d'image sous la forme d'un nouveau fichier vidéo. Pour des sorties vidéo simples, vous pouvez utiliser la classe VideoWriter intégrée à OpenCV, conçue pour cela. Il est utile d’examiner certains concepts avant de les utiliser. Ces concepts sont codec, c'est-à-dire décodeur et FourCC (code à quatre caractères).

Créer une vidéo avec OpenCV (Java)

VideoWriter videoWriter;
videoWriter = new VideoWriter(outputFile, VideoWriter.fourcc('x', '2','6','4'),
                fps, frameSize, isRGB);
//We have stated that we will use x264 as codec with FourCC
//For writing, we add the following method and it will write the image we give as parameter in this call.
 public void Write(Mat frame) {
        if(videoWriter.isOpened()==false){
            videoWriter.release();
            throw new IllegalArgumentException("Video Writer Exception: VideoWriter not opened,"
                    + "check parameters.");        
        }
        //Write video
        videoWriter.write(frame);
    }

//With Video Capture for example, we can read images from the camera and write the same video

VideoCapture videoCapture = new VideoCapture(0);
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();


Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow