Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I am working on the same project: So, here is my working code.

    public class VideoCap {
    public static void main (String args[]){
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    VideoCapture cap =new VideoCapture();
    cap.set(Videoio.CV_CAP_PROP_FRAME_HEIGHT,768 );
    cap.set(Videoio.CV_CAP_PROP_FRAME_WIDTH,1024);
     cap.open("C:\\Users\\Admin\\Downloads\\Video\\Pakistananthem.mp4");
    //cap.open(0);
    Mat pic = new Mat();
    if (cap.isOpened())
    {
        System.out.println("Video is opened");
        //If you want to get the total number of frames in a video just uncomment this
        //int length = (int) cap.get(Videoio.CAP_PROP_FRAME_COUNT);
        //System.out.println(length);
        cap.read(pic);
        Imgcodecs.imwrite("C:\\Users\\Admin\\Desktop\\pics\\pics.png", pic);
        cap.release();
    }

    else
    {
        System.out.println("Fail");
    }

     }    
    }

I am working on the same project: So, here is my working code. Set the environmental variable first.

    public class VideoCap {
    public static void main (String args[]){
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    VideoCapture cap =new VideoCapture();
    cap.set(Videoio.CV_CAP_PROP_FRAME_HEIGHT,768 );
    cap.set(Videoio.CV_CAP_PROP_FRAME_WIDTH,1024);
     cap.open("C:\\Users\\Admin\\Downloads\\Video\\Pakistananthem.mp4");
    //cap.open(0);
    Mat pic = new Mat();
    if (cap.isOpened())
    {
        System.out.println("Video is opened");
        //If you want to get the total number of frames in a video just uncomment this
        //int length = (int) cap.get(Videoio.CAP_PROP_FRAME_COUNT);
        //System.out.println(length);
        cap.read(pic);
        Imgcodecs.imwrite("C:\\Users\\Admin\\Desktop\\pics\\pics.png", pic);
        cap.release();
    }

    else
    {
        System.out.println("Fail");
    }

     }    
    }