Java 中的视频播放(JMF、Fobs4JMF、Xuggler、FMJ)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2041871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Video playback in Java ( JMF, Fobs4JMF, Xuggler, FMJ )
提问by ksullivan
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. I.E I can pick well behaving codecs.
Be able to play, pause, seekToFrameOR seekToTimeand stopplayback. 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)
生产质量
打开和解码视频文件,其视频和音频编解码器可以由我选择。IE 我可以选择表现良好的编解码器。
能够播放、暂停、seekToFrame或seekToTime并停止播放。基本上我希望能够以非线性方式播放单个视频文件的片段。例如,我可能想播放 20.3 秒到 25.6 秒的片段,暂停 10 秒,然后播放 340.3 秒到 350.5 秒的片段,等等。
在播放过程中,视频和音频必须同步。
视频必须显示在 Swing JComponent 中。
必须能够在商业产品中使用而不必开源(IE LGPL 或 Comercial 都不错)
My research has led me to the following solutions:
我的研究使我找到了以下解决方案:
- Use Java Media Framework + Fobs4JMF http://fobs.sourceforge.net/f4jmf_first.html
- 使用 Java 媒体框架 + 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?
虽然 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. I could write a small Flash application with the methods:
与 Java 不同,Flash 在播放视频方面非常出色。我可以使用以下方法编写一个小型 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. Has anyone used JFlashPlayer to play video in Java?
我喜欢这个解决方案的地方在于 Flash 中的视频播放应该是坚如磐石的。有没有人用 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. 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.
Xuggler 是 Java 的 FFMpeg 包装器,它似乎是一个非常活跃和高质量的项目。然而,实现要求中描述的简单视频播放并非易事(特别是寻求),但一些工作已经在 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.
我会很感激你对我的问题的意见。
采纳答案by Art Clarke
Can a brother get a shout out for Xuggler?
兄弟可以为Xuggler 呐喊吗?
回答by jsight
回答by paul
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. I haven't tried it yet and would be interested to hear back from anyone who has.
也有一些工作试图将 VLC 库 libvlc 导入 java。我还没有尝试过,很想听听任何人的反馈。
回答by Oso
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.
还没有尝试过 Xuggler(我很感兴趣),但我在VLCJ 上玩得很开心。我发现其中的缺点只是您必须在应用程序之前安装 VLC。
回答by Michael Berry
In my mind, VLCJis 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.
在我看来,VLCJ是这类事情的前进方向。我喜欢 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. 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.
VLCJ 唯一的事情是让它与多个播放器一起可靠地工作,我不得不求助于进程外播放器。该框架并不是世界上最容易实现的东西,但是当它在那里时它运行得非常好。我目前正在我的应用程序中并排运行 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. 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.)
另一个警告是,嵌入式媒体播放器不能使用 Swing 组件,只能使用重量级画布 - 但这对我来说根本没有问题。如果是这样,那么您可以使用直接媒体播放器获取缓冲图像并将其显示在您选择的任何内容上,但它会更多地占用您的 CPU(尽管不会比采用这种方法的其他播放器更多。)
回答by john16384
I'd recommend using MPV. You can use it in combination with JavaFX quite easily, see this example.
我建议使用MPV。您可以很容易地将它与 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. If you use a child stage, you can even overlay JavaFX controls on top of the video (with full transparancy support).
简而言之,您使用一点 JNA 魔法直接使用 MPV 本地库,然后让视频显示在 JavaFX 舞台上。如果您使用子阶段,您甚至可以在视频顶部覆盖 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 解决方案的性能更好(更快的搜索和启动时间)。