Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaCV capture a frame using FFmpeg

Tags:

ffmpeg

javacv

I create a class that capture frame from a video. When it capture a frame, it's saved as a picture. When the video is .avi, application works ok. When format is .avi.

public static void main(String[] args) {

     FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("C:/Users/Ioanna/Desktop/video1.avi");

     try {
         IplImage img; 

         //Start grabber to capture video
         grabber.start(); 

         //grab video frame to IplImage
         img = grabber.grab();

         if (img != null) {         
             //save video frame as a picture
             cvSaveImage("capture.jpg", img);
         }

     }catch (Exception e) {      
     }
}

The error is

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.googlecode.javacv.FFmpegFrameGrabber.<init>(FFmpegFrameGrabber.java:106)
    at Video.main(Video.java:75)
Caused by: java.lang.IllegalStateException: Can't overwrite cause with java.lang.UnsatisfiedLinkError: no avcodec in java.library.path
    at java.lang.Throwable.initCause(Throwable.java:457)
    at com.googlecode.javacpp.Loader.load(Loader.java:581)
    at com.googlecode.javacpp.Loader.load(Loader.java:532)
    at com.googlecode.javacv.cpp.avcodec.<clinit>(avcodec.java:39)
    ... 2 more
Caused by: java.lang.UnsatisfiedLinkError: no jniavcodec in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1837)

Do anyone know what is the problem?

Thanks in advance

like image 244
Ioanna Avatar asked Oct 21 '22 23:10

Ioanna


1 Answers

After searching the web for quite some time, I came to the following solution:

Step 1: Download the .zip file "javacv-0.6-cppjars.zip" from
https://code.google.com/p/javacv/downloads/list and unzip it.

Step 2: Add "ffmpeg-20130915-git-7ac6c63-windows-x86_64.jar" file to your Java project!

like image 66
benny.la Avatar answered Oct 24 '22 02:10

benny.la