用 Java 处理视频(DVD、.avi .mkv)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4669384/
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
Dealing with video (DVDs, .avi .mkv) in Java
提问by Michael Berry
After looking around for a decent library for playing videos in Java, I've come unstuck. Everyone around is screaming not to use JMF because it's outdated, old and requires the user to install it, other alternatives such as VLCJ seem good if they work but are still relatively unstable and rely on hefty amounts of native code, and as for dealing with DVDs, that seems like gold dust to find in a free library!
在四处寻找用 Java 播放视频的体面库之后,我陷入了困境。周围的每个人都在尖叫不要使用 JMF,因为它已经过时、陈旧并且需要用户安装它,其他替代品如 VLCJ 看起来不错,如果它们工作但仍然相对不稳定并且依赖大量本机代码,至于处理DVD,在免费图书馆中找到似乎是金粉!
Current Options:
当前选项:
- Now JavaFX 2 is gaining momentum it's been something I've been seriously looking at (hence my question here) but I've no luck so far in trying to work out how to make it play anything more than bog standard FLV video.
- VLCJ is working well for what it does (see my current answer) and at the moment is what I'm going ahead with. It uses libvlc to do pretty much anything, as in it can play pretty much any file and plays DVDs out of the box too. Big problem is that you have to use multiple VMs for each player to get it to perform stably, and that means response is relatively slow. I also haven't got this approach to work on a Mac yet.
- JMF is ridiculously outdated, horrible and just not really an option as far as I'm concerned. I've played with it in the past, and the experience was not a good one!
- FMJ says it's a replacement drop in for JMF. I've yet to make it work, as have most other people I've spoken to, and that in itself makes me weary of its quality and comprehension even if I do manage to get it working!
- Xuggler is great for what it does, it's got brilliant tutorials and it's very well written. But while it's great for the low level transcoding work, playing a video and getting the frames in the right order and in sync and so on is just a nightmare to get working properly, and again adds more code which means more maintenance, potentially more bugs etc. etc...
- I haven't tried GStreamer-Java yet with any anger, though it doesn't seem to support DVD playback (it's an open source app I'm working on so commercial plugins aren't an option either) and it's codec support doesn't seem to be the widest.
- JCodecis an interesting effort, the only one I've seen to implement video support from a pure Java perspective - but support for formats is lacking at the moment and it's a relatively new project.
- Writing something myself in a different native library for each platform I want to support. This is the absolute last resort option due to the added maintenance and coding time it'd require.
- 现在 JavaFX 2 正在获得动力,它一直是我一直在认真研究的东西(因此我的问题在这里),但到目前为止我没有运气试图弄清楚如何让它播放比沼泽标准 FLV 视频更多的东西。
- VLCJ 的功能运行良好(请参阅我当前的答案),目前我正在着手进行。它使用 libvlc 做几乎任何事情,因为它可以播放几乎任何文件,也可以播放开箱即用的 DVD。一个大问题是你必须为每个播放器使用多个虚拟机才能使其稳定运行,这意味着响应相对较慢。我还没有在 Mac 上使用这种方法。
- JMF 已经过时了,太可怕了,而且就我而言,这并不是一个真正的选择。以前玩过,体验不是很好!
- FMJ 说它是 JMF 的替代品。我还没有让它工作,就像我交谈过的大多数其他人一样,这本身就让我厌倦了它的质量和理解力,即使我确实设法让它工作了!
- Xuggler 非常擅长它的工作,它有精彩的教程,而且写得很好。但是,虽然它非常适合低级转码工作,但播放视频并以正确的顺序获取帧并同步等等只是正常工作的噩梦,并且再次添加更多代码,这意味着更多维护,可能会出现更多错误等等等等...
- 我还没有愤怒地尝试过 GStreamer-Java,尽管它似乎不支持 DVD 播放(我正在开发它是一个开源应用程序,因此商业插件也不是一个选择)并且它的编解码器支持不支持' t似乎是最宽的。
- JCodec是一项有趣的工作,是我见过的唯一一个从纯 Java 角度实现视频支持的工作 - 但目前缺乏对格式的支持,而且它是一个相对较新的项目。
- 我自己在不同的本地库中为我想要支持的每个平台编写一些东西。由于需要增加维护和编码时间,因此这是绝对的最后选择。
Based on the above (or anything else you can think of), what options would people recommend and are there any other sensible ones I've missed out? Or any others people think might be available in the near future?
基于以上(或您能想到的任何其他内容),人们会推荐哪些选项,还有我错过的其他明智选项吗?或者其他人认为可能在不久的将来可用?
采纳答案by Michael Berry
After doing a lot of research around different options and trying a few out, I've gone with VLCJ after all, but here's the catch - all the VLCJ stuff is done in out of process VM's. It's a bit more complicated to set up (see herefor how I did it) but afterwards you can throw all you like at it and it works just fine (currently using 3 out of process players with no stability issues.)
在对不同选项进行了大量研究并尝试了一些之后,我毕竟已经使用了 VLCJ,但这里有一个问题 - 所有 VLCJ 的东西都是在进程外 VM 中完成的。设置起来有点复杂(请参阅此处了解我是如何做到的),但之后您可以随心所欲地投入使用,并且效果很好(目前使用 3 个没有稳定性问题的进程外播放器。)
Xuggler was great, but unfortunately too low level for me - the sheer amount of re-inventing the wheel (and a worse wheel at that) required just to get playback with seeking working put me off somewhat; I felt it'd take forever to sort all the problems out with it. For encoding / transcoding / other low level video work though I'd wholeheartedly recommend it - best without a doubt.
Xuggler 很棒,但不幸的是,对我来说水平太低了 - 只需要重新发明轮子(以及更糟糕的轮子)就可以通过寻找工作来播放,这让我有些失望;我觉得用它来解决所有问题需要很长时间。对于编码/转码/其他低级视频工作,尽管我全心全意推荐它 - 毫无疑问最好。
Caveats with my chosen approach? Well, if the external VMs aren't shut down explicitly they'll carry on playing the video in the background even after the application has quit, and debugging gets harder with this approach. I also haven't verified it runs on Mac yet, and my initial suggestion is probably not because from what I've heard MacOS doesn't let one process control another's window without explicit permission with native code. That should be possible with a bit of work though.
我选择的方法有什么注意事项?好吧,如果外部 VM 没有明确关闭,即使在应用程序退出后,它们也会在后台继续播放视频,并且使用这种方法进行调试会变得更加困难。我还没有验证它是否可以在 Mac 上运行,我最初的建议可能不是因为据我所知,MacOS 不允许一个进程在未经本机代码明确许可的情况下控制另一个进程的窗口。不过,这应该可以通过一些工作来实现。
As a spin off to the project I'm working on at the moment I might see if I can wrap up all this out of process functionality in a simple Java video framework that uses VLCJ underneath. If anyone would be interested in this (I can't promise anything but the more interest I get, the more likely I am to work on it) then feel free to let me know!
作为我目前正在进行的项目的衍生项目,我可能会看看是否可以将所有这些进程外功能封装在一个简单的 Java 视频框架中,该框架在下面使用 VLCJ。如果有人对此感兴趣(我不能保证任何事情,但我得到的兴趣越多,我就越有可能致力于它),请随时告诉我!
So after my research and findings, I'd recommend going with VLCJ (but definitelyusing out of process players) if you just want to play / record / stream video stuff, and Xuggler if you want to do any low level video work with the codecs themselves. At the time of writing, there just is no nice, pure Java solution, and it'll probably stay that way for a while - fortunately though it is possible to get decent results with native libraries cross platform. It just requires a lot more work!
因此,经过我的研究和发现,如果您只想播放/录制/流式传输视频内容,我建议使用 VLCJ(但绝对使用进程外播放器),如果您想使用 Xuggler 进行任何低级视频工作,我建议您使用编解码器本身。在撰写本文时,还没有好的、纯 Java 解决方案,而且它可能会保持这种状态一段时间 - 幸运的是,尽管使用本机库跨平台可以获得不错的结果。它只是需要更多的工作!
回答by olafpadme
I used jffmeg on some of my projects(ffmeg java bindings), so far I havent faced any problem. http://jffmpeg.sourceforge.net/documentation.html. I also used qt-jambi, but never tried its video library(phonon), this can also solve your problem.
我在我的一些项目(ffmeg java 绑定)中使用了 jffmeg,到目前为止我还没有遇到任何问题。 http://jffmpeg.sourceforge.net/documentation.html。我也使用过 qt-jambi,但从未尝试过它的视频库(声子),这也可以解决您的问题。
回答by Waldheinz
I can recommend the gstreamer-javabindings. As the name suggests, it wraps the GStreamerAPI in Java classes. This way you have access to the media-processing graphing capabilities which GStreamer provides. This can be really neat if you want to do more advanced tasks like transcoding.
我可以推荐gstreamer-java绑定。顾名思义,它将GStreamerAPI包装在 Java 类中。通过这种方式,您可以访问 GStreamer 提供的媒体处理图形功能。如果您想执行更高级的任务(例如转码),这可能非常有用。
Also, if I remember correctly, there was a commercial plugin for GStreamer which supported DVD playback and came with a license for the CSS. If this does not matter for your use case you can always go with the open-sourced one, too (the only one I ever needed).
另外,如果我没记错的话,GStreamer 有一个商业插件,它支持 DVD 播放并带有 CSS 许可证。如果这对您的用例无关紧要,您也可以始终使用开源的(这是我唯一需要的)。
回答by user489041
I'd agree with staying away from JMF. Especially if you want to play DVD's. Even JMF relies on native code for some of its functionality. You prob not going to get away from having some sort of native dependencies anyway. One other option would be FMJ. Its an open source version of JMF. I havent had much luck with it though.
我同意远离 JMF。特别是如果您想播放 DVD。甚至 JMF 的某些功能也依赖于本机代码。无论如何,您可能不会摆脱某种本机依赖关系。另一种选择是 FMJ。它是 JMF 的开源版本。虽然我没有太多运气。
My suggestion would to go with VLCJ. I was exploring this when I needed a media solution. Unfortunately it is released under the GPL so I cant use it in my application, but it seems like it should be able to handle what you want.
我的建议是使用 VLCJ。当我需要一个媒体解决方案时,我正在探索这个。不幸的是它是在 GPL 下发布的,所以我不能在我的应用程序中使用它,但它似乎应该能够处理你想要的。
Also, my other post might be of interest to you. Link
另外,我的另一篇文章你可能会感兴趣。关联
Also, thismight be useful.
此外,这可能很有用。
回答by Fernando el Geek
Have you tried of using the JavaFX APIs?.
您是否尝试过使用 JavaFX API?
The way I see it JavaFX includes support for H.264 playback... and here someone shows how to play back video in Google′s new open source WebM / VP8
在我看来 JavaFX 包括对 H.264 播放的支持……这里有人展示了如何在 Google 的新开源 WebM / VP8 中播放视频
http://javafxplace.blogspot.com/2010/06/javafx-and-webm-on-linux.html
http://javafxplace.blogspot.com/2010/06/javafx-and-webm-on-linux.html
回答by ismail
回答by javatar
I'm currently using the OpenImaj Library http://openimaj.org/tutorialwhich has a
我目前正在使用 OpenImaj 库http://openimaj.org/tutorial,它有一个
XuggleVideo and XuggleAudio class
I'd suggest you use that and implement your own threading mechanisms to play them. I'm currently working on a media player with hopes of getting it play the 'popular' video formats well since the
我建议你使用它并实现你自己的线程机制来播放它们。我目前正在开发一个媒体播放器,希望它能够很好地播放“流行”的视频格式
VideoDisplay class
in the library does a good Job but the playback is kinda choppy and the library was implemented with swing in mind and attaching the
在图书馆里做得很好,但播放有点断断续续,图书馆在实现时考虑到了摇摆并附加了
ImageComponent
to a swing node doesn't seem to work for some reason in JavaFx but I'm able to get them images from a video displaying for now and i hope i get some luck with this.
由于某种原因,到摆动节点似乎在 JavaFx 中不起作用,但我现在可以从显示的视频中获取它们的图像,我希望我能从中获得一些运气。