view src/com/aurellem/capture/video/XuggleVideoRecorder.java @ 64:155c70b7e6de

removed cursing
author Robert McIntyre <rlm@mit.edu>
date Fri, 10 Feb 2012 04:07:05 -0700
parents 8a6b1684f536
children 302d5e9ad120
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 * @author Robert McIntyre
17 *
18 */
20 public class XuggleVideoRecorder extends AbstractVideoRecorder{
22 IMediaWriter writer;
23 BufferedImage frame;
24 int videoChannel = 0;
25 long currentTimeStamp = 0;
26 boolean videoReady = false;
29 public XuggleVideoRecorder(File output) throws IOException {super(output);}
31 public void initVideo(){
32 this.frame = new BufferedImage(
33 width, height,
34 BufferedImage.TYPE_3BYTE_BGR);
35 this.writer = ToolFactory.makeWriter(this.targetFileName);
36 writer.addVideoStream(videoChannel,
37 0, IRational.make(fps),
38 width, height);
39 this.videoReady = true;
40 }
42 public void record(BufferedImage rawFrame) {
43 if (!this.videoReady){initVideo();}
44 // convert the Image into the form that Xuggle likes.
45 this.frame.getGraphics().drawImage(rawFrame, 0, 0, null);
46 writer.encodeVideo(videoChannel,
47 frame,
48 currentTimeStamp, TimeUnit.NANOSECONDS);
50 currentTimeStamp += (long) (1000000000.0 / fps);
51 }
53 public void finish() {
54 writer.close();
55 }
57 }