Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil Windows 10 #106

Closed
vladbancila opened this issue Jun 6, 2016 · 21 comments

Comments

@vladbancila
Copy link

vladbancila commented Jun 6, 2016

This error occurs when trying to use FFmpegFrameGrabberclass , find below stack trace and pom.xml - Maven
Please help me repair this problem. The same problem appears in Linux , only operational system is Win 7 works fine. Thanks in advance !

Using this method:

public String genereazaImagine(int nrFrame) {

        String numeFisierVideo = numeFisierXml.replace(".xml", ".mp4");


        FFmpegFrameGrabber g = new FFmpegFrameGrabber(numeFisierVideo);

        try {
            g.start();

            long microsecunde = g.getLengthInTime();
            long ore = TimeUnit.MICROSECONDS.toHours(microsecunde);
            long minutes = TimeUnit.MICROSECONDS.toMinutes(microsecunde);
            long secunde = TimeUnit.MICROSECONDS.toSeconds(microsecunde);
            String rezultatCalcul = "0" + ore + ":" + minutes % 60 + ":" + secunde % 60;

            this.setDurataEmisune(rezultatCalcul);

            g.setFrameNumber(nrFrame);

            Frame frame = g.grabFrame();

            this.setCalePoza(numeFisierVideo.substring(0, numeFisierVideo.length() - 4) + ".jpg");

            ImageIO.write(new Java2DFrameConverter().convert(frame), "jpg", new File(calePoza));

            g.stop();
        } catch (Exception | IOException e) {

            e.printStackTrace();
        }
        // org.bytedeco.javacpp.avutil
        return numePoza;
    }

Error stack trace:

java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.bytedeco.javacpp.Loader.load(Loader.java:390)
    at org.bytedeco.javacpp.Loader.load(Loader.java:358)
    at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2539)
    at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:383)
    at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:377)
    at ro.radcom.catchupStandardKoolnet.business.GeneratorXmlStandard.genereazaImagine(GeneratorXmlStandard.java:566)
    at ro.radcom.catchupStandardKoolnet.controllers.HomeController.genereazaImagine(HomeController.java:135)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
@vladbancila
Copy link
Author

I attach text of pom.xml - THX
pom original.txt

@saudet
Copy link
Member

saudet commented Jun 6, 2016

Could you try again with JavaCV 1.2?

@vladbancila
Copy link
Author

Unfortunately the same thing happens with versions 1.1 and 1.2 of JavaCV and JavaCpp .Is working correctly on version 1.0 and Windows 7 . In the rest of cases is not finding at runtime the proper class.

@vladbancila
Copy link
Author

Today I tried the new version 1.2.1 on win 10 and still not working getting the same error 👍 java.lang.NoClassDefFoundError

I can replicate this problem in a smaller program and attach a runnable jar of it, or war...

@saudet
Copy link
Member

saudet commented Jun 7, 2016

On Windows, you're probably hitting issue bytedeco/javacpp-presets#225 right?

@vladbancila
Copy link
Author

Is more like this issue : bytedeco/javacv#429

@saudet
Copy link
Member

saudet commented Jun 8, 2016

Which is a duplicate of bytedeco/javacpp-presets#225

@vladbancila
Copy link
Author

ok thank you very much ! I will investigate further more .

@tingfengainiaini
Copy link

I have encoutered this. Finally, it works after when i upgrade the native lib.

@wypstone
Copy link

@tingfengainiaini
what do you mean by "upgrade the native lib". can you show out? thks a lot..
i'm in centos 7. it works fine in my win7 too

@tingfengainiaini
Copy link

@wypstone hi, download the newest javacv native library in https://github.com/bytedeco/javacv, now version is javacv-1.2-bin.zip (169 MB). Update the native dynamic librarys you need in your project.

@saudet
Copy link
Member

saudet commented Sep 21, 2016

Right, this should be fixed. Details at bytedeco/javacpp-presets#225

@saudet saudet closed this as completed Sep 21, 2016
@wypstone
Copy link

Thank you all guys. I found my centos glibc the highest 2.12, and ldd 1.2'so showing me "version `GLIBC_2.14' not found".(at least 2.14)
when i turn back to 1.1 or upgrate the os glibc, it's both work.

@yuzhougit
Copy link

@wypstone , Hi, your solution works which saves my time, thanks for your share. But how do you find the error "version `GLIBC_2.14' not found" or how do you know that at least glibc 2.14 is needed for javaCV 1.1? I am interested at it.

能分享一下是怎么发现这个问题需要升级glibc来解决的吗?

@chammond75
Copy link

chammond75 commented Nov 15, 2017

Hi all, I'm still having this problem:

java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_131]
at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_131]
at org.bytedeco.javacpp.Loader.load(Loader.java:739) ~[javacpp-1.3.3.jar:1.3.3]
at org.bytedeco.javacpp.Loader.load(Loader.java:684) ~[javacpp-1.3.3.jar:1.3.3]
at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2819) ~[ffmpeg-3.2.1-1.3.jar:1.3.3]
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:509) ~[javacv-1.3.3.jar:1.3.3]
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:503) ~[javacv-1.3.3.jar:1.3.3]

here are my gradle dependencies

compile group: 'org.bytedeco', name: 'javacv-platform', version: '1.3.3'
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv-platform', version: '3.2.0-1.3'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg-platform', version: '3.2.1-1.3'`

I'm running on Linux through a docker image. I'm not sure what the exact settings are on that image (am new to this company and am running on their infrastructure). It's critical that I get this resolved. How do I go about figuring out if there's a native library that needs updating and if so which one it is?

EDIT: Same code works just fine on Mac OS X @saudet is there additional info that I can give you that would help resolve this issue? I'm currently working on downloading the docker image to get more information. But this is basically an AWS basic Linux Docker image. So if I need to run extra commands to install ffmpeg on there or something like that please let me know.

@alyk
Copy link

alyk commented Nov 15, 2017

I've just faced the same error in my Android project.
In my case *.so files extracted from ffmpeg-android-{platform}.jar were missing in jniLibs/{platform} directory.
like here --> https://stackoverflow.com/a/37427633/2220203

@chammond75
Copy link

@saudet

I continue to run up against the following error (again for context this is running in a Docker image on AWS):

java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avcodec
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_131]
at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_131]
at org.bytedeco.javacpp.Loader.load(Loader.java:739) ~[javacpp-1.3.3.jar:1.3.3]
at org.bytedeco.javacpp.Loader.load(Loader.java:684) ~[javacpp-1.3.3.jar:1.3.3]
at org.bytedeco.javacpp.avformat$AVFormatContext.(avformat.java:2819) ~[ffmpeg-3.2.1-1.3.jar:1.3.3]
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:509) ~[javacv-1.3.3.jar:1.3.3]
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:503) ~[javacv-1.3.3.jar:1.3.3]

I notice that this is slightly different than the error that I posted earlier. In that error I could not initialize “avutil” and here it’s “avcodec” that cannot be initialized.

I am running Alpine Linux 3.6 in a docker image. During the creation of that docker image I actually compile ffmpeg 3.2.1. I didn’t know if that was necessary or not but I did it out of desperation. Here are the relevant entries from my build.gradle file:

compile group: 'org.bytedeco', name: 'javacv-platform', version: '1.3.3'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv-platform', version: '3.2.0-1.3'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier:'linux-x86_64'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg-platform', version: '3.2.1-1.3'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier:'linux-x86_64'

I admit that I’m completely new to ffmpeg and a bit of a Linux luddite. I wish I had better insight into what was happening at the native level so that I could debug this easier. Most of what I see in the forums is that people are missing the right jars that contain the necessary .so files. But that typically manifests itself as a link error if I’m not mistaken. Is it possible that I’m missing the right jars as well? Locally in my build they all look like they are there. Lastly here’s my code:

FFmpegFramGrabber grabber = new FFmpegFrameGrabber(new BufferedInputStream(url.openStream())));
grabber.start();
Frame f = null;
while ((f = grabber.grabKeyFrame()) != null) {
final BufferedImage image = converter.convert(f);
final Double timestamp = Double.valueOf(grabber.getTimestamp() / 1_000_000d);
holder.collectImage(image, timestamp);
}

And, of course, the problem happens at the invocation of the start() method.

If anyone has any solutions that would be GREATLY appreciated.

@kristof-taveirne
Copy link

Hi Chammond75,

Did you find a solution for your problem? I'm experiencing the same.
I'll keep you informed when when I do.

Kristof.

@chammond75
Copy link

In my particular case I was finally able to address my problem by increasing my max heap and max stack size in the JVM. I went to a 3Gb max heap (-Xmx) and 1m max stack (-Xss).

In addition I also unpacked the native libraries and ran ldd on them (since i’m using Linux) to make sure that all of their dependencies were properly met on the system on which I was running. I switched my base docker image to centos 7. I also made sure to update to jdk 8 update 151.

Again the trick for me ended up being the heap thing. There were some out of memory errors that were occurring but not getting logged to the console (until I ran on a local Linux VM). There’s also a snapshot version 1.3.4-SNAPSHOT that tries to address a stack overflow exception that was leading to no class def. I haven’t tried the snapshot yet.

Let me know if any of this is helpful. If not I’ll try to recollect other things I tried in the road to getting this work. Good luck.

@kristof-taveirne
Copy link

Hi Chammond,
Thank you for your reply!

I followed your advice and for me switching to Centos 7 fixed it!
Didn't need to increase the heap.

Thanks a lot!

Greetings,
Kristof.

@zhuanqizhirou
Copy link

I got the same error. The error is ,the maven dependency artifactId is javacv-platform,not javacv!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants