Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

api - Dealing with video (DVDs, .avi .mkv) in Java

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!

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.
  • 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 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.

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.

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!

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...