3
Hello,
I need to save pictures/frames from a video. The idea is to create a preview of the film before it starts.
The problem is I’m not being able to implement the examples I found.
First example take a screenshot of the component with Javafx, it works but the video has to 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 Librarias seems to be possible but neither with one nor with the other.
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: https://stackoverflow.com/a/22107132/3792998
I’m not wearing Maven:
Libraries added to the project:
javacpp
javacv
issues:
- Does anyone know which libraries are needed to put the it works the javaCV?
- It is necessary to have already installed on Opencv PC or has nothing to do?
- Some more practical code for what I intend to do?
By mistake
java.lang.NoClassDefFoundError: com/googlecode/javacpp/Pointer
is missing a class/package, compiled via command line? If yes try to use sojava -cp nome-do-pacote.jar
– Guilherme Nascimento
If not using Maven which one are you using? Gradle, Sbt or command line?
– Guilherme Nascimento
no, I haven’t compiled via cmd yet... I’m using Netbeans and entering the libraries directly. But in this case I’m not getting it.
– jsantos1991
But does the project in Netbeans use Maven or Gradle? Why are these libs usually added to the project, or did you not even add?
– Guilherme Nascimento
I directly added the libs to the project (without using Maven or Gradle). https://github.com/bytedeco/javacv#manual-installation - I’ve added the ones that say here
– jsantos1991
Check there if added all jars, in case it is the
javacpp.jar
. Another thing, by the comments of the post you linked, the way to get theBufferedImage
is different in more recent versions. Also see if when running the same jars are in classpath.– Dudaskank
@Dudaskank yes I have the lib
javacpp.jar
inserted, already updated it by another but the problem continues, the error results when I try to create theFFmpegFrameGrabber
– jsantos1991