Converting a series of images to a video in Java?

2019-02-07 14:50发布

问题:

Currently, the functioning prototype has everything it needs to work: A semi-transparent window for easy resizing on the place you want to record, multiple threads to manage screen shot taking, etc., but one last task I need it to do has eluded me for months. I need to convert all of the images I dumped in a folder I made called temp (that I delete after everything is done) into a movie.

I already have found this, but it is a standalone sort of thing you use in a shell. I need to just tweak it so that it just converts all the images (screencapture1.jpg, screencapture2.jpg, etc.) into a single movie.

Why can't I do this myself? Because I suck at understanding the work of other people, programming language-wise. I don't know why, but unless it's the simplest thing, I can never seem to understand it.

回答1:

I'd suggest just learning how to call external programs from your java program. Then you can just run that example program you linked to. Or if you want even more capability, use ffmpeg which will do this automatically from the command line as well:

ffmpeg -i screencapture%d.jpg -vcodec mpeg4 outfile.avi

ffmpeg allows you to customize a lot of things about the output video. Just check out the documentation for all the options.

The Java command Runtime.getRuntime().exec(...) will let you run whatever command line you pass it. There are many examples of how to do this if you Google it.



回答2:

I suggest to use Xuggler for this. Here's an introduction.