使用vlcj从视频中获取FPS

时间:2015-01-22 18:44:33

标签: java vlcj

有没有办法在不启动视频播放或显示视频本身的情况下从vlcj获取每秒帧数?

2 个答案:

答案 0 :(得分:2)

不,我担心没有办法做到这一点。

这不是vlcj的限制,vlcj提供了LibVLC提供的任何内容。

对于需要这种信息的应用程序,我会使用“MediaInfo”工具作为单独的进程(使用commons-exec)并解析输出。

https://mediaarea.net/en/MediaInfo

答案 1 :(得分:0)

// Create a VLCJ component and a window (if having a GUI is acceptable for you)
EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
JFrame frame = new JFrame();
frame.setContentPane(mediaPlayerComponent);

// Make sure the video is not visible nor audible
mediaPlayerComponent.mediaPlayer().audio().setMute(true);
mediaPlayerComponent.mediaPlayer().audio().setVolume(0);
mediaPlayerComponent.setVisible(false);

// Load the file. startXXX() functions are blocking calls, rather than playXXX(), until the video is ready.
frame.setVisible(true);
mediaPlayerComponent.mediaPlayer().media().startPaused("C:\\video.mp4");

// if there are several video tracks, make sure to take the index of the track with the same "id" value.
int index = 0;
for (int i = 0; i < mediaPlayerComponent.mediaPlayer().media().info().videoTracks().size(); ++i) {
  if (mediaPlayerComponent.mediaPlayer().media().info().videoTracks().get(i).id() == mediaPlayerComponent.mediaPlayer().video().track()) {
    index = i;
    break;
  }
}

// Get the frame rate (images per second)
double imgRate = (double)mediaPlayerComponent.mediaPlayer().media().info().videoTracks().get(index).frameRate() / mediaPlayerComponent.mediaPlayer().media().info().videoTracks().get(index).frameRateBase();