Mercurial > jmeCapture
view src/com/aurellem/capture/Main.java @ 3:a92de00f0414
migrating files
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 11:55:55 -0700 |
parents | |
children | 5dfc9e768816 |
line wrap: on
line source
1 /**2 * @(#)Main.java 1.2 2009-08-293 *4 * Copyright (c) 2008-2009 Werner Randelshofer, Immensee, Switzerland.5 * All rights reserved.6 *7 * You may not use, copy or modify this file, except in compliance with the8 * license agreement you entered into with Werner Randelshofer.9 * For details see accompanying license terms.10 */11 package com.aurellem.capture;13 import java.awt.*;14 import java.awt.image.BufferedImage;15 import java.awt.image.IndexColorModel;16 import java.io.*;17 import java.util.Random;20 /**21 * Main.22 *23 * @author Werner Randelshofer24 * @version 1.1 2009-08-29 Added raw output.25 * <br>1.0 2008-00-15 Created.26 */27 public class Main {29 /**30 * @param args the command line arguments31 */32 public static void main(String[] args) {33 try {34 test(new File("/home/r/avidemo-jpg.avi"), AVIOutputStream.VideoFormat.JPG, 24, 1f);35 test(new File("/home/r/avidemo-png.avi"), AVIOutputStream.VideoFormat.PNG, 24, 1f);36 test(new File("/home/r/avidemo-raw.avi"), AVIOutputStream.VideoFormat.RAW, 24, 1f);37 test(new File("/home/r/avidemo-rle8.avi"), AVIOutputStream.VideoFormat.RLE, 8, 1f);38 test(new File("avidemo-rle4.avi"), AVIOutputStream.VideoFormat.RLE, 4, 1f);40 } catch (IOException ex) {41 ex.printStackTrace();42 }43 }45 private static void test(File file, AVIOutputStream.VideoFormat format, int depth, float quality) throws IOException {46 System.out.println("Writing " + file);47 AVIOutputStream out = null;48 Graphics2D g = null;49 try {50 out = new AVIOutputStream(file, format, depth);51 out.setVideoCompressionQuality(quality);53 out.setTimeScale(1);54 out.setFrameRate(30);56 Random rnd = new Random(0); // use seed 0 to get reproducable output57 BufferedImage img;58 switch (depth) {59 case 24:60 default: {61 img = new BufferedImage(320, 160, BufferedImage.TYPE_INT_RGB);62 break;63 }64 case 8: {65 byte[] red = new byte[256];66 byte[] green = new byte[256];67 byte[] blue = new byte[256];68 for (int i = 0; i < 255; i++) {69 red[i] = (byte) rnd.nextInt(256);70 green[i] = (byte) rnd.nextInt(256);71 blue[i] = (byte) rnd.nextInt(256);72 }73 rnd.setSeed(0); // set back to 0 for reproducable output74 img = new BufferedImage(320, 160, BufferedImage.TYPE_BYTE_INDEXED, new IndexColorModel(8, 256, red, green, blue));75 break;76 }77 case 4: {78 byte[] red = new byte[16];79 byte[] green = new byte[16];80 byte[] blue = new byte[16];81 for (int i = 0; i < 15; i++) {82 red[i] = (byte) rnd.nextInt(16);83 green[i] = (byte) rnd.nextInt(16);84 blue[i] = (byte) rnd.nextInt(16);85 }86 rnd.setSeed(0); // set back to 0 for reproducable output87 img = new BufferedImage(320, 160, BufferedImage.TYPE_BYTE_BINARY, new IndexColorModel(4, 16, red, green, blue));88 break;89 }90 }91 g = img.createGraphics();92 g.setBackground(Color.WHITE);93 g.clearRect(0, 0, img.getWidth(), img.getHeight());95 for (int i = 0; i < 100; i++) {96 g.setColor(new Color(rnd.nextInt()));97 g.fillRect(rnd.nextInt(img.getWidth() - 30), rnd.nextInt(img.getHeight() - 30), 30, 30);98 out.writeFrame(img);99 }101 } finally {102 if (g != null) {103 g.dispose();104 }105 if (out != null) {106 out.close();107 }108 }109 }110 }