views:

3801

answers:

15

Hi all, i am currently working on a web application that needs to accept video uploaded by users in any format (.avi, .mov, etc.) and convert them to flv for playing in a flash-based player.

Since the site is OpenCms-based, the best solution would be a ready-made plugin for OpenCms that allowed to upload and play videos doing the transcode operation in background, but just a set of Java classes to do the transcode would be great and then i could make the uploading form and playback part on my own.

+21  A: 

There's a great open source tool call FFmpeg that I use to transcode my videos. I use PHP making shell calls to make it come to life, but I can't imagine that it would be too hard to get it to play nice with Java. (Maybe this could be a good starting point for you.)

I feed my installation 30+ gig batches on a weekly basis and it always comes out as quality material. The only tricky part for me has been getting it compiled to handle a wide variety of video formats. On the bright side, this has provided me with heavy lifting I need.

thaBadDawg
I know about FFMpeg, but i'm not sure i can make a shell call on my webserver (especially because i don't know the OS it runs on and i'd like my app to be OS-independent), i was hoping to find something pure-java
Raibaz
FFMpeg is unfortunately the only REAL player in the game for free. FFmpeg is commonly used on linux, but there's also a Windows binary if you are so inclined.
UltimateBrent
make sure you get/compile a binary with LAME support, as FLV typically uses MP3 for its audio stream
Peter Burns
FFMPeg *is* **the** way to go... As someone has mentioned in another answer, there are java wrappers you can use.
toxvaerd
+1  A: 

You could try using an online service like HeyWatch to convert your video. Never used it but they claim

"transparent upload, send videos transparently from your website"

Not a java solution, but you wouldn't have to worry about what OS your web application is on.

If OS wasn't an issue I agree with the answer theBadDawg gave. I don't know of and have had not any luck finding a pure java solution.

Mark Robinson
+1  A: 

Encoding files in one format to another takes a lot of development time to get right, which is why there is so little in terms of decoders/encoders that are able to accomplish those feats. The ones that are well known and used the most are ffmpeg and mencoder.

What you may want to look into is to see if the platform you are running on (Windows/Mac OS X/Other unix) has an underlying set of API calls you can use that is able to decode the files, and re-encode them. Windows has DirectShow and Mac OS X has Quicktime. Not sure if you can access those API's using Java though.

FFMpeg does have a Java wrapper available: FFMPEG Java, and there is also FOBS which has a JNI available for their C++ wrapper around ffmpeg. The last one that I found jFFmpeg, however there are some posts that I found with Google suggesting that the project may not be alive any longer.

Your best bet would be either mencoder from mplayer and or ffmpeg. Ffmpeg can be installed as a separate binary and then called from other code using the default "shell" commands. If you are however not able to execute commands you may need to look at using an online conversion website like Mark Robinson suggested.

X-Istence
A: 

FFMpeg is the best when it comes to video transcoding.

You can use java wrappers for ffmpeg - http://fmj-sf.net/ffmpeg-java/getting_started.php http://sourceforge.net/projects/jffmpeg/

Suku
+3  A: 

There is an open source library used by MPlayer, called mencoder, wich supports FLV, as well as a lot of other codecs.

There is a Java GUI you could see how was made

This could help too.

I don't seem to be able to find any example not called from the console, so it may not be usefull for you. :S

Edit Also take a look at this question.

voyager
+5  A: 
Baishampayan Ghose
+5  A: 

You basically have two choices if you want to host, transcode and stream flv files (and don't want to buy a video transcoding application): you can call out to FFMpeg/MEncoder or you can use an external Web service. You could also sidestep the problem completely by allowing them to embed YouTube videos on your site.

If you go the 'local FFMpeg route' I would suggest simply using ProcessBuilder and constructing a command-line to execute FFMpeg. That way you get full control over what gets executed, you avoid JNI, which is an absolute nightmare to work with, and you keep OS-specific code out of your app. You can find FFMPeg with all the bells and whistles for pretty much any platform. There's a good chance it's already on your server.

The nice thing about the 'Local FFMPeg' route is that you don't have to pay for any extra hosting, and everything is running locally, although your hosting admin might start complaining if you're using a crazy amount of disk and CPU. There are some other StackOverflow questions that talk about some of the gotchas using FFMpeg to create flvs that you can actually play in the flash player.

The Web service route is nice because there is less setup involved. I have not used Hey!Watch but it looks promising. PandaStream is easy to set up and it works well, plus you get all your videos on S3 with no additional effort.

Cameron Pope
CPU usage is definitely something you would have to watch out for if you are running on a shared hosting environment. Most plans offer plenty of disk space and bandwidth, but are very stingy on the CPU power you use.
Kibbee
+6  A: 

You can encode video in Java using Xuggler, which is a Java API that natively uses FFmpeg's C code behind the scenes.

Xuggle
+1 and many more upvotes for your answers, which are undervalued. Art, big kudos for your work in Xuggler project.
cetnar
A: 

I use a imoviesoft total video converter pro, it help me convert almost any video format with excellent conversion speed and quality, such as converting WMV to MP4, WMV to MPEG, MKV to AVI, WMV to AVI, AVI to MPEG, etc.. Furthermore, it can easily convert video files to popular audio files like converting WMV to MP3, AVI to WMA, MKV to AAC, MP4 to MP3, etc. It works as: iPod Video Converter, PSP Video Converter, iPhone Video Converter, etc. After easy and wonderful conversion, you can fully enjoy videos on your portable players. You can learn more details here: http://www.imoviesoft.com/products/total-video-converter.html

+1  A: 

If you want to do it with java, you can do it very easily using Xuggle.

They have a great website explaining how to do everything

the documentation is here: http://build.xuggle.com/view/Stable/job/xuggler_jdk5_stable/javadoc/java/api/index.html

and an excellent tutorial telling you how to do what you want is here: http: //blog.xuggle.com/2009/06/05/introduction-to-xuggler-mediatools/

They provide an easy way to do what you want in the first tutorial, which is simple trans-coding.

I've found that it works alright for encoding to flv. What it does behind the scenes is use ffmpeg, so anything that will trip up ffmpeg will also fail with xuggle.

The relevant sample java code is:

 // create a media reader
 IMediaReader reader = ToolFactory.makeReader("videofile.flv");

 // add a viewer to the reader, to see the decoded media
 reader.addListener(ToolFactory.makeWriter("output.mov", reader));

 // read and decode packets from the source file and
 // and dispatch decoded audio and video to the writer
 while (reader.readPacket() == null)
   ;

Which I got from http ://wiki.xuggle.com/MediaTool_Introduction

If you want some fully working clojure code... here it is :)

(import '(com.xuggle.mediatool ToolFactory))
(import '(com.xuggle.mediatool IMediaDebugListener IMediaDebugListener$Event))

    (defn readerRecurse
      "calls .readPacket until there's nothing left to do2"
      [reader]
      (if (not (nil? (.readPacket reader))) ; here .readPacket actually does the processing as a side-effect.
        true                                   ; it returns null when it has MORE ro process, and signals an error when done... 
        (recur reader)))


    (defn convert
      "takes video and converts it to a new type of video"
      [videoInput videoOutput]
      (let [reader (ToolFactory/makeReader videoInput)]
        (doto reader
          (.addListener (ToolFactory/makeWriter videoOutput reader))
          (.addListener (ToolFactory/makeDebugListener (into-array [IMediaDebugListener$Event/META_DATA]))))
        (readerRecurse reader)))

now all you have to do is something like:

(convert "/path/to/some_file.stupid_extention" "/path/to/awesome.flv")

and you're done!

Robert McIntyre
A: 

You might also be interested in hearing that we've now released Panda as a hosted service as well, which makes the setup and scaling easier :)

http://pandastream.com

dctanner
A: 

yea, ffmpeg is the best for this work...We use ffmpeg to convert video for a long time and it works with all video formats..numerous options are there..

mahmudul hasan
A: 

Aunsoft Video Converter helps you convert between various formats. It is the must-have conversion tool for video lovers, and enables you to enjoy movies on computer, to further edit video for creation, to present video on HDTV, and to publish video online in web-friendly format. You can control your video and music on popular portable devices including iPad, Nexus One, HTC Hero, Zune, iPod, PSP, Apple TV, iPhone anytime anywhere.

With this powerful converter, you can also convert videos for video editing software like Adobe Premiere, Windows Movie Maker, Sony Vegas, and upload video to YouTube and MySpace to share videos.

http://www.aunsoft.com/video-converter/

carlalva01
A: 

I always use aHisoft Converter that can convert all videos and audios with video editing function. http://www.downloadvideos-convert.com This converter enables you to get rid of the useless part of the video/music video/ film/movie. You can cut the movie by setting the star time and end time. By setting the size of the movie, you can enjoy them with full screen on your portable device.