简体   繁体   English

Java 中的视频播放(JMF、Fobs4JMF、Xuggler、FMJ)

[英]Video playback in Java ( JMF, Fobs4JMF, Xuggler, FMJ )

I need simple video playback in Java.我需要用 Java 进行简单的视频播放。

Here are my requirements:以下是我的要求:

  • PRODUCTION QUALITY生产质量

  • Open and decode video files whose video and audio codecs can be chosen by me.打开和解码视频文件,其视频和音频编解码器可以由我选择。 IE I can pick well behaving codecs. IE 我可以选择表现良好的编解码器。

  • Be able to play , pause , seekToFrame OR seekToTime and stop playback.能够播放暂停seekToFrameseekToTime停止播放。 Essentially I wish to be able to play segments of a single video file in a non linear fashion.基本上我希望能够以非线性方式播放单个视频文件的片段。 For example I may want to play the segment 20.3sec to 25.6sec, pause for 10 seconds and then play the segment 340.3sec to 350.5sec, etc.例如,我可能想播放 20.3 秒到 25.6 秒的片段,暂停 10 秒,然后播放 340.3 秒到 350.5 秒的片段,等等。

  • During playback, video and audio must be in sync.在播放过程中,视频和音频必须同步。

  • The video must be displayed in a Swing JComponent.视频必须显示在 Swing JComponent 中。

  • Must be able to use in a commercial product without having to be open source (IE LGPL or Comercial is good)必须能够在商业产品中使用而不必开源(IE LGPL 或 Comercial 都不错)


My research has led me to the following solutions:我的研究使我找到了以下解决方案:

I have implemented a quick prototype and this seems to do what I need.我已经实现了一个快速原型,这似乎满足了我的需要。 I can play a segment of video using:我可以使用以下方法播放一段视频:

player.setStopTime(new Time(end));
player.setMediaTime(new Time(start));
player.start();

While Fobs4JMF seems to work, I feel the quality of the code is poor and the project is no longer active.虽然 Fobs4JMF 似乎有效,但我觉得代码质量很差,项目不再活跃。 Does anyone know of any products which use Fobs4JMF?有谁知道使用 Fobs4JMF 的任何产品?


  • Write a Flash application which plays a video and use JFlashPlayer to bring it into my Java Swing application编写一个播放视频的 Flash 应用程序并使用 JFlashPlayer 将其带入我的 Java Swing 应用程序

Unlike Java, Flash is brilliant at playing video.与 Java 不同,Flash 在播放视频方面非常出色。 I could write a small Flash application with the methods:我可以使用以下方法编写一个小型 Flash 应用程序:

open(String videoFile),
play(),
pause(),
seek(int duration),
stop()

Then bring it into Java using JFlashPlayer which can call Flash functions from Java.然后使用可以从Java调用Flash函数的JFlashPlayer将其导入Java。

What I like about this solution is that video playback in Flash should be rock solid.我喜欢这个解决方案的地方在于 Flash 中的视频播放应该是坚如磐石的。 Has anyone used JFlashPlayer to play video in Java?有没有人用 JFlashPlayer 在 Java 中播放视频?


  • Write a simple media player on top of Xuggler在 Xuggler 之上编写一个简单的媒体播放器

Xuggler is an FFMpeg wrapper for Java which seems to be a quite active and high quality project. Xuggler 是 Java 的 FFMpeg 包装器,它似乎是一个非常活跃和高质量的项目。 However, implementing the simple video playback described in the requirements is not trivial (Seeking in particular) but some of the work has been done in the MediaTools MediaViewer which would be the base upon which to build from.然而,实现要求中描述的简单视频播放并非易事(特别是寻求),但一些工作已经在 MediaTools MediaViewer 中完成,这将是构建的基础。


  • Use FMJ使用 FMJ

I have tried to get FMJ to work but have had no sucess so far.我试图让 FMJ 工作,但到目前为止没有成功。


I would appreciate your opinions on my problem.我会很感激你对我的问题的意见。

兄弟可以为Xuggler 呐喊吗?

In my mind, VLCJ is the way forward for this type of thing.在我看来, VLCJ是这类事情的前进方向。 I love Xuggler for encoding / transcoding work, but unfortunately it's just so complicated to do simple playback and solve all the sync issues and suchlike - and it does very much feel like reinventing the wheel doing so.我喜欢 Xuggler 的编码/转码工作,但不幸的是,做简单的播放和解决所有同步问题等都太复杂了——而且这样做感觉就像是在重新发明轮子。

The only thing with VLCJ is that to get it to work reliably with multiple players I've had to resort to out of process players. VLCJ 唯一的事情是让它与多个播放器一起可靠地工作,我不得不求助于进程外播放器。 The framework wasn't the simplest thing in the world to get in place, but when it's there it works beautifully.该框架并不是世界上最容易实现的东西,但是当它在那里时它运行得非常好。 I'm currently running 3 out of process players in my app side by side with no problems whatsoever.我目前正在我的应用程序中并排运行 3 个进程外播放器,没有任何问题。

The other caveat is that the embedded media player won't work with a swing component, just a heavyweight canvas - but that hasn't proven a problem for me at all.另一个警告是,嵌入式媒体播放器不能使用 Swing 组件,只能使用重量级画布 - 但这对我来说根本没有问题。 If it does, then you can use the direct media player to get a bufferedimage and display that on whatever you choose, but it will eat into your CPU a bit more (though no more than other players that take this approach.)如果是这样,那么您可以使用直接媒体播放器获取缓冲图像并将其显示在您选择的任何内容上,但它会更多地占用您的 CPU(尽管不会比采用这种方法的其他播放器更多。)

JavaFX has a number of working video and audio codecs builtin. JavaFX内置了许多有效的视频和音频编解码器。 It's likely to be the solution with the broadest support at the moment.它可能是目前获得最广泛支持的解决方案。

I've been using jffmpeg in the same way you use FOBS, it works pretty well, although I haven't compared them.我一直在以与使用 FOBS 相同的方式使用 jffmpeg,虽然我没有比较它们,但效果很好。

I would also love to see an easy way to interface with native codecs the way that JavaFX does, but there doesn't seem to be real integration between JavaFX and Java.我也很想看到一种像 JavaFX 那样与本机编解码器交互的简单方法,但 JavaFX 和 Java 之间似乎没有真正的集成。

There has also been some work trying to get the VLC library libvlc into java.也有一些工作试图将 VLC 库 libvlc 导入 java。 I haven't tried it yet and would be interested to hear back from anyone who has.我还没有尝试过,很想听听任何人的反馈。

haven't tried Xuggler (which i'm interested in) but I'm having a good time with VLCJ .还没有尝试过 Xuggler(我很感兴趣),但我在VLCJ 上玩得很开心 The drawback I find in it is only that you have to have VLC installed prior to your application.我发现其中的缺点只是您必须在应用程序之前安装 VLC。

I'd recommend using MPV .我建议使用MPV You can use it in combination with JavaFX quite easily, see this example .您可以很容易地将它与 JavaFX 结合使用,请参阅此示例

In short, you use a little JNA magic to use the MPV native libaries directly, and then let the video display on a JavaFX stage.简而言之,您使用一点 JNA 魔法直接使用 MPV 本地库,然后让视频显示在 JavaFX 舞台上。 If you use a child stage, you can even overlay JavaFX controls on top of the video (with full transparancy support).如果您使用子阶段,您甚至可以在视频顶部覆盖 JavaFX 控件(具有完全透明支持)。

VLC (with VLCJ) can be used in a similar fashion, but I find that the MPV solution performs better (faster seek and start times). VLC(带有 VLCJ)可以以类似的方式使用,但我发现 MPV 解决方案的性能更好(更快的搜索和启动时间)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM