Converting a series of images to a video in Java?
Asked Answered
U

2

2

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.

Undone answered 21/5, 2010 at 0:12 Comment(0)
D
5

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.

Depositary answered 21/5, 2010 at 0:41 Comment(6)
Adding the FFmpeg library would multiply my application's size by over 300 times... =( Also, how do I use it? I'm not good with shells, but I know for certain I have to tell my shell where the FFmpeg library is before typing ffmpeg -i screencapture%d.jpg -vcodec mpeg4 outfile.avi will work.Undone
You may have to specify the full path. If in Windows, it may be something like Runtime.getRuntime().exec("C:\\Program Files\\ffmpeg\\ffmpeg.exe -i screencapture%d.jpg -vcodec mpeg4 outfile.avi"); replacing the path to your executable accordingly. I know this will increase your application size a lot, but it is pretty hard not to when you think about the capabilities you need. You need a JPEG decoder and an MPEG video encoder, both of which are quite complex. Also, you probably want it to be pretty fast. No matter what solution you use, it's going to take space.Depositary
Okay. Would it be possible to take out unnecessary parts of the FFmpeg library to shrink it down?Undone
Also, I don't see an ffmpeg.exe. I only see C files. I am also on a Mac, so I don't think a windows executable would work.Undone
Yeah, the ffmpeg site doesn't actually offer any compiled binaries. Windows and Linux versions are easy to find, but I have never searched for Mac OS versions. You can build your own, which shouldn't be too hard (although I've never done so for the Mac). See: stephenjungels.com/jungels.net/articles/ffmpeg-howto.html. Possibly a simpler option is to use the ffmpeg binary that is bundled with ffmpegX: ffmpegx.com. I don't know exactly where ffmpegX will install it to, but you should be able to do a search and find it.Depositary
Also, if you build your own ffmpeg executable from source, you may be able to reduce the size of the binary somewhat by disabling certain things. This is done when running the configure script.Depositary
M
2

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

Morita answered 21/5, 2010 at 0:23 Comment(1)
Is there a tutorial for the kind of thing I'm looking for? Thanks.Undone

© 2022 - 2024 — McMap. All rights reserved.