2012-11-06 71 views
1

我必須在Java/OpenGL應用程序中播放相當大的視頻,在某些情況下播放UHD(4000x2000)。我現在用VLCJ解決了這個問題(無法讓GStreamer足夠快地解碼)。 當使用普通嵌入式播放器時,VLC本身播放視頻就像VLCJ一樣好。使用DirectMediaPlayer使用vlcj播放大型視頻(FullHD +)

當我使用直播系統時,較大的視頻開始播放並在幾幀後停止播放,或根本不啓動(display()仍然被調用,但始終使用相同的幀!)。對於我來說,HDReady(1280x720仍然播放良好)和FullHD(1920x1080)之間的某個地方。這似乎不依賴於PC的性能。我在一臺5年前的筆記本電腦和高端機器上測試了這一結果,結果完全相同。 任何想法,如果我做錯了什麼或如果VLCJ DirectPlayer只是無法處理較大的視頻?

我正在使用VLC 2.0.0(也試過2.0.3和2.0.4)與github最新的VLCJ。

我有一個在線日誌上:http://pastebin.com/UeyMrVmW

我attatch一個簡單的例子,我如何設置它再現了問題的直接播放。

public class VLCTestPlayer implements RenderCallback, BufferFormatCallback { 

protected MediaPlayerFactory mediaPlayerFactory; 

protected DirectMediaPlayer mediaPlayer; 

public static void main(final String[] args) { 
    NativeLibrary.addSearchPath("libvlc", 
      "C:\\Program Files (x86)\\VideoLAN\\VLC"); 
    SwingUtilities.invokeLater(new Runnable() { 
     @Override 
     public void run() { 
      VLCTestPlayer testplayer = new VLCTestPlayer(args); 
     } 
    }); 
} 

private VLCTestPlayer(String[] args) { 

    JFrame frame = new JFrame("vlcj Tutorial"); 

    mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--verbose=3"); 

    mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(this, this); 

    String videoFile = "myVideo.mp4"; 
    boolean started = mediaPlayer.prepareMedia(videoFile); 

    if (started) 
     mediaPlayer.play(); 
    System.out.println("Video started: " + started + " from: " + videoFile); 

    frame.setLocation(100, 100); 
    frame.setSize(1050, 600); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.setVisible(true); 
} 

@Override 
public BufferFormat getBufferFormat(int sourceWidth, int sourceHeight) { 
    sourceWidth = sourceWidth/1; 
    sourceHeight = sourceHeight/1; 
    System.out.println("Got VideoFormat: " + sourceWidth + "x" 
      + sourceHeight); 
    BufferFormat format = new BufferFormat("RGBA", sourceWidth, 
      sourceHeight, new int[] { sourceWidth * 4 }, 
      new int[] { sourceHeight }); 

    return format; 
} 

@Override 
public void display(DirectMediaPlayer mediaPlayer, Memory[] nativeBuffers, 
     BufferFormat bufferFormat) { 

    ByteBuffer buffer = nativeBuffers[0].getByteBuffer(0, 
      (int) bufferFormat.getWidth() * (int) bufferFormat.getHeight() 
        * 4); 
    int pos = 4 * ((int) bufferFormat.getWidth() 
      * (int) bufferFormat.getHeight()/2 + (int) bufferFormat 
      .getWidth()/2) + 700; 
    System.out.println("Got VideoFrame: " + buffer.get(pos) + ":" 
      + buffer.get(pos + 1) + ":" + buffer.get(pos + 2) + ":" 
      + buffer.get(pos + 3)); 
} 
} 

回答

1

我會說這是幾乎可以肯定,儘管你的測試性能問題 - 從我的經驗,玩高清視頻直接播放,甚至在你做不會有工作方式現代化的系統,無需硬件它只是不會應付加速。作爲粗略指南,我的6個月大的i5臺式機幾乎不能管理720p視頻。 (作爲一個方面說明,你在那裏的println聲明肯定不會有什麼幫助,如果每秒完成多次,他們可能會花費比你想象的更多的時間。)

但是,節省的優雅是你應該能夠使用JavaFX及其提供的硬件加速類來獲得此功能 - 有關詳細信息,請參閱here