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@9: IMediaWriter writer; rlm@9: BufferedImage frame; rlm@9: int videoChannel = 0; rlm@9: long currentTimeStamp = 0; rlm@9: boolean videoReady = false; rlm@9: rlm@9: rlm@9: public XuggleVideoRecorder(File output) throws IOException {super(output);} rlm@9: rlm@9: public void initVideo(){ rlm@9: this.frame = new BufferedImage( rlm@9: width, height, rlm@9: BufferedImage.TYPE_3BYTE_BGR); rlm@9: this.writer = ToolFactory.makeWriter(this.targetFileName); rlm@9: writer.addVideoStream(videoChannel, rlm@9: 0, IRational.make(fps), rlm@9: width, height); rlm@9: this.videoReady = true; rlm@9: } rlm@11: rlm@9: public void record(BufferedImage rawFrame) { rlm@9: if (!this.videoReady){initVideo();} rlm@9: // convert the Image into the form that Xuggle likes. rlm@9: this.frame.getGraphics().drawImage(rawFrame, 0, 0, null); rlm@9: writer.encodeVideo(videoChannel, rlm@9: frame, rlm@9: currentTimeStamp, TimeUnit.NANOSECONDS); rlm@9: rlm@9: currentTimeStamp += (long) (1000000000.0 / fps); rlm@9: } rlm@9: rlm@9: public void finish() { rlm@9: writer.close(); rlm@9: } rlm@9: rlm@9: } rlm@9: rlm@10: