30

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?

Community
  • 1
  • 1
Michael Berry
  • 70,193
  • 21
  • 157
  • 216
  • 1
    Xuggler is great as long as one of the released versions will work for you and you aren't expecting any fixes or updates. Its pretty much DIY now. – Paul Gregoire Apr 18 '14 at 20:41
  • @Mondain It's great for lower level transcoding work, but if you just want to build a media player it requires a lot of work just to get relatively simple features working properly (such as seeking.) – Michael Berry Apr 19 '14 at 13:19

7 Answers7

13

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!

Michael Berry
  • 70,193
  • 21
  • 157
  • 216
  • 1
    Yep, thats true. I've tried all of the libraries and only had luck with Xuggler and VLCJ (tnx for recommending VLCJ, [STACK](http://stackoverflow.com/questions/6731844/which-java-library-to-use-for-record-a-video-from-a-connected-camera)). I decided to use VLCJ since Xuggler has no camera support. For now I developed app that uses VLCJ and streams from 2 different cameras and desktop into 3 separate .flv files at the same time and it works. But I don't use out of process.. to be true, didn't heard about out of process player until yours answer on my question. I'll go now and read your article. – vale4674 Oct 24 '11 at 18:22
  • Any current best recommendation as of now, as this post is about 5 years back. I hope there may be some libraries now. is any? – kuhajeyan Jun 21 '16 at 06:15
  • @kuhajeyan The only thing that's really changed is that some of the bugs with more than one VLCJ instance in the same VM have been fixed, but AFAIK still not all of them. There's certainly no additional Java based libraries that I know of that offer better support. – Michael Berry Jun 21 '16 at 08:25
  • @berry120 thanks, me too finally had to resorted to vlcj, my initial intention is to keep everything to run from within, would have felt fine if xuggler was still active. Sad to see it is no longer active. – kuhajeyan Jun 21 '16 at 09:31
  • I had to use custom stream that decrypted mp4 on the fly and passed data to vlclib through memory buffer (imem). That was so slow that mp4 video started up in like 20-30 seconds. Each read had to be done through JNI. any ideas how to do this othervise? – ed22 Apr 10 '18 at 02:06
  • @MichaelBerry The only reason the vlcj is running externally is because otherwise the application will crash at some point? I am asking this because this is the behavior I am encountering at this moment after vlcj is running a long time. At some point it stucks, but no visible cause is to be found - looking into logs, there is nothing to indicate an exception stacktrace. Maybe there is a silent crash, but until so far I did not find it. – Victor Mar 07 '19 at 15:47
2

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.

olafpadme
  • 76
  • 7
1

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.

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.

Also, my other post might be of interest to you. Link

Also, this might be useful.

Community
  • 1
  • 1
user489041
  • 27,916
  • 55
  • 135
  • 204
  • I've also tried FMJ in the past without managing to get it to work, and have spoken to others who have ended up in a similar situation! I'm in two minds about VLCJ - on the face of it it looks very good, it's got hefty media support and has native binaries for multiple platforms. But the amount of crashes (and I mean full on VM blowouts, not just errors and exceptions being thrown) that I've been getting when using it has been horrific. Hopefully this will improve in the future, but for a user friendly application like the one I'm trying to develop at the moment it unfortunately rules it out. – Michael Berry Jan 12 '11 at 17:47
  • I know, they pride it on being a drop in replacement... if only it were that easy. Ive never actually got down to toying with VLCJ, but it being so unstable would def cause you some serious issues. Java just really lacks a good up to date multimedia solution. You might find my other post interesting about using JMF without having to explicitly install it. I liked it above. – user489041 Jan 12 '11 at 17:50
  • Thanks for that link - I'd actually come across that answer when searching around earlier, it's good to solve the installer problem! I couldn't get VLCJ to work reliably at all. It kept crashing before doing anything initially, and then when I did manage to get it to work it kept crashing at seemingly random intervals. It's a shame, because if it "just worked" it'd be exactly what I needed! – Michael Berry Jan 13 '11 at 01:59
1

Have you tried of using the JavaFX APIs?.

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

http://javafxplace.blogspot.com/2010/06/javafx-and-webm-on-linux.html

  • I haven't yet tried using them, but if I am using JavaFX I'd prefer to wait until 2.0 came out and that horrible JavaFX script was deprecated. JavaFX on the desktop is possible with the current versions sure - but all the examples I've seen using video are rather hacky and usually depend on internals that might change from release to release. – Michael Berry Jan 18 '11 at 11:30
1

Try Xuggler , it wraps the famous FFmpeg libraries in Java.

ismail
  • 46,010
  • 9
  • 86
  • 95
1

I can recommend the gstreamer-java bindings. As the name suggests, it wraps the GStreamer API 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.

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

Waldheinz
  • 10,399
  • 3
  • 31
  • 61
0

I'm currently using the OpenImaj Library http://openimaj.org/tutorial which has a

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.

javatar
  • 13
  • 1
  • 2
  • As per some of the other comments, I'd be weary of using anything based on Xuggle as it's been inactive for a number of years now. Besides, it's a rather low level libary and is much more suited to processing of individual frames rather than actual video playback. – Michael Berry Jul 13 '18 at 23:35