Ask Your Question

Borny's profile - activity

2020-06-26 19:06:48 -0600 received badge  Notable Question (source)
2020-01-28 13:41:01 -0600 received badge  Popular Question (source)
2018-06-05 01:39:26 -0600 received badge  Supporter (source)
2018-06-04 05:06:48 -0600 marked best answer Extracting Frames Opencv Java

Hello,

i am trying to extract all frames out of a video with opencv java.

The code seems to work so far in giving me the correct number of all frames and the fps, but i just get the same first frame 4000 times.

public class VideoCap {
public static void main (String args[]){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

VideoCapture cap = new VideoCapture();

    String input = "/Users/Jan/Desktop/Video/Java.mp4";
    String output = "/Users/Jan/Desktop/Video/Output";

cap.open(input);

    int video_length = (int) cap.get(Videoio.CAP_PROP_FRAME_COUNT);
    int frames_per_second = (int) cap.get(Videoio.CAP_PROP_FPS);
    int frame_number = (int) cap.get(Videoio.CAP_PROP_POS_FRAMES);

Mat frame = new Mat();

if (cap.isOpened())
{
        System.out.println("Video is opened");
        System.out.println("Number of Frames: " + video_length);
        System.out.println(frames_per_second + " Frames per Second");
        System.out.println("Converting Video...");

    cap.read(frame);

    while(frame_number <= video_length)
    {
        Imgcodecs.imwrite(output + "/" + frame_number +".jpg", frame);
        frame_number++;
    }
    cap.release();

        System.out.println(video_length + " Frames extracted");

}

    else
    {
        System.out.println("Fail");
    }
} }
2018-06-04 05:06:48 -0600 received badge  Scholar (source)
2018-06-04 04:15:05 -0600 commented question Extracting Frames Opencv Java

Could you elaborate on how to get the other frames? As far as i understood it, cap.read(frame) would iterate over the fr

2018-06-04 03:49:25 -0600 asked a question Extracting Frames Opencv Java

Extracting Frames Opencv Java Hello, i am trying to extract all frames out of a video with opencv java. The code seem