annotate src/com/aurellem/capture/video/XuggleVideoRecorder.java @ 10:4c5fc53778c1

moved randelshofer stuff to rightfull place, enabled XuggleVideoRecorder
author Robert McIntyre <rlm@mit.edu>
date Wed, 26 Oct 2011 09:38:27 -0700
parents 5dfc9e768816
children 8a6b1684f536
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@9 15 *
rlm@9 16 *
rlm@9 17 * @author Robert McIntyre
rlm@9 18 *
rlm@9 19 */
rlm@10 20
rlm@9 21 public class XuggleVideoRecorder extends AbstractVideoRecorder{
rlm@9 22
rlm@9 23 IMediaWriter writer;
rlm@9 24 BufferedImage frame;
rlm@9 25 int videoChannel = 0;
rlm@9 26 long currentTimeStamp = 0;
rlm@9 27 boolean videoReady = false;
rlm@9 28
rlm@9 29
rlm@9 30 public XuggleVideoRecorder(File output) throws IOException {super(output);}
rlm@9 31
rlm@9 32 public void initVideo(){
rlm@9 33 this.frame = new BufferedImage(
rlm@9 34 width, height,
rlm@9 35 BufferedImage.TYPE_3BYTE_BGR);
rlm@9 36 this.writer = ToolFactory.makeWriter(this.targetFileName);
rlm@9 37 writer.addVideoStream(videoChannel,
rlm@9 38 0, IRational.make(fps),
rlm@9 39 width, height);
rlm@9 40 this.videoReady = true;
rlm@9 41 }
rlm@9 42
rlm@9 43
rlm@9 44 public void record(BufferedImage rawFrame) {
rlm@9 45 if (!this.videoReady){initVideo();}
rlm@9 46 // convert the Image into the form that Xuggle likes.
rlm@9 47 this.frame.getGraphics().drawImage(rawFrame, 0, 0, null);
rlm@9 48 writer.encodeVideo(videoChannel,
rlm@9 49 frame,
rlm@9 50 currentTimeStamp, TimeUnit.NANOSECONDS);
rlm@9 51
rlm@9 52 currentTimeStamp += (long) (1000000000.0 / fps);
rlm@9 53 }
rlm@9 54
rlm@9 55 public void finish() {
rlm@9 56 writer.close();
rlm@9 57 }
rlm@9 58
rlm@9 59 }
rlm@9 60
rlm@10 61