# HG changeset patch # User Robert McIntyre # Date 1322972061 21600 # Node ID 5afa49c5a7d3b45879036fa366eb62ec4701a5bc # Parent f2c5f1fca9a79c9aa75b2096be11e951a2ffdfa1 adding wiki readme goodness diff -r f2c5f1fca9a7 -r 5afa49c5a7d3 README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README Sat Dec 03 22:14:21 2011 -0600 @@ -0,0 +1,116 @@ +======Capture Audio/Video to a File====== + +So you've made your cool new JMonkeyEngine3 game and you want to +create a demo video to show off your hard work. Or maybe you want to +make a cutscene for your game using the physics and characters in the +game itself. Screen capturing is the most straightforward way to do +this, but it can slow down your game and produce low-quality video and +audio as a result. A better way is to record video and audio directly +from the game while it is running. + +There's a full solution for doing this already made for you here: + +http://www.aurellem.com/releases/jmeCapture-latest.zip +http://www.aurellem.com/releases/jmeCapture-latest.tar.bz2 + +Download the archive in your preferred format, extract, +add the jars to your project, and you are ready to go. + +The javadoc is here: +http://www.aurellem.com/jmeCapture/docs/ + +Here is a complete example showing how to capture both audio and video +from one of jMonkeyEngine3's advenced demo applications. + + +import java.io.File; +import java.io.IOException; + +import jme3test.water.TestPostWater; + +import com.aurellem.capture.Capture; +import com.aurellem.capture.IsoTimer; +import com.jme3.app.SimpleApplication; + + +/** + * Demonstrates how to use basic Audio/Video capture with a + * jMonkeyEngine application. You can use these techniques to make + * high quality cutscenes or demo videos, even on very slow laptops. + * + * @author Robert McIntyre + */ + +public class Basic { + + public static void main(String[] ignore) throws IOException{ + File video = File.createTempFile("JME-water-video", ".avi"); + File audio = File.createTempFile("JME-water-audio", ".wav"); + + SimpleApplication app = new TestPostWater(); + app.setTimer(new IsoTimer(60)); + app.setShowSettings(false); + + Capture.captureVideo(app, video); + Capture.captureAudio(app, audio); + + app.start(); + + System.out.println(video.getCanonicalPath()); + System.out.println(audio.getCanonicalPath()); + } +} + + + +As you can see, to capture video and audio you use the +''com.aurellem.capture.Capture'' class, which has two methods, +''captureAudio'' and ''captureVideo'', and the +''com.aurellem.capture.IsoTimer class'', which sets the audio and +video framerate. + +The steps are as simple as: + + +yourApp.setTimer(new IsoTimer(desiredFramesPerSecond)); + + +This causes jMonkeyEngine to take as much time as it needs to fully +calculate every frame of the video and audio. You will see your game +speed up and slow down depending on how computationally demanding your +game is, but the final recorded audio and video will be perfectly +sychronized and will run at exactly the fps which you specified. + + +captureVideo(yourApp, targetVideoFile); +captureAudio(yourApp, targetAudioFile); + + +These will cause the app to record audio and video when it is run. +Audio and video will stop being recorded when the app stops. Your +audio will be recorded as a 44,100 Hz linear PCM wav file, while the +video will be recorded according to the following rules: + +1.) (Preferred) If you supply an empty directory as the file, then + the video will be saved as a sequence of .png files, one file per + frame. The files start at 0000000.png and increment from there. + You can then combine the frames into your preferred + container/codec. If the directory is not empty, then writing + video frames to it will fail, and nothing will be written. + +2.) If the filename ends in ".avi" then the frames will be encoded as + a RAW stream inside an AVI 1.0 container. The resulting file + will be quite large and you will probably want to re-encode it to + your preferred container/codec format. Be advised that some + video payers cannot process AVI with a RAW stream, and that AVI + 1.0 files generated by this method that exceed 2.0GB are invalid + according to the AVI 1.0 spec (but many programs can still deal + with them.) Thanks to Werner Randelshofer for his excellent work + which made AVI file writer option possible. + +3.) Any non-directory file ending in anything other than ".avi" will + be processed through Xuggle. Xuggle provides the option to use + many codecs/containers, but you will have to install it on your + system yourself in order to use this option. Please visit + http://www.xuggle.com/ to learn how to do this. + diff -r f2c5f1fca9a7 -r 5afa49c5a7d3 src/com/aurellem/capture/IsoTimer.java --- a/src/com/aurellem/capture/IsoTimer.java Sat Dec 03 21:53:52 2011 -0600 +++ b/src/com/aurellem/capture/IsoTimer.java Sat Dec 03 22:14:21 2011 -0600 @@ -27,7 +27,7 @@ * the high-quality recording. If an Application uses this IsoTimer * instead of the normal one, we can be sure that every call to * simpleUpdate, for example, corresponds to exactly (1 / fps) seconds - * of game-time. This let's us record perfect video and audio even on + * of game-time. This lets us record perfect video and audio even on * a slow computer. * * @author Robert McIntyre