Mercurial > jmeCapture
view 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 |
line wrap: on
line source
1 package com.aurellem.capture.video;3 import java.awt.image.BufferedImage;4 import java.io.File;5 import java.io.IOException;6 import java.util.concurrent.TimeUnit;8 import com.xuggle.mediatool.IMediaWriter;9 import com.xuggle.mediatool.ToolFactory;10 import com.xuggle.xuggler.IRational;13 /**14 * Handles writing video files using Xuggle.15 *16 *17 * @author Robert McIntyre18 *19 */21 public class XuggleVideoRecorder extends AbstractVideoRecorder{23 IMediaWriter writer;24 BufferedImage frame;25 int videoChannel = 0;26 long currentTimeStamp = 0;27 boolean videoReady = false;30 public XuggleVideoRecorder(File output) throws IOException {super(output);}32 public void initVideo(){33 this.frame = new BufferedImage(34 width, height,35 BufferedImage.TYPE_3BYTE_BGR);36 this.writer = ToolFactory.makeWriter(this.targetFileName);37 writer.addVideoStream(videoChannel,38 0, IRational.make(fps),39 width, height);40 this.videoReady = true;41 }44 public void record(BufferedImage rawFrame) {45 if (!this.videoReady){initVideo();}46 // convert the Image into the form that Xuggle likes.47 this.frame.getGraphics().drawImage(rawFrame, 0, 0, null);48 writer.encodeVideo(videoChannel,49 frame,50 currentTimeStamp, TimeUnit.NANOSECONDS);52 currentTimeStamp += (long) (1000000000.0 / fps);53 }55 public void finish() {56 writer.close();57 }59 }