2013-08-06 34 views
4

我最近下載了,Xuggler教程代碼:幀捕捉和視頻製作this link,我添加了所有我的項目中的.jar文件這是需要運行該代碼,但是,當我運行這個代碼然後我得到錯誤:錯誤com.xuggle.ferry.JNILibraryLoader - 無法加載庫:xuggle-xuggler;版本:3;

這裏是我的代碼:

package xug; 

import java.awt.image.BufferedImage; 
import java.io.File; 
import java.io.IOException; 

import javax.imageio.ImageIO; 

import com.xuggle.mediatool.IMediaReader; 
import com.xuggle.mediatool.MediaListenerAdapter; 
import com.xuggle.mediatool.ToolFactory; 
import com.xuggle.mediatool.event.IVideoPictureEvent; 
import com.xuggle.xuggler.Global; 

public class VideoThumbnailsExample { 

    public static final double SECONDS_BETWEEN_FRAMES = 10; 
    private static final String inputFilename = "e:/low_light.mp4"; 
    private static final String outputFilePrefix = "e:/Frames/processedImages"; 
    // The video stream index, used to ensure we display frames from one and 
    // only one video stream from the media container. 
    private static int mVideoStreamIndex = -1; 
    // Time of last frame write 
    private static long mLastPtsWrite = Global.NO_PTS; 
    public static final long MICRO_SECONDS_BETWEEN_FRAMES = 
      (long) (Global.DEFAULT_PTS_PER_SECOND * SECONDS_BETWEEN_FRAMES); 

    public static void main(String[] args) { 

     IMediaReader mediaReader = ToolFactory.makeReader(inputFilename); 

     // stipulate that we want BufferedImages created in BGR 24bit color space 
     mediaReader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR); 

     mediaReader.addListener(new ImageSnapListener()); 

     // read out the contents of the media file and 
     // dispatch events to the attached listener 
     while (mediaReader.readPacket() == null) ; 

    } 

    private static class ImageSnapListener extends MediaListenerAdapter { 

     public void onVideoPicture(IVideoPictureEvent event) { 

      if (event.getStreamIndex() != mVideoStreamIndex) { 
       // if the selected video stream id is not yet set, go ahead an 
       // select this lucky video stream 
       if (mVideoStreamIndex == -1) { 
        mVideoStreamIndex = event.getStreamIndex(); 
       } // no need to show frames from this video stream 
       else { 
        return; 
       } 
      } 

      // if uninitialized, back date mLastPtsWrite to get the very first frame 
      if (mLastPtsWrite == Global.NO_PTS) { 
       mLastPtsWrite = event.getTimeStamp() - MICRO_SECONDS_BETWEEN_FRAMES; 
      } 

      // if it's time to write the next frame 
      if (event.getTimeStamp() - mLastPtsWrite 
        >= MICRO_SECONDS_BETWEEN_FRAMES) { 

       String outputFilename = dumpImageToFile(event.getImage()); 

       // indicate file written 
       double seconds = ((double) event.getTimeStamp()) 
         /Global.DEFAULT_PTS_PER_SECOND; 
       System.out.printf(
         "at elapsed time of %6.3f seconds wrote: %s\n", 
         seconds, outputFilename); 

       // update last write time 
       mLastPtsWrite += MICRO_SECONDS_BETWEEN_FRAMES; 
      } 

     } 

     private String dumpImageToFile(BufferedImage image) { 
      try { 
       String outputFilename = outputFilePrefix 
         + System.currentTimeMillis() + ".png"; 
       ImageIO.write(image, "png", new File(outputFilename)); 
       return outputFilename; 
      } catch (IOException e) { 
       e.printStackTrace(); 
       return null; 
      } 
     } 
    } 
} 

,我在這家下面的錯誤。

[main] ERROR com.xuggle.ferry.JNILibraryLoader - Could not load library: xuggle-xuggler; version: 3; Visit http://www.xuggle.com/xuggler/faq/ to find common solutions to this problem 
java.lang.UnsatisfiedLinkError: no xuggle-xuggler in java.library.path 
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) 
    at java.lang.Runtime.loadLibrary0(Runtime.java:845) 
    at java.lang.System.loadLibrary(System.java:1084) 
    at com.xuggle.ferry.JNILibraryLoader.loadLibrary0(JNILibraryLoader.java:265) 
    at com.xuggle.ferry.JNILibraryLoader.loadLibrary(JNILibraryLoader.java:168) 
    at com.xuggle.xuggler.XugglerJNI.<clinit>(XugglerJNI.java:19) 
    at com.xuggle.xuggler.Global.<clinit>(Global.java:238) 
    at xug.VideoThumbnailsExample.<clinit>(VideoThumbnailsExample.java:28) 
Exception in thread "main" Java Result: 1 

請解釋爲什麼類加載器是無法加載的.jar文件

+1

看起來像本地編譯庫(。所以,.DLL或名爲.dylib)不能被發現 –

回答

4

您遇到的問題是無法找到Xuggle使用的本機庫。我懷疑你的類路徑中存在衝突。

如果「所有罐子」是指下載頁面中的罐子,則不應該下載所有罐子。在Xuggler downloads page它表示要麼下載包含所有操作系統的本地庫的xuggle‑xuggler.jar,要麼選擇特定的體系結構。

在嘗試運行你鏈接到的例子,我也做了以下內容:

  • 下載xuggle‑xuggler.jar(v.5.2)。我沒有使用maven,所以按照下載頁面的說明,我打開Xuggle POM file來檢查並使用特定版本獲取依賴關係。
  • 用一點幫助從谷歌這些依賴性:slf4j-1.6.4commons-cli 1.1logback 1.0,(包含兩個必要的罐子),xuggle-utils 1.20junit你可以忽略。
    下載後,您可以在zip文件中找到POM文件中描述的5個罐子(slf4j-api-1.6.4.jar, commons-cli-1.1.jar, logback-core-1.0.0.jar, logback-classic-1.0.0.jar, xuggle-utils-1.20.688.jar),這些罐子是xuggle‑xuggler.jar的依賴關係。
  • 在您最喜愛的IDE(我使用Eclipse)中創建一個項目將這些6個jar文件導入到您的項目中,並且您很好。

按照上述步驟,我可以在Windows機器上成功運行測試程序。

我希望有幫助。

+0

你可以請幫助的帖子http://stackoverflow.com/questions/21672099/exception-error-com-xuggle-ferry-jnilibraryloader-could-not-load-library-oc –

+0

這些可以鏈接被打破,你能否請更新你的答案 –

+0

@Jaggz鏈接已損壞,但沒有更新的答案。如果您訪問[xuggler的github頁面](https://github.com/artclarke/xuggle-xuggler),您會看到它現在已被棄用,作者建議使用[謙虛視頻](https://github.com/ artclarke/humble-video)代替 –

0

繼CS的回答結束了對我的工作:

  • 代替xuggle,xuggler.jar使用xuggle-xuggler-5.4.jar(谷歌的名稱,如果鏈接中斷)

  • 而不是xuggle-utils-1.20.688。罐子使用com.xuggle.utils-1.22.jar

  • 創建一個項目,導入6個罐子和運行這個測試:

    import com.xuggle.xuggler.ICodec; 
    import com.xuggle.mediatool.ToolFactory; 
    import com.xuggle.mediatool.IMediaWriter; 
    import java.awt.image.BufferedImage; 
    import java.io.File; 
    import java.util.concurrent.TimeUnit; 
    
    public class XuggleTest { 
    
        private static int idx = 1; 
        private static final int WIDTH = 500; 
        private static final int HEIGHT = 500; 
        private static final int NFRAMES = 200; 
    
        public static void main(String[] arguments) { 
    
         // Create writer 
         IMediaWriter writer = ToolFactory.makeWriter("output.mp4"); 
         writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4, WIDTH, HEIGHT); 
         long ms = 15; // ms per frame 
    
         for (int i = 0; i < NFRAMES; i++) { 
    
          BufferedImage frame = convert(getFrame()); 
          long time = i * ms; 
          writer.encodeVideo(0, frame, time, TimeUnit.MILLISECONDS); 
    
          idx++; 
         } 
         System.out.println("Finished writing file: " + System.getProperty("user.dir") + File.separator + writer.getUrl()); 
    
         writer.close(); 
        } 
    
        private static BufferedImage convert(BufferedImage value) { 
         // Convert data type 
         BufferedImage result = new BufferedImage(value.getWidth(), value.getHeight(), BufferedImage.TYPE_3BYTE_BGR); 
         result.getGraphics().drawImage(value, 0, 0, null); 
         return result; 
        } 
    
        private static BufferedImage getFrame() { 
         // Create image frame 
         BufferedImage img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB); 
         img.createGraphics().fillRoundRect(idx, idx, idx, idx, 10, 10); 
         return img; 
        } 
    } 
    
相關問題