2

Main Goal:

My main goal was to get the duration of all .mp4 files from a directory. So, I have googled it and found this qeustion where one answer referred this for full code.

Error in import:

When I took the necessary portion in my code, it was showing error in the following line:

import com.xuggle.xuggler.IContainer;

After that, I downloaded Xuggler from here which I got from here. Then I got the following Error:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.xuggle.ferry.JNILibrary.<clinit>(JNILibrary.java:42)
    at com.xuggle.ferry.FerryJNI.<clinit>(FerryJNI.java:14)
    at com.xuggle.ferry.Ferry.<clinit>(Ferry.java:25)
    at com.xuggle.xuggler.XugglerJNI.<clinit>(XugglerJNI.java:19)
    at com.xuggle.xuggler.IContainer.<clinit>(IContainer.java:1622)
    at videotimecalcualtioncoursera.MainFrame.calculateTime(MainFrame.java:116)
    at videotimecalcualtioncoursera.MainFrame.jButtonCalculateActionPerformed(MainFrame.java:284)
    at videotimecalcualtioncoursera.MainFrame.access$000(MainFrame.java:33)
    at videotimecalcualtioncoursera.MainFrame$4.actionPerformed(MainFrame.java:204)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6525)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6290)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2739)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
    at java.awt.EventQueue.access$400(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:697)
    at java.awt.EventQueue$3.run(EventQueue.java:691)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:719)
    at java.awt.EventQueue$4.run(EventQueue.java:717)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 45 more

Solving the Exception "java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory":

To seek the solution of the above exception, I found this question and tried all its three solution with no luck. Got the following exception:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006ee76520, pid=10112, tid=3292
#
# JRE version: Java(TM) SE Runtime Environment (8.0_25-b18) (build 1.8.0_25-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [xuggle6026878147022032067.dll+0x736520]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# H:\Dropbox\JavaProjects\VideoTimeCalcualtionCoursera\hs_err_pid10112.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Java Result: 1

Solving the Exception "SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder":

Seeking the solution of it, I got this question and the accepted answer could do nothing except removing the first three lines in error stream.

What I have tried then:

I have tried adding the following .jar files in my project:

  1. xuggle-xuggler-5.4.jar
  2. slf4j-api-1.6.4.jar / slf4j-api-1.7.12.jar
  3. slf4j-simple-1.7.6.jar / slf4j-simple-1.7.12.jar
  4. log4j-1.2.16.jar
  5. logback-classic-1.0.0.jar
  6. logback-core-1.0.6.jar
  7. slf4j-jdk14-1.7.12.jar
  8. slf4j-log4j12-1.7.12.jar

File - hs_err_pid10112.log:

You can see the error file here, I could not added it as adding it would cross the character limit.

How to resolve this problem?

Note:

I have traversed along the following questions:

  1. using Logback with slf4j [on hold]
  2. Error with Slf4j and classpath
  3. Given I'm stuck with SLF4J and java.util.Logging, what is optimal solution?
  4. How do I get a list of configured loggers using Jboss LogManager with SLF4J?
  5. How to write event logs into xml files with SLF4J or Logback?
  6. OpenJPA logging with slf4j on WebSphere
  7. Tomcat Logging With Slf4j and Log4j
Community
  • 1
  • 1
Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56

3 Answers3

1

You will usually need three functional parts:

  1. the API used by the program (slf4j-api)
  2. bridging code to adapt the logger implementation to the SLF4J API (e.g. slf4j-log4j12) this one must match the logger you use.
  3. the logger implementation (e.g. log4j)

Some jars cover more than one part, e.g. logback covers 2 and 3 because it implements slf4j natively or if you use java util logging you don't need to explicitly add part 3 (it is in the Java runtime)

You must also use matching versions of the slf4j components, for example don't mix slf4j-api-1.6.4.jar with slf4j-log4j12-1.7.12.jar.

Have a look at the slf4j documentation for the details.

Henry
  • 42,982
  • 7
  • 68
  • 84
0

I would try adding your dependencies one by one (while commenting out dependent code). My first impression is that one of these libraries features incompatible versions/backends for slf4j on their classpaths. it's impossible to know which one until you discover this. Once you do that, you can get gradle/maven to exclude one of the conflicting things from your classpath.

0

I could not solve the issue, but I could achieve my goal in other way.

I have used IBM's tool kit for it.

  1. Downloaded IBM's API from here.
  2. Added the following code snippet in my code:

    public long getDuration(File file) throws IOException {
        PlayerControl playerControl = PlayerFactory.createLightweightMPEG4Player();
        playerControl.open(file.getAbsolutePath());
        return playerControl.getDuration();
    }
    

As my goal was only getting the duration, this is not the efficient way.

In my PC (core-i5, 2.5GHz, 6GB RAM, Win10), It took 42657ms to process 60 .mp4 files which outputted Around 6 Hours 41 Minutes of Duration.

If you want, you can check it in my repository.

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56