用 Java 处理视频(DVD、.avi .mkv) [英] Dealing with video (DVDs, .avi .mkv) in Java

查看:32
本文介绍了用 Java 处理视频(DVD、.avi .mkv)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在四处寻找用 Java 播放视频的体面库之后,我不知所措.周围的每个人都在尖叫不要使用 JMF,因为它已经过时、陈旧并且需要用户安装它,其他替代品如 VLCJ 看起来不错,如果它们工作但仍然相对不稳定并且依赖大量本机代码,至于处理DVD,在免费图书馆中找到似乎是金粉!

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!

  • 现在 JavaFX 2 势头强劲,这是我一直在认真研究的问题(因此我的问题 此处),但到目前为止,我没有运气试图弄清楚如何让它播放比沼泽标准 FLV 视频更多的内容.
  • VLCJ 的工作效果很好(请参阅我当前的答案),目前我正在着手进行.它使用 libvlc 做几乎任何事情,因为它可以播放几乎任何文件,也可以播放开箱即用的 DVD.一个大问题是你必须为每个播放器使用多个虚拟机才能使其稳定运行,这意味着响应相对较慢.我还没有在 Mac 上使用这种方法.
  • JMF 已经过时、可笑,而且在我看来并不是一个真正的选择.我以前玩过,体验不是很好!
  • FMJ 说它是 JMF 的替代品.我还没有让它发挥作用,就像我交谈过的大多数其他人一样,这本身就让我厌倦了它的质量和理解力,即使我确实设法让它发挥作用!
  • Xuggler 的工作非常出色,它有精彩的教程,而且写得非常好.但是,虽然它非常适合低级转码工作,但播放视频并以正确的顺序获取帧并同步等等只是正常工作的噩梦,并且再次添加更多代码,这意味着更多维护,可能会出现更多错误等等等等...
  • 我还没有生气地尝试过 GStreamer-Java,尽管它似乎不支持 DVD 播放(这是一个我正在开发的开源应用程序,因此也不能选择商业插件)并且它是编解码器支持似乎不是最广泛的.
  • JCodec 是一项有趣的工作,是我见过的唯一一个从纯 Java 角度实现视频支持的工作- 但目前缺乏对格式的支持,而且这是一个相对较新的项目.
  • 针对我想要支持的每个平台,在不同的本机库中自己编写一些东西.由于需要额外的维护和编码时间,因此这绝对是最后的选择.
  • 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.
  • JCodec is 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.

基于上述(或您能想到的任何其他内容),人们会推荐哪些选项,还有我错过的其他明智选项吗?或者其他人认为可能在不久的将来可用?

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?

推荐答案

在对不同选项进行了大量研究并尝试了一些之后,我毕竟已经使用了 VLCJ,但这里有一个问题 - 所有 VLCJ 的东西在进程外 VM 中完成.设置起来有点复杂(参见 这里我是如何做到的)但之后你可以随心所欲地投入一切,它工作得很好(目前使用3个没有稳定性问题的进程外播放器.)

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 here for 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.)

Xuggler 很棒,但不幸的是,对我来说水平太低了 - 只需要重新发明轮子(还有更糟糕的轮子)就需要通过寻找工作来播放,这让我有些失望;我觉得用它来解决所有问题需要很长时间.对于编码/转码/其他低级视频工作,尽管我全心全意推荐它 - 毫无疑问是最好的.

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.

我选择的方法有什么注意事项?好吧,如果外部 VM 没有明确关闭,即使在应用程序退出后,它们也会在后台继续播放视频,并且使用这种方法进行调试会变得更加困难.我还没有验证它在 Mac 上运行,我最初的建议可能不是因为据我所知 MacOS 不允许一个进程在没有本地代码明确许可的情况下控制另一个进程的窗口.不过,这应该可以通过一些工作来实现.

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.

作为我目前正在进行的项目的衍生项目,我可能会看看我是否可以将所有这些进程外功能封装在一个简单的 Java 视频框架中,该框架在下面使用 VLCJ.如果有人对此感兴趣(我不能保证任何事情,但我得到的兴趣越多,我就越有可能致力于它),请随时告诉我!

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!

因此,根据我的研究和发现,如果您只想播放/录制/流式传输视频内容,我建议使用 VLCJ(但绝对使用进程外播放器),如果您想使用 Xuggler想要使用编解码器本身进行任何低级视频工作.在撰写本文时,还没有很好的纯 Java 解决方案,它可能会保持这种状态一段时间 - 幸运的是,尽管使用本机库跨平台可以获得不错的结果.只是需要做更多的工作!

So after my research and findings, I'd recommend going with VLCJ (but definitely using 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!

这篇关于用 Java 处理视频(DVD、.avi .mkv)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆