annotate src/com/aurellem/capture/video/XuggleVideoRecorder.java @ 21:d924d7d29063

spazz dancing lol
author Robert McIntyre <rlm@mit.edu>
date Sat, 29 Oct 2011 16:23:57 -0700
parents 8a6b1684f536
children 302d5e9ad120
rev   line source
rlm@9 1 package com.aurellem.capture.video;
rlm@9 2
rlm@10 3 import java.awt.image.BufferedImage;
rlm@10 4 import java.io.File;
rlm@10 5 import java.io.IOException;
rlm@10 6 import java.util.concurrent.TimeUnit;
rlm@10 7
rlm@10 8 import com.xuggle.mediatool.IMediaWriter;
rlm@10 9 import com.xuggle.mediatool.ToolFactory;
rlm@10 10 import com.xuggle.xuggler.IRational;
rlm@10 11
rlm@9 12
rlm@9 13 /**
rlm@9 14 * Handles writing video files using Xuggle.
rlm@11 15 *
rlm@9 16 * @author Robert McIntyre
rlm@9 17 *
rlm@9 18 */
rlm@10 19
rlm@9 20 public class XuggleVideoRecorder extends AbstractVideoRecorder{
rlm@9 21
rlm@9 22 IMediaWriter writer;
rlm@9 23 BufferedImage frame;
rlm@9 24 int videoChannel = 0;
rlm@9 25 long currentTimeStamp = 0;
rlm@9 26 boolean videoReady = false;
rlm@9 27
rlm@9 28
rlm@9 29 public XuggleVideoRecorder(File output) throws IOException {super(output);}
rlm@9 30
rlm@9 31 public void initVideo(){
rlm@9 32 this.frame = new BufferedImage(
rlm@9 33 width, height,
rlm@9 34 BufferedImage.TYPE_3BYTE_BGR);
rlm@9 35 this.writer = ToolFactory.makeWriter(this.targetFileName);
rlm@9 36 writer.addVideoStream(videoChannel,
rlm@9 37 0, IRational.make(fps),
rlm@9 38 width, height);
rlm@9 39 this.videoReady = true;
rlm@9 40 }
rlm@11 41
rlm@9 42 public void record(BufferedImage rawFrame) {
rlm@9 43 if (!this.videoReady){initVideo();}
rlm@9 44 // convert the Image into the form that Xuggle likes.
rlm@9 45 this.frame.getGraphics().drawImage(rawFrame, 0, 0, null);
rlm@9 46 writer.encodeVideo(videoChannel,
rlm@9 47 frame,
rlm@9 48 currentTimeStamp, TimeUnit.NANOSECONDS);
rlm@9 49
rlm@9 50 currentTimeStamp += (long) (1000000000.0 / fps);
rlm@9 51 }
rlm@9 52
rlm@9 53 public void finish() {
rlm@9 54 writer.close();
rlm@9 55 }
rlm@9 56
rlm@9 57 }
rlm@9 58
rlm@10 59