comparison 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
comparison
equal deleted inserted replaced
67:30cea3f0f30a 68:302d5e9ad120
17 * 17 *
18 */ 18 */
19 19
20 public class XuggleVideoRecorder extends AbstractVideoRecorder{ 20 public class XuggleVideoRecorder extends AbstractVideoRecorder{
21 21
22 IMediaWriter writer; 22
23 BufferedImage frame; 23 IMediaWriter writer;
24 int videoChannel = 0; 24 BufferedImage frame;
25 long currentTimeStamp = 0; 25 int videoChannel = 0;
26 boolean videoReady = false; 26 long currentTimeStamp = 0;
27 boolean videoReady = false;
28
27 29
30 public XuggleVideoRecorder(File output)
31 throws IOException {super(output);}
28 32
29 public XuggleVideoRecorder(File output) 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 }
30 43
31 public void initVideo(){ 44 public void record(BufferedImage rawFrame) {
32 this.frame = new BufferedImage( 45 if (!this.videoReady){initVideo();}
33 width, height, 46 // convert the Image into the form that Xuggle likes.
34 BufferedImage.TYPE_3BYTE_BGR); 47 this.frame.getGraphics().drawImage(rawFrame, 0, 0, null);
35 this.writer = ToolFactory.makeWriter(this.targetFileName); 48 writer.encodeVideo(videoChannel,
36 writer.addVideoStream(videoChannel, 49 frame,
37 0, IRational.make(fps), 50 currentTimeStamp, TimeUnit.NANOSECONDS);
38 width, height);
39 this.videoReady = true;
40 }
41
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);
49 51
50 currentTimeStamp += (long) (1000000000.0 / fps); 52 currentTimeStamp += (long) (1000000000.0 / fps);
51 } 53 }
52 54
53 public void finish() { 55 public void finish() {
54 writer.close(); 56 writer.close();
55 } 57 }
58
56 59
57 } 60 }
58 61
59 62