Java 中的视频播放(JMF、Fobs4JMF、Xuggler、FMJ)
我需要用 Java 进行简单的视频播放。
以下是我的要求:
制作质量
打开并解码其视频和音频编解码器可以由我选择的视频文件。 IE 我可以选择表现良好的编解码器。
能够播放、暂停、seekToFrame或seekToTime和停止播放。本质上,我希望能够以非线性方式播放单个视频文件的片段。例如,我可能想播放 20.3 秒到 25.6 秒的片段,暂停 10 秒,然后播放 340.3 秒到 350.5 秒的片段,等等。
在播放过程中,视频和音频必须同步。
视频必须在 Swing JComponent 中显示。
必须能够在商业产品中使用,而不必开源(IE LGPL 或 Comercial 很好)
我的研究使我找到了以下解决方案:
- 使用 Java Media Framework + Fobs4JMF http://fobs.sourceforge.net/f4jmf_first.html
我已经实现了一个快速原型,这个似乎做我需要的。我可以使用以下方式播放一段视频:
player.setStopTime(new Time(end));
player.setMediaTime(new Time(start));
player.start();
虽然 Fobs4JMF 似乎可以工作,但我觉得代码质量很差,并且该项目不再活跃。有人知道有哪些产品使用 Fobs4JMF 吗?
- 编写一个播放视频的 Flash 应用程序,并使用 JFlashPlayer 将其引入我的 Java Swing 应用程序中
与 Java 不同,Flash 在播放视频方面表现出色。我可以使用以下方法编写一个小型 Flash 应用程序:
open(String videoFile),
play(),
pause(),
seek(int duration),
stop()
然后使用 JFlashPlayer 将其引入 Java,JFlashPlayer 可以从 Java 调用 Flash 函数。
我喜欢这个解决方案的原因是 Flash 中的视频播放应该坚如磐石。有人用JFlashPlayer在Java中播放视频吗?
- 在 Xuggler 之上编写一个简单的媒体播放器
Xuggler 是 Java 的 FFMpeg 包装器,这似乎是一个非常活跃且高质量的项目。然而,实现需求中描述的简单视频播放并不是微不足道的(特别是 Seeking),但一些工作已经在 MediaTools MediaViewer 中完成,这将是构建的基础。
- 使用 FMJ
我曾尝试让 FMJ 发挥作用,但到目前为止还没有成功。
我很感激您对我的问题的意见。
I need simple video playback in Java.
Here are my requirements:
PRODUCTION QUALITY
Open and decode video files whose video and audio codecs can be chosen by me. I.E I can pick well behaving codecs.
Be able to play, pause, seekToFrame OR seekToTime and stop playback. 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.
During playback, video and audio must be in sync.
The video must be displayed in a Swing JComponent.
Must be able to use in a commercial product without having to be open source (I.E. LGPL or Comercial is good)
My research has led me to the following solutions:
- Use Java Media Framework + Fobs4JMF
http://fobs.sourceforge.net/f4jmf_first.html
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. Does anyone know of any products which use Fobs4JMF?
- Write a Flash application which plays a video and use JFlashPlayer to bring it into my Java Swing application
Unlike Java, Flash is brilliant at playing video. I could write a small Flash application with the methods:
open(String videoFile),
play(),
pause(),
seek(int duration),
stop()
Then bring it into Java using JFlashPlayer which can call Flash functions from Java.
What I like about this solution is that video playback in Flash should be rock solid. Has anyone used JFlashPlayer to play video in Java?
- Write a simple media player on top of Xuggler
Xuggler is an FFMpeg wrapper for Java which seems to be a quite active and high quality project. 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.
- Use FMJ
I have tried to get FMJ to work but have had no sucess so far.
I would appreciate your opinions on my problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
有兄弟可以为Xuggler喊一声吗?
Can a brother get a shout out for Xuggler?
在我看来,VLCJ 是此类事物的发展方向。我喜欢 Xuggler 的编码/转码工作,但不幸的是,执行简单的播放和解决所有同步问题等都太复杂了 - 而且这样做确实感觉像是重新发明轮子。
VLCJ 唯一的问题是,为了让它能够与多个播放器可靠地工作,我不得不求助于进程外播放器。该框架并不是世界上安装起来最简单的东西,但是当它在那里时,它就会完美地工作。我目前在我的应用程序中并排运行 3 个进程外播放器,没有任何问题。
另一个需要注意的是,嵌入式媒体播放器不能与 swing 组件一起使用,而只能与重量级画布一起使用 - 但这对我来说根本不是问题。如果是这样,那么您可以使用直接媒体播放器来获取缓冲图像并在您选择的任何内容上显示该图像,但它会更多地消耗您的 CPU(尽管不会比采用此方法的其他播放器更多)。
In my mind, VLCJ is the way forward for this type of thing. 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.
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. 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.
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. 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.)
JavaFX 内置了许多可用的视频和音频编解码器。这可能是目前获得最广泛支持的解决方案。
JavaFX has a number of working video and audio codecs builtin. It's likely to be the solution with the broadest support at the moment.
我一直以与使用 FOBS 相同的方式使用 jffmpeg,它工作得很好,尽管我没有对它们进行比较。
我也希望看到一种像 JavaFX 那样与本机编解码器交互的简单方法,但 JavaFX 和 Java 之间似乎没有真正的集成。
还有一些工作试图将 VLC 库 libvlc 引入 java。我还没有尝试过,很想听听尝试过的人的回复。
I've been using jffmpeg in the same way you use FOBS, it works pretty well, although I haven't compared them.
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.
There has also been some work trying to get the VLC library libvlc into java. I haven't tried it yet and would be interested to hear back from anyone who has.
还没有尝试过 Xuggler(我对此很感兴趣),但我在 VLCJ 上玩得很开心。我发现它的缺点只是你必须在应用程序之前安装 VLC。
haven't tried Xuggler (which i'm interested in) but I'm having a good time with VLCJ. The drawback I find in it is only that you have to have VLC installed prior to your application.
我建议使用 MPV。您可以轻松地将它与 JavaFX 结合使用,请参阅此 示例.
简而言之,您使用一点 JNA 魔法来直接使用 MPV 本机库,然后让视频显示在 JavaFX 舞台上。如果您使用子舞台,您甚至可以在视频顶部覆盖 JavaFX 控件(具有完全透明度支持)。
VLC(带有 VLCJ)可以以类似的方式使用,但我发现 MPV 解决方案性能更好(寻道和启动时间更快)。
I'd recommend using MPV. You can use it in combination with JavaFX quite easily, see this example.
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. If you use a child stage, you can even overlay JavaFX controls on top of the video (with full transparancy support).
VLC (with VLCJ) can be used in a similar fashion, but I find that the MPV solution performs better (faster seek and start times).
JMF / Fobs / Xuggler 均处于非活动状态。
JavaFX 是一个选项,但如果您需要同时混合 2-3 个视频
你不会有一个美好的时光和一个大块的盛宴。
不幸的是,VLCJ 似乎也有点“笨重”,虽然没有那么糟糕,但也有它自己的问题。
推荐OpenCV,支持64位。使用它取得了最大的成功,可以一次播放多个视频并且没问题。
JMF / Fobs / Xuggler are all inactive.
JavaFX is an option, but if you need too mix 2-3 videos at once
you are not going too have a good time and a chunk fest.
VLCJ seemed a little "chunky" as well unfortunately, not as bad but had it's own problems.
Recommend OpenCV, supports 64bit. Have had the best success with it, can play several videos at once and be fine.