diff src/com/aurellem/capture/video/FileVideoRecorder.java @ 39:784a3f4e6202

updating capture-video
author Robert McIntyre <rlm@mit.edu>
date Thu, 03 Nov 2011 16:00:46 -0700
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/com/aurellem/capture/video/FileVideoRecorder.java	Thu Nov 03 16:00:46 2011 -0700
     1.3 @@ -0,0 +1,41 @@
     1.4 +package com.aurellem.capture.video;
     1.5 +
     1.6 +import java.awt.image.BufferedImage;
     1.7 +import java.io.File;
     1.8 +import java.io.IOException;
     1.9 +import javax.imageio.ImageIO;
    1.10 +
    1.11 +public  class FileVideoRecorder extends AbstractVideoRecorder{
    1.12 +    int current;
    1.13 +    File outDir;
    1.14 +    String formatName = "png";
    1.15 +	
    1.16 +    public FileVideoRecorder(File output) throws IOException {
    1.17 +	super(output);
    1.18 +	if (output.exists() 
    1.19 +	    && output.isDirectory() 
    1.20 +	    && (0 == output.listFiles().length)){
    1.21 +	    // good
    1.22 +	}
    1.23 +	else if (!output.exists()){
    1.24 +	    output.mkdir();
    1.25 +	}
    1.26 +	else {
    1.27 +	    throw new IOException("argument must be either an empty " + 
    1.28 +				  "directory or a nonexistent one.");
    1.29 +	}
    1.30 +	this.outDir = output;
    1.31 +    }
    1.32 +
    1.33 +    public void record(BufferedImage rawFrame) {
    1.34 +	String name = String.format("%07d.%s" , current++, formatName);
    1.35 +	File target = new File(output, name);
    1.36 +	try {ImageIO.write(rawFrame, formatName, target);}
    1.37 +	catch (IOException e) {e.printStackTrace();}
    1.38 +    }
    1.39 +
    1.40 +    public void finish() {}
    1.41 +}
    1.42 +
    1.43 +
    1.44 +