diff src/com/aurellem/capture/Capture.java @ 68:302d5e9ad120

adjust format
author Robert McIntyre <rlm@mit.edu>
date Thu, 19 Jul 2012 12:28:55 -0500
parents afc437f637bd
children 2c50a0c99715
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/Capture.java	Tue Feb 28 11:17:04 2012 -0600
     1.2 +++ b/src/com/aurellem/capture/Capture.java	Thu Jul 19 12:28:55 2012 -0500
     1.3 @@ -18,19 +18,21 @@
     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
     1.8 - * and audio from a jMonkeyEngine3 application.  To capture audio or video do
     1.9 - * the following:
    1.10 + * Use the methods in this class for capturing consistent,
    1.11 + * high quality video and audio from a jMonkeyEngine3
    1.12 + * application.  To capture audio or video do the following:
    1.13   * 
    1.14 - * 1.) Set your application's timer to an IsoTimer. Create the IsoTimer with the
    1.15 - *     desired video frames-per-second.
    1.16 + * 1.) Set your application's timer to an IsoTimer. Create
    1.17 + *     the IsoTimer with the desired video
    1.18 + *     frames-per-second.
    1.19   *
    1.20 - * 2.) Call captureAudio and/or captureVideo on the Application as desired
    1.21 - *     before starting the Application.
    1.22 + * 2.) Call captureAudio and/or captureVideo on the
    1.23 + *     Application as desired before starting the
    1.24 + *     Application.
    1.25   * 
    1.26 - * See the Basic and Advanced demos in the examples section for more
    1.27 - * information.  If you have any trouble, please PM me on the jMonkeyEngine
    1.28 - * forums.  My username is bortreb.
    1.29 + * See the Basic and Advanced demos in the examples section
    1.30 + * for more information.  If you have any trouble, please PM
    1.31 + * me on the jMonkeyEngine forums.  My username is bortreb.
    1.32   * 
    1.33   * @author Robert McIntyre
    1.34   */
    1.35 @@ -38,57 +40,69 @@
    1.36  public class Capture {
    1.37  
    1.38      /**
    1.39 -     * Use this function to capture video from your application.  You
    1.40 -     * specify the framerate at which the video will be recording by setting
    1.41 -     * the Application's timer to an IsoTimer created with the desired
    1.42 +     * Use this function to capture video from your
    1.43 +     * application.  You specify the framerate at which the
    1.44 +     * video will be recording by setting the Application's
    1.45 +     * timer to an IsoTimer created with the desired
    1.46       * frames-per-second.
    1.47       * 
    1.48 -     * There are three ways to record and they are selected by the
    1.49 -     * properties of the file that you specify.
    1.50 +     * There are three ways to record and they are selected
    1.51 +     * by the properties of the file that you specify.
    1.52       * 
    1.53 -     * 1.) (Preferred) If you supply an empty directory as the file, then
    1.54 -     *     the video will be saved as a sequence of .png files, one file per
    1.55 -     *     frame.  The files start at 0000000.png and increment from there.
    1.56 -     *     You can then combine the frames into your preferred
    1.57 -     *     container/codec. If the directory is not empty, then writing
    1.58 -     *     video frames to it will fail, and nothing will be written.
    1.59 +     * 1.) (Preferred) If you supply an empty directory as
    1.60 +     *     the file, then the video will be saved as a
    1.61 +     *     sequence of .png files, one file per frame.  The
    1.62 +     *     files start at 0000000.png and increment from
    1.63 +     *     there.  You can then combine the frames into your
    1.64 +     *     preferred container/codec. If the directory is
    1.65 +     *     not empty, then writing video frames to it will
    1.66 +     *     fail, and nothing will be written.
    1.67       *     
    1.68 -     * 2.) If the filename ends in ".avi" then the frames will be encoded as
    1.69 -     *     a RAW stream inside an AVI 1.0 container.  The resulting file
    1.70 -     *     will be quite large and you will probably want to re-encode it to
    1.71 -     *     your preferred container/codec format.  Be advised that some
    1.72 -     *     video payers cannot process AVI with a RAW stream, and that AVI
    1.73 -     *     1.0 files generated by this method that exceed 2.0GB are invalid
    1.74 -     *     according to the AVI 1.0 spec (but many programs can still deal
    1.75 -     *     with them.)  Thanks to Werner Randelshofer for his excellent work
    1.76 -     *     which made AVI file writer option possible.
    1.77 +     * 2.) If the filename ends in ".avi" then the frames
    1.78 +     *     will be encoded as a RAW stream inside an AVI 1.0
    1.79 +     *     container.  The resulting file will be quite
    1.80 +     *     large and you will probably want to re-encode it
    1.81 +     *     to your preferred container/codec format.  Be
    1.82 +     *     advised that some video payers cannot process AVI
    1.83 +     *     with a RAW stream, and that AVI 1.0 files
    1.84 +     *     generated by this method that exceed 2.0GB are
    1.85 +     *     invalid according to the AVI 1.0 spec (but many
    1.86 +     *     programs can still deal with them.)  Thanks to
    1.87 +     *     Werner Randelshofer for his excellent work which
    1.88 +     *     made AVI file writer option possible.
    1.89       *  
    1.90 -     * 3.) Any non-directory file ending in anything other than ".avi" will
    1.91 -     *     be processed through Xuggle.  Xuggle provides the option to use
    1.92 -     *     many codecs/containers, but you will have to install it on your
    1.93 -     *     system yourself in order to use this option. Please visit
    1.94 -     *     http://www.xuggle.com/ to learn how to do this.
    1.95 +     * 3.) Any non-directory file ending in anything other
    1.96 +     *     than ".avi" will be processed through Xuggle.
    1.97 +     *     Xuggle provides the option to use many
    1.98 +     *     codecs/containers, but you will have to install
    1.99 +     *     it on your system yourself in order to use this
   1.100 +     *     option. Please visit http://www.xuggle.com/ to
   1.101 +     *     learn how to do this.
   1.102       * 
   1.103       * @param app The Application from which you wish to record Video.
   1.104       * @param file The file to which the video will be captured. 
   1.105       * @throws IOException
   1.106       */
   1.107  	
   1.108 -    public static void captureVideo(final Application app, final File file) throws IOException{
   1.109 +    public static void captureVideo
   1.110 +	(final Application app, final File file) throws IOException{
   1.111  	final AbstractVideoRecorder videoRecorder;
   1.112  
   1.113  	if (file.getCanonicalPath().endsWith(".avi")){
   1.114  	    videoRecorder = new AVIVideoRecorder(file);}
   1.115  	else if (file.isDirectory()){
   1.116  	    videoRecorder = new FileVideoRecorder(file);}
   1.117 -	else { videoRecorder = new XuggleVideoRecorder(file);}
   1.118 +	else { 
   1.119 +	    videoRecorder = new XuggleVideoRecorder(file);
   1.120 +	}
   1.121  
   1.122  	Callable<Object> thunk = new Callable<Object>(){
   1.123  	    public Object call(){
   1.124  
   1.125  		ViewPort viewPort = 
   1.126  		app.getRenderManager()
   1.127 -		.createPostView("aurellem video record", app.getCamera());
   1.128 +		.createPostView("aurellem video record", 
   1.129 +				app.getCamera());
   1.130  
   1.131  		viewPort.setClearFlags(false, false, false);
   1.132  
   1.133 @@ -107,28 +121,34 @@
   1.134  
   1.135  
   1.136      /**
   1.137 -     * Use this function to capture audio from your application.  Audio data
   1.138 -     * will be saved in linear PCM format at 44,100 hertz in the wav container
   1.139 -     * format to the file that you specify.
   1.140 +     * Use this function to capture audio from your
   1.141 +     * application.  Audio data will be saved in linear PCM
   1.142 +     * format at 44,100 hertz in the wav container format to
   1.143 +     * the file that you specify.
   1.144       * 
   1.145 -     * Note that you *have* to use an IsoTimer for your Application's timer
   1.146 -     * while recording audio or the recording will fail. Also ensure that your
   1.147 -     * IsoTimer obeys the following constraints:
   1.148 +     * Note that you *have* to use an IsoTimer for your
   1.149 +     * Application's timer while recording audio or the
   1.150 +     * recording will fail. Also ensure that your IsoTimer
   1.151 +     * obeys the following constraints:
   1.152       * 
   1.153 -     *  1.) The frames-per-second value of the IsoTimer cannot be lower than 10
   1.154 -     *   frames-per-second.
   1.155 +     *  1.) The frames-per-second value of the IsoTimer
   1.156 +     *   cannot be lower than 10 frames-per-second.
   1.157       *
   1.158 -     *  2.) The frames-per-second value of the IsoTimer must evenly divide
   1.159 -     *   44,100.
   1.160 +     *  2.) The frames-per-second value of the IsoTimer must
   1.161 +     *   evenly divide 44,100.
   1.162       * 
   1.163 -     * @param app The Application from which you wish to record Audio.
   1.164 -     * @param file the target file to which you want to record audio data.
   1.165 +     * @param app The Application from which you wish to
   1.166 +     * record Audio.
   1.167 +     * @param file the target file to which you want to
   1.168 +     * record audio data.
   1.169       * @throws IOException
   1.170       */
   1.171  	
   1.172 -    public static void captureAudio(final Application app, final File file) throws IOException{
   1.173 +    public static void captureAudio
   1.174 +	(final Application app, final File file) throws IOException{
   1.175  	AppSettings settings = null;
   1.176 -	if (app.getContext() != null){settings = app.getContext().getSettings();}
   1.177 +	if (app.getContext() != null){
   1.178 +	    settings = app.getContext().getSettings();}
   1.179  	if (settings == null){settings = new AppSettings(true);}
   1.180  	settings.setAudioRenderer("Send");
   1.181  	app.setSettings(settings);