view src/com/aurellem/capture/video/XuggleVideoRecorder.java @ 68:302d5e9ad120

adjust format
author Robert McIntyre <rlm@mit.edu>
date Thu, 19 Jul 2012 12:28:55 -0500
parents 8a6b1684f536
children 2c50a0c99715
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{
23 IMediaWriter writer;
24 BufferedImage frame;
25 int videoChannel = 0;
26 long currentTimeStamp = 0;
27 boolean videoReady = false;
30 public XuggleVideoRecorder(File output)
31 throws IOException {super(output);}
33 public void initVideo(){
34 this.frame = new BufferedImage(
35 width, height,
36 BufferedImage.TYPE_3BYTE_BGR);
37 this.writer = ToolFactory.makeWriter(this.targetFileName);
38 writer.addVideoStream(videoChannel,
39 0, IRational.make(fps),
40 width, height);
41 this.videoReady = true;
42 }
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 }
60 }