Java Forum / General / January 2006
Create movies in Java
Ross Clement (Email address invalid - do not use) - 01 Jan 2006 19:06 GMT Hi. I would like to be able to create movie files from inside Java. I would like to draw the movie frame by frame using standard Java graphics and image classes, then write it out to an external file. I would then use external tools such as ffmpeg to compress/reformat/add audio to the movie, so the format by which it would be written from Java is not that important.
I presume this is possible, but can't find any sample code or tutorials. I can find huge numbers of tutorials about how to play back movie files in Java, some on transcoding etc., but nothing on authoring.
Any hints/pointers?
Thanks in anticipation,
Ross-c
Bruce Lee - 01 Jan 2006 22:50 GMT > Hi. I would like to be able to create movie files from inside Java. I > would like to draw the movie frame by frame using standard Java [quoted text clipped - 13 lines] > > Ross-c google "java jmf"
Andrew Thompson - 04 Jan 2006 02:34 GMT >>Hi. I would like to be able to create movie files from inside Java. ...
> google "java jmf" There is a sample app. that comes with the JMF called.. 'JpegImagesToMovie' to convert a series of .jpg files to Quicktime .mov format.
It has come in quite handy here, allowing me to create time-lapse animations from any series of pictures. [ I then (am currently) use ImTOO Avi/Mpeg Converter to change the .mov to .mpg format, though it sounds as if you have that side covered. ]
For simple examples of dealing with images, check the code samples available on Marco Shmidt's site, here.. <http://schmidt.devlib.org/java/image-file-code-examples.html>
HTH
 Signature Andrew Thompson physci, javasaver, 1point1c, lensescapes - athompson.info/andrew
Ross Clement (Email address invalid - do not use) - 04 Jan 2006 10:50 GMT Thanks for the feedback. I've downloaded the source to JpegImagesToMovie.java and it *should* be easy for me to adapt it for my needs. As the movies I will be creating are very large (1/4 hour to 1 hour) I think that it won't be feasible to dump an image sequence and convert, so I'll be hacking the code to store directly as quicktime.
Cheers,
Ross-c
Andrew Thompson - 04 Jan 2006 11:06 GMT > Thanks for the feedback. I've downloaded the source to > JpegImagesToMovie.java and it *should* be easy for me to adapt it for > my needs. As the movies I will be creating are very large (1/4 hour to > 1 hour) I think that it won't be feasible to dump an image sequence and > convert, so I'll be hacking the code to store directly as quicktime. You might be right, that is much longer than the 61-62 second anims. I've done, but OTOH they are at 2304x1728 px and end up around a 1/4 Gig in size!. I'd recommend testing it first. [ There are also command line args. you can use to increase the memory available to a Java process. ]
..ohh, but I did hack the JITM source myself to accept a directory, and simply add all .jpg files in name order - I was not about to specify 300-600 image names on the command line! ;-)
 Signature Andrew Thompson physci, javasaver, 1point1c, lensescapes - athompson.info/andrew
opalpa@gmail.com - 04 Jan 2006 15:22 GMT Here are a couple of things I learned doing this deed -- making BufferedImage instances and then sequencing them into a Quicktime movie:
# It's not all that easy. One thing that will be frustrating is that the Processor is asychronous. That is you cannot loop through your images and pass each image to the processor. You'll have to use the asynch calls and call backs. From the perspective of making movies from BufferedImage instances this seems like an idiocy. The explanation is that JMF is intended for playback. With that in mind things like asynchronicity are standard in video packages. If you're not comfortable with wait() and notify() methods that are part of Object you'll feel some frustration, I anticipate.
# I have had all kinds of exceptions when trying to simulatenously read multiple movies with JMF. I guess they use some file statics. Anyway the JMF is a little away from a robust system.
# The movies are big!
Cool stuff is possible. Here is a program I made: given a google query go out to web and query google. For all links on first page of results get the content of each of the webpages. After getting the content of each of the pages find all image links. For image links that appear to be content (instead of spacers, buttons, etc) combine them ihnto the movie. It's kind of fun to pick something "juggling midgets", "warner brothers cartoons", "big tits" and get a Quicktime movie.
I also made some stuff where I render images, like a countdown, and generate a Quicktime mov that I can put into video productions.
opalpa@gmail.com http://www.geocities.com/opalpaweb/
Roedy Green - 04 Jan 2006 17:38 GMT >Here are a couple of things I learned doing this deed -- making >BufferedImage instances and then sequencing them into a Quicktime >movie: Here is one problem you may run into that I had with a streaming protocol for JPG images. When the compressor does each image, it compresses it in isolation from the other images. It is happy to get the colours just a tad off. However, it gets them a tad off on each frame in a slightly different way. If you look at a series, you don't gave consistent colours. This is acceptable for a security camera, but may not be for advertising.
To solve that you would have to start from something with accurate colours, maybe giant TIFFs. and somehow compress them in a consistent way frame to frame. MP3 encoders likely know how to handle this.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Oliver Wong - 10 Jan 2006 21:10 GMT >>Here are a couple of things I learned doing this deed -- making >>BufferedImage instances and then sequencing them into a Quicktime [quoted text clipped - 11 lines] > colours, maybe giant TIFFs. and somehow compress them in a consistent > way frame to frame. MP3 encoders likely know how to handle this. As long as your image format is lossless, you shouldn't have any problems with compression artefacts. PNG, BMP, etc. would work just as well as TIFF.
You should probably leave the compressing to the codecs, rather than "doing it yourself". In fact, if you try to do your own compression, and then pass it to a codec, you may make the codec's job harder, particularly if your compression is lossy. The codec won't be able to tell what are artefacts introduced via lossy compression, and what is significant detail to reproduce in the video stream.
- Oliver
opalpa@gmail.com - 04 Jan 2006 15:23 GMT Here are a couple of things I learned doing this deed -- making BufferedImage instances and then sequencing them into a Quicktime movie:
# It's not all that easy. One thing that will be frustrating is that the Processor is asychronous. That is you cannot loop through your images and pass each image to the processor. You'll have to use the asynch calls and call backs. From the perspective of making movies from BufferedImage instances this seems like an idiocy. The explanation is that JMF is intended for playback. With that in mind things like asynchronicity are standard in video packages. If you're not comfortable with wait() and notify() methods that are part of Object you'll feel some frustration, I anticipate.
# I have had all kinds of exceptions when trying to simulatenously read multiple movies with JMF. I guess they use some file statics. Anyway the JMF is a little away from a robust system.
# The movies are big!
Cool stuff is possible. Here is a program I made: given a google query go out to web and query google. For all links on first page of results get the content of each of the webpages. After getting the content of each of the pages find all image links. For image links that appear to be content (instead of spacers, buttons, etc) combine them ihnto the movie. It's kind of fun to pick something "juggling midgets", "warner brothers cartoons", "big tits" and get a Quicktime movie.
I also made some stuff where I render images, like a countdown, and generate a Quicktime mov that I can put into video productions.
opalpa@gmail.com http://www.geocities.com/opalpaweb/
Ross Clement (Email address invalid - do not use) - 04 Jan 2006 23:23 GMT Thanks to everyone who replied on this thread.
I have hacked a modified version of the JpegImagesToMovie code into my program. Provided that I encode (using Sun's JPEGImageEncoder class) by images (BufferedImage) as JPEGs before returning them as output from my PullBufferStream.read( ) method, then I get a good QuickTime movie as output that I can play using mplayer and reformat using ffmpeg.
However, I tried to avoid converting my images to JPEGs first by using RGBFormat. After some trial and error hacking, I made the code write a quicktime file. However when I tried to play it back, the programs didn't like the movie and refused to do anything with it.
My application is a very primitive "electronic whiteboard" type program. I basically record a stream of mouse movements (actually pens on a touch-screen enabled plasma screen) and can play them back. I wanted to be able to dump the result as a movie for mixing with the sound I record of me talking while writing. So visual quality isn't a massive problem provided that people can read what I am writing. However, I can see the "jpegginess" of the image even in the original not very compressed movie. I'm going to try setting the JPEG quality higher than the default (whatever that was) and see if that helps.
But, if possible, I would like to remove the conversion to JPEG intermediate step. Can anyone recommend an alternative format I could use, or point me to any references on how I can get the RGB format to work?
Cheers,
Ross-c
Ross Clement (Email address invalid - do not use) - 04 Jan 2006 23:29 GMT PS: Setting the quality of the JPEGEncoder object to 1.0 improved things considerably. But I would still like to know how to avoid encoding to a JPEG.
Cheers,
Ross-c
opalpa@gmail.com - 05 Jan 2006 01:27 GMT Skip jpeg by specifing RGBFormat, convert BufferedImage to Buffer with javax.media.util.ImageToBuffer.createBuffer, set descriptor to ContentDescriptor.RAW.
Cheers,
http://www.geocities.com/opalpaweb/
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|