Writing AVI videos using pure Java
August 12th, 2008
Since writing QuickTime movies using pure Java turned out to be relatively easy, I gave today a try at an AVI encoder for PNG and Motion-JPEG encoded videos.
The AVIOuputStream class is freely available as part of my CubeTwister source code. You can download a small demo which only contains the AVIOutputStream and all necessary sources here: AVIDemo.jar. Running the demo will create a Motion JPEG-encoded and a PNG-encoded AVI video.
I am not sure, if AVI supports PNG-encoded videos at all, because Microsoft Media Player 11 can’t play them. The QuickTime player works fine with them though.
The source code is available under the terms of the Creative Commons Attribution 3.0 license.
Enjoy.
Update 2009-08-30: AVIOutputStream can now also write RAW-encoded video.
August 26th, 2008 at 5:35 pm
When I use the demo it creates the jpg avi and png avi (obviously), but when I use Windows Media Player and Media Player from Mega Codec, the playback is playing 1 frame (actually worse) per second…effectively it thinks the 3 second avi is 50 minutes long. Quicktime plays it in 3 seconds.
Do you know why that would be?
Thanks.
August 27th, 2008 at 7:04 am
Hi Mario,
You are right, the frame rate and time scale values are not computed properly. I had mixed up AVI “frame rate” with QuickTime “frame duration”.
I have fixed this now, and uploaded a new version.
It should play back now correctly in Windows Media Player as well.
Thanks,
Werner
October 1st, 2008 at 12:46 am
Thanks for this; I didn’t even realize AVI’s could be written with JPEG’s. This works great.
October 1st, 2008 at 6:02 am
Hi Jeremy,
Didn’t you mean “PNG’s”?
Because, I thought, I got the idea for writing JPEG’s into AVI from you.
March 8th, 2009 at 11:42 pm
I haven’t tried the class yet but I am sure that many Java developers out there really want this kind of functionality and it was pretty difficult to find
I develop Java games and I figured that this could be a nice way for players to generate in-game videos.
Thanks for developing this!
March 9th, 2009 at 8:14 am
Hi Per,
Just keep in mind that the video files may quickly become huge.
After generating an in-game video from Java (I highly recommend generating AVI-PNG or QuickTime-PNG), you may want to run it through an MPEG-4 H.264 baseline encoder. The final video will be very small, and look very crisp. Best thing is, it will work seamlessly with Flash, QuickTime, iPod/iPhone and Windows MediaPlayer.
July 4th, 2009 at 1:01 pm
Hi just wondering which H.264 encode you are using, I haven’t been able to convert the files using ffmpeg
Cheers
July 4th, 2009 at 2:53 pm
Hi Chris,
I use QuickTime Pro.
I just tried with ffmpeg. It works fine with the JPEG-encoded sample video, but it doesn’t support the PNG-encoded sample video.
I also tried ffmpeg with my QuickTime sample videos. Its the same here: JPEG-encoded video works, PNG-encoded video does not.
hth
January 5th, 2010 at 4:18 pm
Hello!
I just wanted to tell you that I have integrated your software into my game engine and it works great!
Do you plan to add audio as well?
If you don’t do it, I will eventually do it myself and you can get my code if you want to. I just have to read those RIFF specs first…
January 6th, 2010 at 5:04 pm
Hi Per,
Do you have a link to your game engine?
I have currently no need for audio support in AVIOutputStream.
If you add it to it, I would be very pleased to get your code.
Best,
Werner
January 6th, 2010 at 9:15 pm
The game engine/tool is currently under development, but I use your AVIOutputStream for every ingame Youtube video I make, except when the actual sound from the game is required. I will give you a link when I release my next game which will happen within 6 months (I hope
).
One huge benefit I get when I use your software is that I get very smooth videos which is sometimes not possible when I use external software such as Fraps, Taksi and CamStudio due to slowdowns.