record and save video stream use opencv in java

狂风中的少年 提交于 2021-01-28 18:26:36

问题


my question is about : how to record and save with the time specified like after two hours this app must done record and save in one folder.

public class per1 {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Scanner scan = new Scanner(System.in);
        VideoCapture camera = new VideoCapture(0);

        String cc = String.valueOf(camera.get(Videoio.CAP_PROP_FOURCC));
        int fps = (int) camera.get(Videoio.CAP_PROP_FPS);
        int width = (int) camera.get(Videoio.CAP_PROP_FRAME_WIDTH);
        int height = (int) camera.get(Videoio.CAP_PROP_FRAME_HEIGHT);
        final Size frameSize = new Size((int) camera.get(Videoio.CAP_PROP_FRAME_WIDTH), (int) camera.get(Videoio.CAP_PROP_FRAME_HEIGHT));

        VideoWriter save = new VideoWriter("D:/video.mpg", Videoio.CAP_PROP_FOURCC, fps, frameSize, true);

        if (camera.isOpened()) {
            System.out.println("ON");
            Mat framecam = new Mat();
            boolean cekframe = camera.read(framecam);
            System.out.println("cekframe " + cekframe);
            try {
                while (cekframe) {
                    camera.read(framecam);
                    save.write(framecam);
                }
                Thread.sleep(4000);
            } catch (Exception e) {
                System.out.println("OFF \n" + e);
            }
            camera.release();
            save.release();
            System.exit(1);
            System.out.println("DOne");
        }
    } 

来源:https://stackoverflow.com/questions/53158765/record-and-save-video-stream-use-opencv-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!