# Revision history [back]

### how to display the grabbed video frame inside JFrame

I have posted a question in SO website and it is [here].

what i want to do is, to open a video of .avi extension, and in a while-loop i am reading the video fram by frame using the methods grab() and retrieve() as shown below in the code, and for each grabbed frame i am converting it to an image and display that image inside a JFrame.

given the code below, each grabbed frame is converted into an image correctly, i knew that it is converted into an imagr correctly because after the program finish execution i checked where the converted fram into image is located and it contains the last frame in the video. the problem is, the displayed image on the JFrame is not changing, despite the video contains many frames only the first frame is shown inside EVERY created JFrame, and what i want to do is, for every grabbed frame it should be displayed inside a new JFrame.

please have alook at the code posted below, and let me know why despite every grabbed frame is converted into image and saved to a specific path, when i display the saved image inside JFrame, only the first grabbed image is displayed inside the JFrame.

code:

public class PlayVideo {
static VideoCapture vCapture;
static Mat mat;

public static void main(String[] args) {

vCapture = new VideoCapture("C:/private/..../AVIs/ChuteLibre.avi");
vCapture.open("C:/private/..../AVIs/ChuteLibre.avi");
mat = new Mat();

if (!vCapture.isOpened()) {
System.out.println("media failed to open");
} else {
while (vCapture.grab()) {
vCapture.retrieve(mat);
showInFrame(mat);
}
vCapture.release();
}


}

 private static void showInFrame(Mat mat) {
// TODO Auto-generated method stub
JFrame mediaFrame = new JFrame("Media");
mediaFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mediaFrame.setVisible(true);
mediaFrame.setSize(300,300);

Highgui.imwrite("c:/private/img.jpg", mat);
ImageIcon image = new ImageIcon("c:/private/img.jpg");
JLabel label = new JLabel("", image, JLabel.CENTER);

mediaFrame.repaint();
mediaFrame.validate();
mediaFrame.setVisible(true);


} }

(http://stackoverflow.com/questions/29237543/how-to-capture-avi-file-frame-by-frame-and-display-it-in-jframe)

 2 No.2 Revision thdrksdfthmn 2170 ●5 ●18 ●46

### how to display the grabbed video frame inside JFrame

I have posted a question in SO website and it is [here].

what i want to do is, to open a video of .avi extension, and in a while-loop i am reading the video fram by frame using the methods grab() and retrieve() as shown below in the code, and for each grabbed frame i am converting it to an image and display that image inside a JFrame.

given the code below, each grabbed frame is converted into an image correctly, i knew that it is converted into an imagr correctly because after the program finish execution i checked where the converted fram into image is located and it contains the last frame in the video. the problem is, the displayed image on the JFrame is not changing, despite the video contains many frames only the first frame is shown inside EVERY created JFrame, and what i want to do is, for every grabbed frame it should be displayed inside a new JFrame.

please have alook at the code posted below, and let me know why despite every grabbed frame is converted into image and saved to a specific path, when i display the saved image inside JFrame, only the first grabbed image is displayed inside the JFrame.

code:

public class PlayVideo {
static VideoCapture vCapture;
static Mat mat;

public static void main(String[] args) {

vCapture = new VideoCapture("C:/private/..../AVIs/ChuteLibre.avi");
vCapture.open("C:/private/..../AVIs/ChuteLibre.avi");
mat = new Mat();

if (!vCapture.isOpened()) {
System.out.println("media failed to open");
} else {
while (vCapture.grab()) {
vCapture.retrieve(mat);
showInFrame(mat);
}
vCapture.release();
}


}

   }

private static void showInFrame(Mat mat) {
// TODO Auto-generated method stub
JFrame mediaFrame = new JFrame("Media");
mediaFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mediaFrame.setVisible(true);
mediaFrame.setSize(300,300);

Highgui.imwrite("c:/private/img.jpg", mat);
ImageIcon image = new ImageIcon("c:/private/img.jpg");
JLabel label = new JLabel("", image, JLabel.CENTER);