Java 中的媒体播放器库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3886056/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 03:50:31  来源:igfitidea点击:

Media player libraries in Java

javastreamingmedia-player

提问by Grodriguez

I am evaluating libraries for playing audio/video in Java. It does not need to be 100% Java; Java bindings to native libraries are perfectly OK. An external application that can be controlled from Java is also fine, as long as it can render video on a Java component.

我正在评估在 Java 中播放音频/视频的库。它不需要是 100% Java;Java 绑定到本机库是完全可以的。可以从 Java 控制的外部应用程序也可以,只要它可以在 Java 组件上呈现视频。

The target platform is Linux. Windows support is a plus, but not required.

目标平台是Linux。Windows 支持是一个加分项,但不是必需的。

I have played with VLC using the VLCjbindings, and it works pretty well in general, but keeps crashing occasionally when put under stress. I have also used mplayer in slave mode, which looks good. But I'd like to evaluate other options as well.

我已经使用VLCj绑定玩过 VLC ,它在一般情况下运行良好,但在承受压力时偶尔会崩溃。我也在slave模式下使用过mplayer ,看起来不错。但我也想评估其他选项。

These are the requirements:

这些是要求:

  • Live playback of H.264, MPEG4 through RTP using RTSP. Extra points for MJPEG over HTTP.
  • Able to render video on a Java (Swing or AWT) Component
  • Open source, and actively maintained
  • Stable, rock-solid
  • 使用 RTSP 通过 RTP 实时播放 H.264、MPEG4。MJPEG over HTTP 的额外加分。
  • 能够在 Java(Swing 或 AWT)组件上呈现视频
  • 开源,积极维护
  • 稳定,坚如磐石

Suggestions? Advice?

建议?建议?

采纳答案by Grodriguez

Ok, I've spent the last month playing with several options and these are the results:

好的,我在上个月玩了几个选项,结果如下:

  1. VLC. This was my first thought, as everybody keeps saying that it "plays everything". I have used both the VLCjJava bindings, and the built-in remote interface(-I rc). I found this to work pretty well in general, but had some issues. I kept seeing ocassional crashes under heavy load (not VLCj's fault as it also happens when using the binary directly). Also I've found memory consumption to be relatively high when compared to other options.

  2. MPlayer. This actually performs better than VLC in my experience, no crashes, and memory consumption is lower. No Java bindings, although the slave modeworks very well.

  3. GStreamer. Very powerful, very flexible, while still easy to get started with. Tried both the Java bindingsand running the gst-launchbinary from Java. Both approaches work remarkably well.

  4. Xugglerlooked good, however it seems to have issues with RTP (as stated in the FAQ). Since both GStreamer and MPlayer worked so well, I did not get past the initial research.

  1. VLC. 这是我的第一个想法,因为每个人都一直说它“可以播放所有内容”。我使用了VLCjJava 绑定和内置远程接口( -I rc)。我发现这在一般情况下工作得很好,但有一些问题。我一直看到在重负载下偶尔崩溃(不是 VLCj 的错误,因为它在直接使用二进制文件时也会发生)。此外,我发现与其他选项相比,内存消耗相对较高。

  2. 播放器。根据我的经验,这实际上比 VLC 性能更好,没有崩溃,并且内存消耗更低。没有 Java 绑定,尽管从模式运行良好。

  3. GStreamer。非常强大,非常灵活,同时仍然易于上手。尝试了Java 绑定gst-launch从 Java运行二进制文件。这两种方法都非常有效。

  4. Xuggler看起来不错,但它似乎与 RTP 有问题(如常见问题中所述)。由于 GStreamer 和 MPlayer 都运行良好,我没有通过最初的研究。

I found GStreamer to be the best solution given the requirements, with MPlayer being the second option.

根据要求,我发现 GStreamer 是最佳解决方案,而 MPlayer 是第二个选择。

回答by Michael Berry

I've also spent a while researching my options, and I've actually come to the conclusion that VLCJ is the best option - however here's the clincher, you need to run it out of process (especially with multiple players) for it to give you 100% reliable operation. That's the approach I'm taking and I've yet to see it crash. With it rock solid in this way it also has other advantages:

我也花了一段时间研究我的选择,实际上我得出的结论是 VLCJ 是最好的选择 - 然而这里是关键,你需要运行它(尤其是在多个玩家的情况下)才能让它给出您 100% 可靠运行。这就是我正在采取的方法,我还没有看到它崩溃。以这种方式坚如磐石,它还具有其他优点:

  • It can play pretty much anything. Yes it's a bit of a cliche, but this includes DVDs, Youtube videos, pretty much any video file...
  • Should support Linux / Mac / Windows, though I've yet to verify Mac working.
  • Actively maintained, and if you ask a good (as in well thought out) question on the discussion group the owner often replies in minute in my experience!
  • Open source, and the Google group activity at the time of writing is high.
  • Uses all the graphics acceleration VLC does
  • Able to play to any heavyweight Canvas component (and if you use the direct player, you get the BufferedImage to display anywhere you like, even in JOGL 3D land if you're that crazy!
  • 它几乎可以播放任何东西。是的,这有点陈词滥调,但这包括 DVD、Youtube 视频,几乎任何视频文件......
  • 应该支持 Linux / Mac / Windows,虽然我还没有验证 Mac 是否工作。
  • 积极维护,如果您在讨论组中提出一个好的(经过深思熟虑的)问题,根据我的经验,所有者通常会在几分钟内回复!
  • 开源,在撰写本文时谷歌群组活跃度很高。
  • 使用 VLC 的所有图形加速功能
  • 能够播放任何重量级的 Canvas 组件(如果您使用直接播放器,您可以将 BufferedImage 显示在您喜欢的任何地方,即使在 JOGL 3D 领域,如果您太疯狂了!

I haven't found it that heavy on the resources front either, though I haven't done any thorough testing (but 3 players work fine in tandem as well as my relatively power-hungry application on my 4 year old basic laptop!)

我也没有发现它在资源方面有那么重,尽管我没有做过任何彻底的测试(但 3 名玩家可以串联工作,而且我在我 4 岁的基本笔记本电脑上的相对耗电的应用程序!)

Disadvantages? There's no official framework for out of process players, so you have to build one yourself (see herefor how I did it). And you do sometimes have to do some fiddling to get it working. But as far as I can see, it's working well for me so far!

缺点?没有针对进程外播放器的官方框架,因此您必须自己构建一个(请参阅此处了解我是如何做到的)。有时你确实需要做一些摆弄才能让它工作。但据我所知,到目前为止,它对我来说效果很好!

回答by effetto

have you looked at gstreamer?

你看过gstreamer吗?