rlm@9: package com.aurellem.capture.video; rlm@9: rlm@10: import java.awt.image.BufferedImage; rlm@10: import java.io.File; rlm@10: import java.io.IOException; rlm@10: import java.util.concurrent.TimeUnit; rlm@10: rlm@10: import com.xuggle.mediatool.IMediaWriter; rlm@10: import com.xuggle.mediatool.ToolFactory; rlm@10: import com.xuggle.xuggler.IRational; rlm@10: rlm@9: rlm@9: /** rlm@9: * Handles writing video files using Xuggle. rlm@11: * rlm@9: * @author Robert McIntyre rlm@9: * rlm@9: */ rlm@10: rlm@9: public class XuggleVideoRecorder extends AbstractVideoRecorder{ rlm@9: rlm@68: rlm@68: IMediaWriter writer; rlm@68: BufferedImage frame; rlm@68: int videoChannel = 0; rlm@68: long currentTimeStamp = 0; rlm@68: boolean videoReady = false; rlm@68: rlm@9: rlm@68: public XuggleVideoRecorder(File output) rlm@68: throws IOException {super(output);} rlm@9: rlm@68: public void initVideo(){ rlm@68: this.frame = new BufferedImage( rlm@68: width, height, rlm@68: BufferedImage.TYPE_3BYTE_BGR); rlm@68: this.writer = ToolFactory.makeWriter(this.targetFileName); rlm@68: writer.addVideoStream(videoChannel, rlm@68: 0, IRational.make(fps), rlm@68: width, height); rlm@68: this.videoReady = true; rlm@68: } rlm@9: rlm@68: public void record(BufferedImage rawFrame) { rlm@68: if (!this.videoReady){initVideo();} rlm@68: // convert the Image into the form that Xuggle likes. rlm@68: this.frame.getGraphics().drawImage(rawFrame, 0, 0, null); rlm@68: writer.encodeVideo(videoChannel, rlm@68: frame, rlm@68: currentTimeStamp, TimeUnit.NANOSECONDS); rlm@9: rlm@68: currentTimeStamp += (long) (1000000000.0 / fps); rlm@68: } rlm@9: rlm@68: public void finish() { rlm@68: writer.close(); rlm@68: } rlm@68: rlm@9: rlm@9: } rlm@9: rlm@10: