It seems like a simple problem, you want to allow people to upload videos, and then you want to process those videos to Flash Video. (Admit it. Flash Video is the video format for the web at the moment.) Talk to the LAMP crowd (or the Rails crowd), and when you ask them the question: “How would you process media files on the web?” You’ll find two popular answers:
- FFMpeg for video processing
- ImageMagick for image processing
But, don’t we do everything in Java through the JMF and the JAI? How would one integrate these utilities into Java?
Video: Using FFMpeg from Java
if it relates to audio or video processing, FFmpeg can probably do it. Throw almost any format at ffmpeg and ask it to resize the video, resample the audio, spit out a thumbnail of every 10th frame, and cook your breakfast, and it will do it. If you are interested in producing Flash Video from Java, and you want to involve ffmpeg in the process you’ve got some options.
- Use a drop-in JMF replacement: Freedom for Media in Java (http://fmj.sourceforge.net/)
- Use a JMF Plugin FOBS C++ & JMF Wrapper for ffmpeg (http://fobs.sourceforge.net/index.html)
- Use Runtime.exec() to invoke ffmpeg directly.
If you are looking for video transcoding, and you are not looking at a million visitors per second, the Runtime.exec() solution gets you to “done” faster than wheeling out the JMF and fiddling with the various properties files that need to be manipulated to get a JMF plugin to run properly.
Image: Using ImageMagick from Java
ImageMagick is this powerhouse image processing utility which supports about 100 image formats, provides the ability to manipulate images, apply filters, etc. If you are interested in side-stepping the JAI, here are some options.
- Take a look at JMagick which is a “thin interface layer into the ImageMagick API”.
- Use Runtime.exec() to invoke imagemagick’s command line utilities directly.
Take a look at D’Arcy Norman’s blog entry JAI vs. ImageMagick image resizing. This is a great summary comparison of using JAI vs. JMagick vs. Runtime.exec(). It proves that even though the default java reaction is to sneer at Runtime.exec(), it is admittedly one of the best integration choices between ImageMagick and Java.
Runtime.exec() *shrug*, it’s ain’t so bad…
While Runtime.exec() might seem like a bad idea for performance of a server, you should know that the Ruby programmer down the hall is busily calling out to ffmpeg and launching something revenue generating while you are still researching the intricacies of the Java Media Framework (JMF). Because ImageMagick and FFMpeg are such powerful utilities, you might be well served to just bypass JMF altogether and invoke these utilities directly. Other alternatives are to use Java as a “stevedore” for an offline processor which runs a periodic job to translate everything in a given directory to FLV. In summary, the idea here is that there are times when Runtime.exec() is an acceptable solution, not everything has to be run through the super-generalized media API.