diff src/com/aurellem/capture/Capture.java @ 56:afc437f637bd

improved formating
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Dec 2011 19:25:27 -0600
parents b05f629fc296
children 302d5e9ad120
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/Capture.java	Sat Dec 03 19:18:38 2011 -0600
     1.2 +++ b/src/com/aurellem/capture/Capture.java	Sat Dec 03 19:25:27 2011 -0600
     1.3 @@ -18,122 +18,135 @@
     1.4  import com.jme3.system.JmeSystem;
     1.5  
     1.6  /**
     1.7 - * Use the methods in this class for capturing consistent, high quality video and audio from a 
     1.8 - * jMonkeyEngine3 application.  To capture audio or video do the following:
     1.9 + * Use the methods in this class for capturing consistent, high quality video
    1.10 + * and audio from a jMonkeyEngine3 application.  To capture audio or video do
    1.11 + * the following:
    1.12   * 
    1.13 - * 1.) Set your application's timer to an IsoTimer. Create the IsoTimer with the desired video
    1.14 - *     frames-per-second.
    1.15 - * 2.) Call captureAudio and/or captureVideo on the Application as desired before starting the Application.
    1.16 + * 1.) Set your application's timer to an IsoTimer. Create the IsoTimer with the
    1.17 + *     desired video frames-per-second.
    1.18 + *
    1.19 + * 2.) Call captureAudio and/or captureVideo on the Application as desired
    1.20 + *     before starting the Application.
    1.21   * 
    1.22 - * See the Basic and Advanced demos in the examples section for more information.  If you have any trouble, 
    1.23 - * please PM me on the jMonkeyEngine forums.  My username is bortreb.
    1.24 + * See the Basic and Advanced demos in the examples section for more
    1.25 + * information.  If you have any trouble, please PM me on the jMonkeyEngine
    1.26 + * forums.  My username is bortreb.
    1.27   * 
    1.28   * @author Robert McIntyre
    1.29   */
    1.30  
    1.31  public class Capture {
    1.32  
    1.33 -	/**
    1.34 -	 * Use this function to capture video from your application.  You specify the framerate at which
    1.35 -	 * the video will be recording by setting the Application's timer to an IsoTimer created with the 
    1.36 -	 * desired frames-per-second. 
    1.37 -	 * 
    1.38 -	 * There are three ways to record and they are selected by the properties of the file that you 
    1.39 -	 * specify.
    1.40 -	 * 
    1.41 -	 * 1.) (Preferred)
    1.42 -	 *     If you supply an empty directory as the file, then the video will
    1.43 -	 *     be saved as a sequence of .png files, one file per frame.  The files start at
    1.44 -	 *     0000000.png and increment from there.  You can then combine the frames into your  
    1.45 -	 *     preferred container/codec. If the directory is not empty, then writing video frames
    1.46 -	 *     to it will fail, and nothing will be written.
    1.47 -	 *     
    1.48 -	 * 2.) If the filename ends in ".avi" then the frames will be encoded as a RAW stream
    1.49 -	 *     inside an AVI 1.0 container.  The resulting file will be quite large and you will
    1.50 -	 *     probably want to re-encode it to your preferred container/codec format.  Be advised
    1.51 -	 *     that some video payers cannot process AVI with a RAW stream, and that AVI 1.0 files
    1.52 -	 *     generated by this method that exceed 2.0GB are invalid according to the AVI 1.0 spec
    1.53 -	 *     (but many programs can still deal with them.)  Thanks to Werner Randelshofer for his 
    1.54 -	 *     excellent work which made AVI file writer option possible.
    1.55 -	 *  
    1.56 -	 * 3.) Any non-directory file ending in anything other than ".avi" will be processed through 
    1.57 -	 *     Xuggle.  Xuggle provides the option to use many codecs/containers, but you will have to 
    1.58 -	 *     install it on your system yourself in order to use this option. Please visit 
    1.59 -	 *     http://www.xuggle.com/ to learn how to do this.
    1.60 -	 * 
    1.61 -	 * @param app The Application from which you wish to record Video.
    1.62 -	 * @param file The file to which the video will be captured. 
    1.63 -	 * @throws IOException
    1.64 -	 */
    1.65 +    /**
    1.66 +     * Use this function to capture video from your application.  You
    1.67 +     * specify the framerate at which the video will be recording by setting
    1.68 +     * the Application's timer to an IsoTimer created with the desired
    1.69 +     * frames-per-second.
    1.70 +     * 
    1.71 +     * There are three ways to record and they are selected by the
    1.72 +     * properties of the file that you specify.
    1.73 +     * 
    1.74 +     * 1.) (Preferred) If you supply an empty directory as the file, then
    1.75 +     *     the video will be saved as a sequence of .png files, one file per
    1.76 +     *     frame.  The files start at 0000000.png and increment from there.
    1.77 +     *     You can then combine the frames into your preferred
    1.78 +     *     container/codec. If the directory is not empty, then writing
    1.79 +     *     video frames to it will fail, and nothing will be written.
    1.80 +     *     
    1.81 +     * 2.) If the filename ends in ".avi" then the frames will be encoded as
    1.82 +     *     a RAW stream inside an AVI 1.0 container.  The resulting file
    1.83 +     *     will be quite large and you will probably want to re-encode it to
    1.84 +     *     your preferred container/codec format.  Be advised that some
    1.85 +     *     video payers cannot process AVI with a RAW stream, and that AVI
    1.86 +     *     1.0 files generated by this method that exceed 2.0GB are invalid
    1.87 +     *     according to the AVI 1.0 spec (but many programs can still deal
    1.88 +     *     with them.)  Thanks to Werner Randelshofer for his excellent work
    1.89 +     *     which made AVI file writer option possible.
    1.90 +     *  
    1.91 +     * 3.) Any non-directory file ending in anything other than ".avi" will
    1.92 +     *     be processed through Xuggle.  Xuggle provides the option to use
    1.93 +     *     many codecs/containers, but you will have to install it on your
    1.94 +     *     system yourself in order to use this option. Please visit
    1.95 +     *     http://www.xuggle.com/ to learn how to do this.
    1.96 +     * 
    1.97 +     * @param app The Application from which you wish to record Video.
    1.98 +     * @param file The file to which the video will be captured. 
    1.99 +     * @throws IOException
   1.100 +     */
   1.101  	
   1.102 -	public static void captureVideo(final Application app, final File file) throws IOException{
   1.103 -		final AbstractVideoRecorder videoRecorder;
   1.104 +    public static void captureVideo(final Application app, final File file) throws IOException{
   1.105 +	final AbstractVideoRecorder videoRecorder;
   1.106  
   1.107 -		if (file.getCanonicalPath().endsWith(".avi")){
   1.108 -			videoRecorder = new AVIVideoRecorder(file);}
   1.109 -		else if (file.isDirectory()){
   1.110 -			videoRecorder = new FileVideoRecorder(file);}
   1.111 -		else { videoRecorder = new XuggleVideoRecorder(file);}
   1.112 +	if (file.getCanonicalPath().endsWith(".avi")){
   1.113 +	    videoRecorder = new AVIVideoRecorder(file);}
   1.114 +	else if (file.isDirectory()){
   1.115 +	    videoRecorder = new FileVideoRecorder(file);}
   1.116 +	else { videoRecorder = new XuggleVideoRecorder(file);}
   1.117  
   1.118 -		Callable<Object> thunk = new Callable<Object>(){
   1.119 -			public Object call(){
   1.120 +	Callable<Object> thunk = new Callable<Object>(){
   1.121 +	    public Object call(){
   1.122  
   1.123 -				ViewPort viewPort = 
   1.124 -						app.getRenderManager()
   1.125 -						.createPostView("aurellem video record", app.getCamera());
   1.126 +		ViewPort viewPort = 
   1.127 +		app.getRenderManager()
   1.128 +		.createPostView("aurellem video record", app.getCamera());
   1.129  
   1.130 -				viewPort.setClearFlags(false, false, false);
   1.131 +		viewPort.setClearFlags(false, false, false);
   1.132  
   1.133 -				// get GUI node stuff
   1.134 -				for (Spatial s : app.getGuiViewPort().getScenes()){
   1.135 -					viewPort.attachScene(s);
   1.136 -				}
   1.137 +		// get GUI node stuff
   1.138 +		for (Spatial s : app.getGuiViewPort().getScenes()){
   1.139 +		    viewPort.attachScene(s);
   1.140 +		}
   1.141  
   1.142 -				app.getStateManager().attach(videoRecorder);
   1.143 -				viewPort.addProcessor(videoRecorder);
   1.144 -				return null;
   1.145 -			}
   1.146 -		};
   1.147 -		app.enqueue(thunk);
   1.148 -	}
   1.149 +		app.getStateManager().attach(videoRecorder);
   1.150 +		viewPort.addProcessor(videoRecorder);
   1.151 +		return null;
   1.152 +	    }
   1.153 +	};
   1.154 +	app.enqueue(thunk);
   1.155 +    }
   1.156  
   1.157  
   1.158 -	/**
   1.159 -	 * Use this function to capture audio from your application.  Audio data will be saved in linear
   1.160 -	 * PCM format at 44,100 hertz in the wav container format to the file that you specify.  
   1.161 -	 * 
   1.162 -	 * Note that you *have* to use an IsoTimer for your Application's timer while recording audio or 
   1.163 -	 * the recording will fail. Also ensure that your IsoTimer obeys the following constraints: 
   1.164 -	 * 
   1.165 -	 *  - The frames-per-second value of the IsoTimer cannot be lower than 10 frames-per-second.
   1.166 -	 *  - The frames-per-second value of the IsoTimer must evenly divide 44,100.  
   1.167 -	 * 
   1.168 -	 * @param app The Application from which you wish to record Audio.
   1.169 -	 * @param file the target file to which you want to record audio data.
   1.170 -	 * @throws IOException
   1.171 -	 */
   1.172 +    /**
   1.173 +     * Use this function to capture audio from your application.  Audio data
   1.174 +     * will be saved in linear PCM format at 44,100 hertz in the wav container
   1.175 +     * format to the file that you specify.
   1.176 +     * 
   1.177 +     * Note that you *have* to use an IsoTimer for your Application's timer
   1.178 +     * while recording audio or the recording will fail. Also ensure that your
   1.179 +     * IsoTimer obeys the following constraints:
   1.180 +     * 
   1.181 +     *  1.) The frames-per-second value of the IsoTimer cannot be lower than 10
   1.182 +     *   frames-per-second.
   1.183 +     *
   1.184 +     *  2.) The frames-per-second value of the IsoTimer must evenly divide
   1.185 +     *   44,100.
   1.186 +     * 
   1.187 +     * @param app The Application from which you wish to record Audio.
   1.188 +     * @param file the target file to which you want to record audio data.
   1.189 +     * @throws IOException
   1.190 +     */
   1.191  	
   1.192 -	public static void captureAudio(final Application app, final File file) throws IOException{
   1.193 -		AppSettings settings = null;
   1.194 -		if (app.getContext() != null){settings = app.getContext().getSettings();}
   1.195 -		if (settings == null){settings = new AppSettings(true);}
   1.196 -		settings.setAudioRenderer("Send");
   1.197 -		app.setSettings(settings);
   1.198 +    public static void captureAudio(final Application app, final File file) throws IOException{
   1.199 +	AppSettings settings = null;
   1.200 +	if (app.getContext() != null){settings = app.getContext().getSettings();}
   1.201 +	if (settings == null){settings = new AppSettings(true);}
   1.202 +	settings.setAudioRenderer("Send");
   1.203 +	app.setSettings(settings);
   1.204  
   1.205 -		JmeSystem.setSystemDelegate(new AurellemSystemDelegate());
   1.206 +	JmeSystem.setSystemDelegate(new AurellemSystemDelegate());
   1.207  		
   1.208 -		final WaveFileWriter writer = new WaveFileWriter(file);
   1.209 +	final WaveFileWriter writer = new WaveFileWriter(file);
   1.210  
   1.211 -		Callable<Object> thunk = new Callable<Object>(){
   1.212 -			public Object call(){
   1.213 -				AudioRenderer ar = app.getAudioRenderer();
   1.214 -				if (ar instanceof MultiListener){
   1.215 -					MultiListener ml = (MultiListener)ar;
   1.216 -					ml.registerSoundProcessor(writer);
   1.217 -				}
   1.218 -				return null;
   1.219 -			}
   1.220 -		};
   1.221 -		app.enqueue(thunk);
   1.222 -	}		
   1.223 +	Callable<Object> thunk = new Callable<Object>(){
   1.224 +	    public Object call(){
   1.225 +		AudioRenderer ar = app.getAudioRenderer();
   1.226 +		if (ar instanceof MultiListener){
   1.227 +		    MultiListener ml = (MultiListener)ar;
   1.228 +		    ml.registerSoundProcessor(writer);
   1.229 +		}
   1.230 +		return null;
   1.231 +	    }
   1.232 +	};
   1.233 +	app.enqueue(thunk);
   1.234 +    }		
   1.235  }