Mercurial > jmeCapture
view README @ 59:5afa49c5a7d3
adding wiki readme goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Dec 2011 22:14:21 -0600 |
parents | |
children | 42bbb176b90f |
line wrap: on
line source
1 ======Capture Audio/Video to a File======3 So you've made your cool new JMonkeyEngine3 game and you want to4 create a demo video to show off your hard work. Or maybe you want to5 make a cutscene for your game using the physics and characters in the6 game itself. Screen capturing is the most straightforward way to do7 this, but it can slow down your game and produce low-quality video and8 audio as a result. A better way is to record video and audio directly9 from the game while it is running.11 There's a full solution for doing this already made for you here:13 http://www.aurellem.com/releases/jmeCapture-latest.zip14 http://www.aurellem.com/releases/jmeCapture-latest.tar.bz216 Download the archive in your preferred format, extract,17 add the jars to your project, and you are ready to go.19 The javadoc is here:20 http://www.aurellem.com/jmeCapture/docs/22 Here is a complete example showing how to capture both audio and video23 from one of jMonkeyEngine3's advenced demo applications.25 <code java>26 import java.io.File;27 import java.io.IOException;29 import jme3test.water.TestPostWater;31 import com.aurellem.capture.Capture;32 import com.aurellem.capture.IsoTimer;33 import com.jme3.app.SimpleApplication;36 /**37 * Demonstrates how to use basic Audio/Video capture with a38 * jMonkeyEngine application. You can use these techniques to make39 * high quality cutscenes or demo videos, even on very slow laptops.40 *41 * @author Robert McIntyre42 */44 public class Basic {46 public static void main(String[] ignore) throws IOException{47 File video = File.createTempFile("JME-water-video", ".avi");48 File audio = File.createTempFile("JME-water-audio", ".wav");50 SimpleApplication app = new TestPostWater();51 app.setTimer(new IsoTimer(60));52 app.setShowSettings(false);54 Capture.captureVideo(app, video);55 Capture.captureAudio(app, audio);57 app.start();59 System.out.println(video.getCanonicalPath());60 System.out.println(audio.getCanonicalPath());61 }62 }63 </java>66 As you can see, to capture video and audio you use the67 ''com.aurellem.capture.Capture'' class, which has two methods,68 ''captureAudio'' and ''captureVideo'', and the69 ''com.aurellem.capture.IsoTimer class'', which sets the audio and70 video framerate.72 The steps are as simple as:74 <code java>75 yourApp.setTimer(new IsoTimer(desiredFramesPerSecond));76 </code>78 This causes jMonkeyEngine to take as much time as it needs to fully79 calculate every frame of the video and audio. You will see your game80 speed up and slow down depending on how computationally demanding your81 game is, but the final recorded audio and video will be perfectly82 sychronized and will run at exactly the fps which you specified.84 <code java>85 captureVideo(yourApp, targetVideoFile);86 captureAudio(yourApp, targetAudioFile);87 </code>89 These will cause the app to record audio and video when it is run.90 Audio and video will stop being recorded when the app stops. Your91 audio will be recorded as a 44,100 Hz linear PCM wav file, while the92 video will be recorded according to the following rules:94 1.) (Preferred) If you supply an empty directory as the file, then95 the video will be saved as a sequence of .png files, one file per96 frame. The files start at 0000000.png and increment from there.97 You can then combine the frames into your preferred98 container/codec. If the directory is not empty, then writing99 video frames to it will fail, and nothing will be written.101 2.) If the filename ends in ".avi" then the frames will be encoded as102 a RAW stream inside an AVI 1.0 container. The resulting file103 will be quite large and you will probably want to re-encode it to104 your preferred container/codec format. Be advised that some105 video payers cannot process AVI with a RAW stream, and that AVI106 1.0 files generated by this method that exceed 2.0GB are invalid107 according to the AVI 1.0 spec (but many programs can still deal108 with them.) Thanks to Werner Randelshofer for his excellent work109 which made AVI file writer option possible.111 3.) Any non-directory file ending in anything other than ".avi" will112 be processed through Xuggle. Xuggle provides the option to use113 many codecs/containers, but you will have to install it on your114 system yourself in order to use this option. Please visit115 http://www.xuggle.com/ to learn how to do this.