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

Error when instantiating a FrameRecorder in OSGI module #194

Closed
phelgren opened this issue Jul 17, 2017 · 8 comments
Closed

Error when instantiating a FrameRecorder in OSGI module #194

phelgren opened this issue Jul 17, 2017 · 8 comments
Labels

Comments

@phelgren
Copy link

I have had a version of javacpp working for quite some time. I use it to transcode audio and video files to mp3/mp4 and it has worked quite well. I am in the process of moving that code from one version of a framework (Liferay 6.0.6) to another (Liferay 7) and although the most of the code has stayed roughly the same, the environment is different. The old code that was working was in a Java Servlet running under Glassfish 3.0 (Java 6) in Windows 7. Now I am working in Windows 10, with OSGI modules deployed to Tomcat 8 (Java 8). The error I see is this:

Exception in thread "Thread-48" 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:726)
at org.bytedeco.javacpp.Loader.load(Loader.java:671)
at org.bytedeco.javacpp.avcodec$AVPacket.(avcodec.java:1694)
at org.bytedeco.javacv.FFmpegFrameRecorder.(FFmpegFrameRecorder.java:152)
at org.bytedeco.javacv.FFmpegFrameRecorder.(FFmpegFrameRecorder.java:123)
at org.bsfinternational.media.process.MergeUsingFFMPEG.run(MergeUsingFFMPEG.java:226)
at java.lang.Thread.run(Thread.java:748)

I saw a few posts about this same error so it seems like it is an environment issue but I am not sure. The biggest challenge for me in the OSGI world is reconciling dependencies and javacpp has a LOT of them. So I probably missed something. The code where it fails is on the first open of a FFMPEGFrameRecorder:

int audioChannels = 1;
FrameRecorder recorder = null;
recorder = new FFmpegFrameRecorder(outputfile,audioChannels); <---- Fails with above error.

I double checked and the path to the file IS correct (outputfile)

In my "old" code I wasn't using Maven or any build tool...just the "traditional" way of adding jars to the /WEB-INF/lib folder for compiles and in the Glassfish domains/domain/lib folder for runtime. The jars I was using were:

10/01/14 04:41 PM 12,917,703 ffmpeg-windows-x86.jar
10/01/14 04:41 PM 13,883,346 ffmpeg-windows-x86_64.jar
10/02/14 09:22 AM 221,925 ffmpeg.jar
10/02/14 09:22 AM 188,272 javacpp.jar
10/02/14 09:22 AM 328,859 javacv.jar
10/02/14 09:23 AM 29,930 libdc1394.jar
10/01/14 04:41 PM 12,366,209 opencv-windows-x86.jar
10/01/14 04:41 PM 13,879,965 opencv-windows-x86_64.jar
10/02/14 09:23 AM 801,246 opencv.jar
10/01/14 04:41 PM 36,137 videoinput-windows-x86.jar
10/02/14 09:21 AM 15,057 videoinput.jar

In the new OSGI based framework (Liferay 7) Maven is a factor because Gradle is used as a build tool (called BLADE). My build.gradle has these entries:

compileInclude group: 'org.bytedeco', name: 'javacpp', version: '1.3.2'	
compileInclude group: 'org.bytedeco', name: 'javacv', version: '1.3.2'
compileInclude group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3'
compileInclude group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3'

Not sure of I need any other entries.

The OSGI module seems to have all the correctly packaged dependencies but obviously something is wrong. Any ideas that could point me in the correct direction would be appreciated.

@saudet
Copy link
Member

saudet commented Jul 17, 2017

Could you try to use "javacv-platform" as dependency instead of "javacv"?

@phelgren
Copy link
Author

The change created a bigger module jar so I was hopeful it picked up something that was missing but I get the same error. I can drill down to all the needed artifacts in the module. The dll's are there along with all the other classes. Not sure where the class definition error is coming from...I'll keep digging and testing

@saudet
Copy link
Member

saudet commented Jul 18, 2017

We can add the platform specific dependencies manually sure:
https://github.com/bytedeco/javacv/wiki/Configuring-Proguard-for-JavaCV#gradle-settings

@phelgren
Copy link
Author

I added the classifiers for windows-x86_64 and windows-x86. There is a DIFFERENT error now but it is similar to the first error:

Exception in thread "Thread-60" java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avcodec$AVPacket
at org.bytedeco.javacv.FFmpegFrameRecorder.(FFmpegFrameRecorder.java:152)
at org.bytedeco.javacv.FFmpegFrameRecorder.(FFmpegFrameRecorder.java:123)
at org.bsfinternational.media.process.MergeUsingFFMPEG.run(MergeUsingFFMPEG.java:226)
at java.lang.Thread.run(Thread.java:748)

@saudet
Copy link
Member

saudet commented Jul 18, 2017

That just means you're including in your dependencies artifacts for the same module with different versions. Just use "javacv-platform", that's what it's for, even if it uses a bit more disk space.

@phelgren
Copy link
Author

Hmmm. Not sure what you mean by that. This is a brand new Windows 10 install. New workspace for Ecllipse. New OSGI project. My only dependencies are defined in the build.gradle file which I would have thought were pulled in through maven (I haven't manually added any jars). So are you saying there is some jar in the classpath somewhere that is a different version?

My build.gradle has this:
compileInclude group: 'org.bytedeco', name: 'javacpp', version: '1.3.2'
compileInclude group: 'org.bytedeco', name: 'javacv-platform', version: '1.3.2'
compileInclude group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'windows-x86_64'
compileInclude group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'windows-x86'
compileInclude group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'windows-x86_64'
compileInclude group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'windows-x86'

As you directed. So when you say "Just use 'javac-platform' " (size here isn't an issue) are there changes to the dependencies above that you recommend? Or does the "different versions" you refer to come from somewhere else?

@phelgren
Copy link
Author

I went back and cleared all the maven cache entries rebuilt the module. I had to sort out some cruft from copying the code from the old framework to new but this seems to be working! Thanks for the pointers! Might be worth it to have some code that specifically draws attention to the "different versions" issue. Not sure how to detect it but might be worth it to deliver a more helpful message....thanks!

@saudet
Copy link
Member

saudet commented Jul 18, 2017

Looks alright, but the command in Gradle for that is gradle dependencies:
https://docs.gradle.org/3.3/userguide/tutorial_gradle_command_line.html#sec:obtaining_information_about_your_build
We can easily notice mismatches that way.

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

No branches or pull requests

2 participants