rlm@3
|
1 package com.aurellem.capture;
|
rlm@3
|
2
|
rlm@3
|
3 import java.io.File;
|
rlm@3
|
4 import java.io.IOException;
|
rlm@12
|
5 import java.util.concurrent.Callable;
|
rlm@3
|
6
|
rlm@12
|
7 import com.aurellem.capture.audio.MultiListener;
|
rlm@12
|
8 import com.aurellem.capture.audio.WaveFileWriter;
|
rlm@9
|
9 import com.aurellem.capture.video.AVIVideoRecorder;
|
rlm@10
|
10 import com.aurellem.capture.video.AbstractVideoRecorder;
|
rlm@39
|
11 import com.aurellem.capture.video.FileVideoRecorder;
|
rlm@10
|
12 import com.aurellem.capture.video.XuggleVideoRecorder;
|
rlm@3
|
13 import com.jme3.app.Application;
|
rlm@12
|
14 import com.jme3.audio.AudioRenderer;
|
rlm@12
|
15 import com.jme3.renderer.ViewPort;
|
rlm@12
|
16 import com.jme3.scene.Spatial;
|
rlm@49
|
17 import com.jme3.system.AppSettings;
|
rlm@44
|
18 import com.jme3.system.JmeSystem;
|
rlm@3
|
19
|
rlm@53
|
20 /**
|
rlm@53
|
21 *
|
rlm@53
|
22 * @author Robert McIntyre
|
rlm@53
|
23 *
|
rlm@53
|
24 */
|
rlm@53
|
25
|
rlm@3
|
26 public class Capture {
|
rlm@3
|
27
|
rlm@12
|
28 public static void captureVideo(final Application app, final File file) throws IOException{
|
rlm@12
|
29
|
rlm@12
|
30 final AbstractVideoRecorder videoRecorder;
|
rlm@10
|
31 // The XuggleVideoRecorder is better than the AVIVideoRecorder in every way
|
rlm@10
|
32 // except for ease of installation. The excellent work by Werner Randelshofer
|
rlm@10
|
33 // is used as a fallback option. Please visit http://www.xuggle.com/ to learn
|
rlm@10
|
34 // how to set up the XuggleVideoRecorder.
|
rlm@12
|
35
|
rlm@12
|
36 if (file.getCanonicalPath().endsWith(".avi")){
|
rlm@12
|
37 videoRecorder = new AVIVideoRecorder(file);}
|
rlm@39
|
38 else if (file.isDirectory()){
|
rlm@39
|
39 videoRecorder = new FileVideoRecorder(file);}
|
rlm@12
|
40 else { videoRecorder = new XuggleVideoRecorder(file);}
|
rlm@12
|
41
|
rlm@12
|
42 Callable<Object> thunk = new Callable<Object>(){
|
rlm@12
|
43 public Object call(){
|
rlm@12
|
44
|
rlm@12
|
45 ViewPort viewPort =
|
rlm@12
|
46 app.getRenderManager()
|
rlm@49
|
47 .createPostView("aurellem video record", app.getCamera());
|
rlm@12
|
48
|
rlm@12
|
49 viewPort.setClearFlags(false, false, false);
|
rlm@12
|
50
|
rlm@12
|
51 // get GUI node stuff
|
rlm@12
|
52 for (Spatial s : app.getGuiViewPort().getScenes()){
|
rlm@12
|
53 viewPort.attachScene(s);
|
rlm@12
|
54 }
|
rlm@12
|
55
|
rlm@12
|
56 app.getStateManager().attach(videoRecorder);
|
rlm@12
|
57 viewPort.addProcessor(videoRecorder);
|
rlm@12
|
58 return null;
|
rlm@12
|
59 }
|
rlm@12
|
60 };
|
rlm@12
|
61 app.enqueue(thunk);
|
rlm@12
|
62 }
|
rlm@12
|
63
|
rlm@12
|
64
|
rlm@12
|
65 public static void captureAudio(final Application app, final File file) throws IOException{
|
rlm@49
|
66 AppSettings settings = null;
|
rlm@49
|
67 if (app.getContext() != null){settings = app.getContext().getSettings();}
|
rlm@49
|
68 if (settings == null){settings = new AppSettings(true);}
|
rlm@49
|
69 settings.setAudioRenderer("Send");
|
rlm@49
|
70 app.setSettings(settings);
|
rlm@49
|
71
|
rlm@44
|
72 JmeSystem.setSystemDelegate(new AurellemSystemDelegate());
|
rlm@44
|
73
|
rlm@49
|
74
|
rlm@24
|
75 final WaveFileWriter writer = new WaveFileWriter(file);
|
rlm@12
|
76
|
rlm@12
|
77 Callable<Object> thunk = new Callable<Object>(){
|
rlm@12
|
78 public Object call(){
|
rlm@12
|
79 AudioRenderer ar = app.getAudioRenderer();
|
rlm@12
|
80 if (ar instanceof MultiListener){
|
rlm@12
|
81 MultiListener ml = (MultiListener)ar;
|
rlm@24
|
82 ml.registerSoundProcessor(writer);
|
rlm@12
|
83 }
|
rlm@12
|
84 return null;
|
rlm@12
|
85 }
|
rlm@12
|
86 };
|
rlm@10
|
87
|
rlm@12
|
88 app.enqueue(thunk);
|
rlm@49
|
89 }
|
rlm@3
|
90 }
|