Hello,
I need to save images / frames of a video. The idea is to create a movie preview before it starts.
The problem is that I'm not able to implement the examples I found.
1st Example to take a screenshot of the component with JavaFX, it works but the video must be playing.
Code:
...
//
private void saveAsPng(Node n) {
WritableImage image = n.snapshot(new SnapshotParameters(), null);
// TODO: probably use a file chooser here
File file = new File("D:\movie12.png");
try {
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
} catch (IOException e) {
System.out.println("Não foi possível capturar imagem do video");
}
}
...
2º Making use of the JavaCV or Xuggler Libraries seems to be possible, but I can not do this with either one.
JavaCV
import com.googlecode.javacv.FFmpegFrameGrabber;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ZzzzzzzSaveImgFromVideo{
public static void main(String []args) throws IOException, Exception
{
FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber("D:\Movie..................mp4");
frameGrabber.start();
IplImage i;
try {
i = frameGrabber.grab();
BufferedImage bi = i.getBufferedImage();
ImageIO.write(bi,"png", new File("D:/Img.png"));
frameGrabber.stop();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
error:
run:
Exception in thread "main" java.lang.NoClassDefFoundError: com/googlecode/javacpp/Pointer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at zzzzzzzsaveimgfromvideo.ZzzzzzzSaveImgFromVideo.main(ZzzzzzzSaveImgFromVideo.java:18)
Caused by: java.lang.ClassNotFoundException: com.googlecode.javacpp.Pointer
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
link: link
I'm not using Maven:
Bookstores added to the project:
javacpp
javacv
issues:
- Does anyone know which libraries are needed to por does javaCV work?
- Is it necessary to have already installed on the OpenCV PC or has nothing to do?
- Some more practical code for what I want to do?