keke77 / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Could not detect end of the video file #277

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the following code:

import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.opencv_core.IplImage;

public class TestClass {

    public static void main(String[] args) {
        IplImage img;
        OpenCVFrameGrabber capture = new OpenCVFrameGrabber("/home/user/a.avi");
        try {
            capture.start();
            while (true) {
                img = capture.grab();
                if (img == null) {
                    break;
                }
                //do something!
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

2. Wait till the Exception are thrown.

What is the expected output? What do you see instead?
I would expect the 'image' variable to be null at the end of video file. 
However, I can't detect it. That way, always the Exception are detected ("could 
not grab frame")...

What version of the product are you using? On what operating system?
JavaCV 0.3 + OpenCV 2.3.2 + Linux Mint

Please provide any additional information below.
I want to decode each frame and then append to a Vector. When I try to do that, 
a NullPointerException are thrown right away. When displaying the frames with 
the CanvasFrame, the video are shown correctly, but the Exception still remains.

Original issue reported on code.google.com by Troi...@gmail.com on 10 Feb 2013 at 3:05

GoogleCodeExporter commented 9 years ago
Could you try again with FFmpegFrameGrabber? You're probably going to have 
better luck with that...

Original comment by samuel.a...@gmail.com on 10 Feb 2013 at 2:23

GoogleCodeExporter commented 9 years ago
Tried that already, the error present was...

Exception in thread "main" java.lang.UnsatisfiedLinkError: 
/tmp/libjniavutil2559064691063702339.so: libavutil.so.50: cannot open shared 
object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1935)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1860)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
    at java.lang.Runtime.load0(Runtime.java:792)
    at java.lang.System.load(System.java:1059)
    at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:403)
    at com.googlecode.javacpp.Loader.load(Loader.java:342)
    at com.googlecode.javacpp.Loader.load(Loader.java:316)
    at com.googlecode.javacv.cpp.avutil.<clinit>(avutil.java:75)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.googlecode.javacpp.Loader.load(Loader.java:335)
    at com.googlecode.javacv.cpp.avcodec.<clinit>(avcodec.java:85)
    at com.googlecode.javacv.FFmpegFrameGrabber.<init>(FFmpegFrameGrabber.java:95)
    at segmentador_thread.Segmentador_Thread.main(TestClass.java:17)
Java Result: 1

I also tried to find the "libavutil.so" with "locate libavutil.so" and the 
results:

/usr/lib/i386-linux-gnu/libavutil.so
/usr/lib/i386-linux-gnu/libavutil.so.51
/usr/lib/i386-linux-gnu/libavutil.so.51.22.1
/usr/lib/i386-linux-gnu/i686/cmov/libavutil.so
/usr/lib/i386-linux-gnu/i686/cmov/libavutil.so.51
/usr/lib/i386-linux-gnu/i686/cmov/libavutil.so.51.22.1

Then I added the /usr/lib/i386-linux-gnu to the PATH, exported it, closed all 
things (Netbans and Terminal), launched the netbeans again and... exception...

Original comment by Troi...@gmail.com on 10 Feb 2013 at 5:51

GoogleCodeExporter commented 9 years ago
This means you're not using JavaCV 0.3. Try again with JavaCV 0.3, which 
supports FFmpeg 1.0

Original comment by samuel.a...@gmail.com on 11 Feb 2013 at 2:01

GoogleCodeExporter commented 9 years ago
First off, thanks for the time and patience despending in this problem!!!

I was using FFMpeg version 0.11.2.

Now I am using the FFMpeg v1.0.4, configured with these:

"./configure --enable-gpl --enable-libfaac --enable-libmp3lame 
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora 
--enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree 
--enable-postproc --enable-version3 --enable-x11grab"

Re-downloaded JavaCV 0.3, put the files "javacpp.jar", "javacv.jar" and 
"java-linux-x86.jar" in the libraries section of the netbeans project.

Calculated the md5sum of these files to comprove the version:
5c71422ae9ca9305bb8b315fa4903d55  javacpp.jar
417cc824ea07ca62cc114333ff6de994  javacv.jar
a804a94f9868980434110ca8008cc39f  javacv-linux-x86.jar

Now my "locate libavutil.so" returns:
/usr/lib/i386-linux-gnu/libavutil.so.51
/usr/lib/i386-linux-gnu/libavutil.so.51.22.1
/usr/lib/i386-linux-gnu/i686/cmov/libavutil.so.51
/usr/lib/i386-linux-gnu/i686/cmov/libavutil.so.51.22.1

My PATH environment it's:
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/loc
al/games:/usr/lib/i386-linux-gnu/:/usr/local/lib

And, finally, the error returned:
Exception in thread "main" java.lang.UnsatisfiedLinkError: 
/tmp/javacpp10411296668401/libjniavcodec.so: libavcodec.so.54: cannot open 
shared object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1935)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1860)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
    at java.lang.Runtime.load0(Runtime.java:792)
    at java.lang.System.load(System.java:1059)
    at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:422)
    at com.googlecode.javacpp.Loader.load(Loader.java:372)
    at com.googlecode.javacpp.Loader.load(Loader.java:319)
    at com.googlecode.javacv.cpp.avcodec.<clinit>(avcodec.java:86)
    at com.googlecode.javacv.FFmpegFrameGrabber.<init>(FFmpegFrameGrabber.java:104)
    at segmentador_thread.Segmentador_Thread.main(TestClass.java:17)

Looks like the needed version now is the libavcodec.so.54... 

Just to be sure tried again with OpenCVFrameGrabber, but the original problem 
(could not grab frame) remains...

Original comment by Troi...@gmail.com on 11 Feb 2013 at 5:13

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Yes, libavcodec.so.54 also comes with FFmpeg 1.0...

Original comment by samuel.a...@gmail.com on 11 Feb 2013 at 5:16

GoogleCodeExporter commented 9 years ago
But what can I been doing wrong? 

Just compiled the FFmpeg version 1.0.4 with the flags above and that file 
simply does not shows itself...

This way I am going to try instaling using "apt-get install" or even renaming 
the file I have to the file I need. This is grotesque!

Original comment by Troi...@gmail.com on 11 Feb 2013 at 5:29

GoogleCodeExporter commented 9 years ago
Looks like you missed the --enable-shared option...

Original comment by samuel.a...@gmail.com on 11 Feb 2013 at 5:31

GoogleCodeExporter commented 9 years ago
Yes, that did the trick!

Thanks for your assistance and patience!

Original comment by Troi...@gmail.com on 11 Feb 2013 at 5:44

GoogleCodeExporter commented 9 years ago
Great! So, does FFmpeg have any problem detecting the end of video files?

Original comment by samuel.a...@gmail.com on 17 Feb 2013 at 12:52

GoogleCodeExporter commented 9 years ago
It works, but I noticed some frames of the end of the input video are not 
recognized/decoded. When I  use the FFMPEG directly under terminal the decoded 
video has more frames than when using the FFMpegFrameGrabber. Really strange...

Original comment by Troi...@gmail.com on 17 Feb 2013 at 6:30

GoogleCodeExporter commented 9 years ago
Ok... let me know if you figure out why it's doing that, thanks!

Original comment by samuel.a...@gmail.com on 24 Feb 2013 at 7:04

GoogleCodeExporter commented 9 years ago
Good news! I figured out why the last few frames of video didn't get decoded 
thanks to the reported issue #315. The fix is available here:
http://code.google.com/p/javacv/source/detail?r=345a0baa8ca1e8bf44bd4d7273635728
6acab82d
Let me know if that doesn't work for you for some reason though, thanks!

Original comment by samuel.a...@gmail.com on 11 May 2013 at 6:20