annotate src/com/aurellem/capture/video/AVIVideoRecorder.java @ 11:8a6b1684f536

refactored.
author Robert McIntyre <rlm@mit.edu>
date Thu, 27 Oct 2011 02:27:02 -0700
parents 4c5fc53778c1
children be5ac56826be
rev   line source
rlm@9 1 package com.aurellem.capture.video;
rlm@9 2
rlm@9 3 import java.awt.image.BufferedImage;
rlm@9 4 import java.io.File;
rlm@9 5 import java.io.IOException;
rlm@9 6
rlm@10 7 import ca.randelshofer.AVIOutputStream;
rlm@10 8
rlm@9 9
rlm@9 10 public class AVIVideoRecorder extends AbstractVideoRecorder{
rlm@9 11
rlm@9 12 AVIOutputStream out = null;
rlm@9 13 boolean videoReady = false;
rlm@9 14 BufferedImage frame;
rlm@9 15
rlm@9 16 public AVIVideoRecorder(File output) throws IOException {
rlm@9 17 super(output);
rlm@9 18 this.out = new AVIOutputStream(output, AVIOutputStream.VideoFormat.PNG, 24);
rlm@9 19 this.out.setVideoCompressionQuality(1.0f);
rlm@9 20 }
rlm@9 21
rlm@9 22
rlm@9 23 public void initVideo (){
rlm@9 24 frame = new BufferedImage(
rlm@9 25 width, height,
rlm@9 26 BufferedImage.TYPE_INT_RGB);
rlm@9 27 out.setFrameRate((int) Math.round(this.fps));
rlm@9 28 out.setTimeScale(1);
rlm@9 29 out.setVideoDimension(width, height);
rlm@9 30 this.videoReady = true;
rlm@9 31 }
rlm@9 32
rlm@9 33 public void record(BufferedImage rawFrame) {
rlm@9 34 if (!videoReady){initVideo();}
rlm@9 35 this.frame.getGraphics().drawImage(rawFrame, 0, 0, null);
rlm@9 36 try {out.writeFrame(frame);}
rlm@9 37 catch (IOException e){e.printStackTrace();}
rlm@9 38 }
rlm@9 39
rlm@9 40 public void finish() {
rlm@9 41 System.out.println("I'm finished! <3");
rlm@9 42 try {out.close();}
rlm@9 43 catch (IOException e) {e.printStackTrace();}
rlm@9 44 }
rlm@9 45
rlm@9 46
rlm@9 47
rlm@9 48 }