Video playback in Java ( JMF, Fobs4JMF, Xuggler, FMJ )

27,065

Solution 1

Can a brother get a shout out for Xuggler?

Solution 2

In my mind, VLCJ is the way forward for this type of thing. I love Xuggler for encoding / transcoding work, but unfortunately it's just so complicated to do simple playback and solve all the sync issues and suchlike - and it does very much feel like reinventing the wheel doing so.

The only thing with VLCJ is that to get it to work reliably with multiple players I've had to resort to out of process players. The framework wasn't the simplest thing in the world to get in place, but when it's there it works beautifully. I'm currently running 3 out of process players in my app side by side with no problems whatsoever.

The other caveat is that the embedded media player won't work with a swing component, just a heavyweight canvas - but that hasn't proven a problem for me at all. If it does, then you can use the direct media player to get a bufferedimage and display that on whatever you choose, but it will eat into your CPU a bit more (though no more than other players that take this approach.)

Solution 3

haven't tried Xuggler (which i'm interested in) but I'm having a good time with VLCJ. The drawback I find in it is only that you have to have VLC installed prior to your application.

Solution 4

I've been using jffmpeg in the same way you use FOBS, it works pretty well, although I haven't compared them.

I would also love to see an easy way to interface with native codecs the way that JavaFX does, but there doesn't seem to be real integration between JavaFX and Java.

There has also been some work trying to get the VLC library libvlc into java. I haven't tried it yet and would be interested to hear back from anyone who has.

Solution 5

JavaFX has a number of working video and audio codecs builtin. It's likely to be the solution with the broadest support at the moment.

Share:
27,065
ksullivan
Author by

ksullivan

Updated on July 16, 2022

Comments

  • ksullivan
    ksullivan almost 2 years

    I need simple video playback in Java.

    Here are my requirements:

    • PRODUCTION QUALITY

    • Open and decode video files whose video and audio codecs can be chosen by me. I.E I can pick well behaving codecs.

    • Be able to play, pause, seekToFrame OR seekToTime and stop playback. Essentially I wish to be able to play segments of a single video file in a non linear fashion. For example I may want to play the segment 20.3sec to 25.6sec, pause for 10 seconds and then play the segment 340.3sec to 350.5sec, etc.

    • During playback, video and audio must be in sync.

    • The video must be displayed in a Swing JComponent.

    • Must be able to use in a commercial product without having to be open source (I.E. LGPL or Comercial is good)


    My research has led me to the following solutions:

    I have implemented a quick prototype and this seems to do what I need. I can play a segment of video using:

    player.setStopTime(new Time(end));
    player.setMediaTime(new Time(start));
    player.start();
    

    While Fobs4JMF seems to work, I feel the quality of the code is poor and the project is no longer active. Does anyone know of any products which use Fobs4JMF?


    • Write a Flash application which plays a video and use JFlashPlayer to bring it into my Java Swing application

    Unlike Java, Flash is brilliant at playing video. I could write a small Flash application with the methods:

    open(String videoFile),
    play(),
    pause(),
    seek(int duration),
    stop()
    

    Then bring it into Java using JFlashPlayer which can call Flash functions from Java.

    What I like about this solution is that video playback in Flash should be rock solid. Has anyone used JFlashPlayer to play video in Java?


    • Write a simple media player on top of Xuggler

    Xuggler is an FFMpeg wrapper for Java which seems to be a quite active and high quality project. However, implementing the simple video playback described in the requirements is not trivial (Seeking in particular) but some of the work has been done in the MediaTools MediaViewer which would be the base upon which to build from.


    • Use FMJ

    I have tried to get FMJ to work but have had no sucess so far.


    I would appreciate your opinions on my problem.

  • ksullivan
    ksullivan over 14 years
    Hi jsight and thanks for your answer. I do know that JavaFX supports video but unfortunately I have had to dismiss it as it is difficult to import JavaFX components into a Java Swing application. There are ways, but they are unsupported hacks.
  • caseyamcl
    caseyamcl over 14 years
  • ksullivan
    ksullivan over 14 years
    Thanks for those links. It seems that in addition to the no official support for JavaFX in Java, there would be distribution problems (particularly relating to the video codecs)
  • caseyamcl
    caseyamcl over 14 years
    @kpsullivan - Any issue with distribution or support will be worse with any other free solution.
  • ksullivan
    ksullivan over 14 years
    What are the distribution issues with the FFMpeg based solutions such as Xuggler and Fobs4JMF? Xuggler seems quite active in terms of getting responses directly from the developers. Also we are not limiting ourselves to free solutions.
  • Michael Berry
    Michael Berry almost 13 years
    appreciate this is over a year old now, but if you're still interested see my answer!
  • paul
    paul almost 13 years
    thanks, yes, it's still an open issue for me and I'll look into this.
  • Michael Berry
    Michael Berry over 12 years
    You don't - you can distribute libvlc with your app, which is what I do.
  • Muhammad Umar
    Muhammad Umar over 12 years
    I need a lot of help on xuggle, how can i add two videos to create one video in xuggle? i am trying google but it is not helping much...
  • Michael Berry
    Michael Berry about 12 years
    Note that with JavaFX 2.1, the supported format base has increased slightly.
  • aaronsnoswell
    aaronsnoswell over 11 years
    Where on earth is the actual download link for Xuggler?!
  • taymedee
    taymedee about 10 years
    Xuggler cannot seekkeyframe for mp3 or m4a. That is the ffmpeg header missing issue.
  • asmaier
    asmaier over 9 years
    Unfortunately Xuggler is not developed actively anymore: xuggle.com/xuggler/status
  • Scuba Steve
    Scuba Steve about 8 years
    ksullivan - Xuggler is depreciated. I've used it myself, but there are problems with the libraries themselves and syncing issues. Check out my project: github.com/seannybgoode/libGDX-MultiMedia Currently in the process of moving to another media player lib.
  • Scuba Steve
    Scuba Steve about 8 years
    Don't try to get support for vlcj though, the guy is a ****ing prick.