Mercurial > jmeCapture
comparison src/com/aurellem/capture/Capture.java @ 12:d10f4d4ff15a
going to improve documentation
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 27 Oct 2011 21:07:50 -0700 |
parents | 8a6b1684f536 |
children | 5f616cc420dd |
comparison
equal
deleted
inserted
replaced
11:8a6b1684f536 | 12:d10f4d4ff15a |
---|---|
1 package com.aurellem.capture; | 1 package com.aurellem.capture; |
2 | 2 |
3 import java.io.File; | 3 import java.io.File; |
4 import java.io.IOException; | 4 import java.io.IOException; |
5 import java.util.concurrent.Callable; | |
5 | 6 |
7 import com.aurellem.capture.audio.MultiListener; | |
8 import com.aurellem.capture.audio.WaveFileWriter; | |
6 import com.aurellem.capture.video.AVIVideoRecorder; | 9 import com.aurellem.capture.video.AVIVideoRecorder; |
7 import com.aurellem.capture.video.AbstractVideoRecorder; | 10 import com.aurellem.capture.video.AbstractVideoRecorder; |
8 import com.aurellem.capture.video.XuggleVideoRecorder; | 11 import com.aurellem.capture.video.XuggleVideoRecorder; |
9 import com.jme3.app.Application; | 12 import com.jme3.app.Application; |
10 import com.jme3.math.ColorRGBA; | 13 import com.jme3.audio.AudioRenderer; |
14 import com.jme3.renderer.ViewPort; | |
15 import com.jme3.scene.Spatial; | |
16 import com.jme3.system.AppSettings; | |
11 | 17 |
12 public class Capture { | 18 public class Capture { |
13 | 19 |
14 public static void SimpleCaptureVideo(Application app, File file) throws IOException{ | 20 public static void captureVideo(final Application app, final File file) throws IOException{ |
15 app.getViewPort().setClearFlags(true, true, true); | 21 |
16 // this prevents pixels from staying in the render buffer between frames | 22 final AbstractVideoRecorder videoRecorder; |
17 // and messing the video up. It's not a problem since Black is the default, and this | |
18 // can be overridden by user code. | |
19 app.getViewPort().setBackgroundColor(ColorRGBA.Black); | |
20 | |
21 // The XuggleVideoRecorder is better than the AVIVideoRecorder in every way | 23 // The XuggleVideoRecorder is better than the AVIVideoRecorder in every way |
22 // except for ease of installation. The excellent work by Werner Randelshofer | 24 // except for ease of installation. The excellent work by Werner Randelshofer |
23 // is used as a fallback option. Please visit http://www.xuggle.com/ to learn | 25 // is used as a fallback option. Please visit http://www.xuggle.com/ to learn |
24 // how to set up the XuggleVideoRecorder. | 26 // how to set up the XuggleVideoRecorder. |
27 | |
28 if (file.getCanonicalPath().endsWith(".avi")){ | |
29 videoRecorder = new AVIVideoRecorder(file);} | |
30 else { videoRecorder = new XuggleVideoRecorder(file);} | |
31 | |
32 Callable<Object> thunk = new Callable<Object>(){ | |
33 public Object call(){ | |
34 | |
35 ViewPort viewPort = | |
36 app.getRenderManager() | |
37 .createPostView("aurellem record", app.getCamera()); | |
38 | |
39 viewPort.setClearFlags(false, false, false); | |
40 | |
41 // get GUI node stuff | |
42 for (Spatial s : app.getGuiViewPort().getScenes()){ | |
43 viewPort.attachScene(s); | |
44 } | |
45 | |
46 app.getStateManager().attach(videoRecorder); | |
47 viewPort.addProcessor(videoRecorder); | |
48 return null; | |
49 } | |
50 }; | |
51 app.enqueue(thunk); | |
52 } | |
53 | |
54 | |
55 public static void captureAudio(final Application app, final File file) throws IOException{ | |
56 AppSettings settings = new AppSettings(true); | |
57 settings.setAudioRenderer("Send"); | |
58 app.setSettings(settings); | |
59 | |
60 Callable<Object> thunk = new Callable<Object>(){ | |
61 public Object call(){ | |
62 AudioRenderer ar = app.getAudioRenderer(); | |
63 if (ar instanceof MultiListener){ | |
64 MultiListener ml = (MultiListener)ar; | |
65 ml.registerSoundProcessor(new WaveFileWriter(file)); | |
66 } | |
67 return null; | |
68 } | |
69 }; | |
25 | 70 |
26 AbstractVideoRecorder videoRecorder; | 71 app.enqueue(thunk); |
27 | 72 } |
28 if (file.getCanonicalPath().endsWith(".avi")){ | 73 |
29 videoRecorder = new AVIVideoRecorder(file);} | |
30 else { videoRecorder = new XuggleVideoRecorder(file);} | |
31 | |
32 app.getStateManager().attach(videoRecorder); | |
33 app.getViewPort().addFinalProcessor(videoRecorder); | |
34 } | |
35 } | 74 } |