Mercurial > jmeCapture
comparison 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 |
comparison
equal
deleted
inserted
replaced
58:f2c5f1fca9a7 | 59:5afa49c5a7d3 |
---|---|
1 ======Capture Audio/Video to a File====== | |
2 | |
3 So you've made your cool new JMonkeyEngine3 game and you want to | |
4 create a demo video to show off your hard work. Or maybe you want to | |
5 make a cutscene for your game using the physics and characters in the | |
6 game itself. Screen capturing is the most straightforward way to do | |
7 this, but it can slow down your game and produce low-quality video and | |
8 audio as a result. A better way is to record video and audio directly | |
9 from the game while it is running. | |
10 | |
11 There's a full solution for doing this already made for you here: | |
12 | |
13 http://www.aurellem.com/releases/jmeCapture-latest.zip | |
14 http://www.aurellem.com/releases/jmeCapture-latest.tar.bz2 | |
15 | |
16 Download the archive in your preferred format, extract, | |
17 add the jars to your project, and you are ready to go. | |
18 | |
19 The javadoc is here: | |
20 http://www.aurellem.com/jmeCapture/docs/ | |
21 | |
22 Here is a complete example showing how to capture both audio and video | |
23 from one of jMonkeyEngine3's advenced demo applications. | |
24 | |
25 <code java> | |
26 import java.io.File; | |
27 import java.io.IOException; | |
28 | |
29 import jme3test.water.TestPostWater; | |
30 | |
31 import com.aurellem.capture.Capture; | |
32 import com.aurellem.capture.IsoTimer; | |
33 import com.jme3.app.SimpleApplication; | |
34 | |
35 | |
36 /** | |
37 * Demonstrates how to use basic Audio/Video capture with a | |
38 * jMonkeyEngine application. You can use these techniques to make | |
39 * high quality cutscenes or demo videos, even on very slow laptops. | |
40 * | |
41 * @author Robert McIntyre | |
42 */ | |
43 | |
44 public class Basic { | |
45 | |
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"); | |
49 | |
50 SimpleApplication app = new TestPostWater(); | |
51 app.setTimer(new IsoTimer(60)); | |
52 app.setShowSettings(false); | |
53 | |
54 Capture.captureVideo(app, video); | |
55 Capture.captureAudio(app, audio); | |
56 | |
57 app.start(); | |
58 | |
59 System.out.println(video.getCanonicalPath()); | |
60 System.out.println(audio.getCanonicalPath()); | |
61 } | |
62 } | |
63 </java> | |
64 | |
65 | |
66 As you can see, to capture video and audio you use the | |
67 ''com.aurellem.capture.Capture'' class, which has two methods, | |
68 ''captureAudio'' and ''captureVideo'', and the | |
69 ''com.aurellem.capture.IsoTimer class'', which sets the audio and | |
70 video framerate. | |
71 | |
72 The steps are as simple as: | |
73 | |
74 <code java> | |
75 yourApp.setTimer(new IsoTimer(desiredFramesPerSecond)); | |
76 </code> | |
77 | |
78 This causes jMonkeyEngine to take as much time as it needs to fully | |
79 calculate every frame of the video and audio. You will see your game | |
80 speed up and slow down depending on how computationally demanding your | |
81 game is, but the final recorded audio and video will be perfectly | |
82 sychronized and will run at exactly the fps which you specified. | |
83 | |
84 <code java> | |
85 captureVideo(yourApp, targetVideoFile); | |
86 captureAudio(yourApp, targetAudioFile); | |
87 </code> | |
88 | |
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. Your | |
91 audio will be recorded as a 44,100 Hz linear PCM wav file, while the | |
92 video will be recorded according to the following rules: | |
93 | |
94 1.) (Preferred) If you supply an empty directory as the file, then | |
95 the video will be saved as a sequence of .png files, one file per | |
96 frame. The files start at 0000000.png and increment from there. | |
97 You can then combine the frames into your preferred | |
98 container/codec. If the directory is not empty, then writing | |
99 video frames to it will fail, and nothing will be written. | |
100 | |
101 2.) If the filename ends in ".avi" then the frames will be encoded as | |
102 a RAW stream inside an AVI 1.0 container. The resulting file | |
103 will be quite large and you will probably want to re-encode it to | |
104 your preferred container/codec format. Be advised that some | |
105 video payers cannot process AVI with a RAW stream, and that AVI | |
106 1.0 files generated by this method that exceed 2.0GB are invalid | |
107 according to the AVI 1.0 spec (but many programs can still deal | |
108 with them.) Thanks to Werner Randelshofer for his excellent work | |
109 which made AVI file writer option possible. | |
110 | |
111 3.) Any non-directory file ending in anything other than ".avi" will | |
112 be processed through Xuggle. Xuggle provides the option to use | |
113 many codecs/containers, but you will have to install it on your | |
114 system yourself in order to use this option. Please visit | |
115 http://www.xuggle.com/ to learn how to do this. | |
116 |