diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/com/aurellem/capture/Main.java	Tue Oct 25 11:55:55 2011 -0700
     1.3 @@ -0,0 +1,110 @@
     1.4 +/**
     1.5 + * @(#)Main.java  1.2  2009-08-29
     1.6 + *
     1.7 + * Copyright (c) 2008-2009 Werner Randelshofer, Immensee, Switzerland.
     1.8 + * All rights reserved.
     1.9 + *
    1.10 + * You may not use, copy or modify this file, except in compliance with the
    1.11 + * license agreement you entered into with Werner Randelshofer.
    1.12 + * For details see accompanying license terms.
    1.13 + */
    1.14 +package com.aurellem.capture;
    1.15 +
    1.16 +import java.awt.*;
    1.17 +import java.awt.image.BufferedImage;
    1.18 +import java.awt.image.IndexColorModel;
    1.19 +import java.io.*;
    1.20 +import java.util.Random;
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + * Main.
    1.25 + *
    1.26 + * @author Werner Randelshofer
    1.27 + * @version 1.1 2009-08-29 Added raw output.
    1.28 + * <br>1.0 2008-00-15 Created.
    1.29 + */
    1.30 +public class Main {
    1.31 +
    1.32 +    /**
    1.33 +     * @param args the command line arguments
    1.34 +     */
    1.35 +    public static void main(String[] args) {
    1.36 +        try {
    1.37 +            test(new File("/home/r/avidemo-jpg.avi"), AVIOutputStream.VideoFormat.JPG, 24, 1f);
    1.38 +            test(new File("/home/r/avidemo-png.avi"), AVIOutputStream.VideoFormat.PNG, 24, 1f);
    1.39 +            test(new File("/home/r/avidemo-raw.avi"), AVIOutputStream.VideoFormat.RAW, 24, 1f);
    1.40 +            test(new File("/home/r/avidemo-rle8.avi"), AVIOutputStream.VideoFormat.RLE, 8, 1f);
    1.41 +            test(new File("avidemo-rle4.avi"), AVIOutputStream.VideoFormat.RLE, 4, 1f);
    1.42 +
    1.43 +        } catch (IOException ex) {
    1.44 +            ex.printStackTrace();
    1.45 +        }
    1.46 +    }
    1.47 +
    1.48 +    private static void test(File file, AVIOutputStream.VideoFormat format, int depth, float quality) throws IOException {
    1.49 +        System.out.println("Writing " + file);
    1.50 +        AVIOutputStream out = null;
    1.51 +        Graphics2D g = null;
    1.52 +        try {
    1.53 +            out = new AVIOutputStream(file, format, depth);
    1.54 +            out.setVideoCompressionQuality(quality);
    1.55 +
    1.56 +            out.setTimeScale(1);
    1.57 +            out.setFrameRate(30);
    1.58 +
    1.59 +            Random rnd = new Random(0); // use seed 0 to get reproducable output
    1.60 +            BufferedImage img;
    1.61 +            switch (depth) {
    1.62 +                case 24:
    1.63 +                default: {
    1.64 +                    img = new BufferedImage(320, 160, BufferedImage.TYPE_INT_RGB);
    1.65 +                    break;
    1.66 +                }
    1.67 +                case 8: {
    1.68 +                    byte[] red = new byte[256];
    1.69 +                    byte[] green = new byte[256];
    1.70 +                    byte[] blue = new byte[256];
    1.71 +                    for (int i = 0; i < 255; i++) {
    1.72 +                        red[i] = (byte) rnd.nextInt(256);
    1.73 +                        green[i] = (byte) rnd.nextInt(256);
    1.74 +                        blue[i] = (byte) rnd.nextInt(256);
    1.75 +                    }
    1.76 +                    rnd.setSeed(0); // set back to 0 for reproducable output
    1.77 +                    img = new BufferedImage(320, 160, BufferedImage.TYPE_BYTE_INDEXED, new IndexColorModel(8, 256, red, green, blue));
    1.78 +                    break;
    1.79 +                }
    1.80 +                case 4: {
    1.81 +                    byte[] red = new byte[16];
    1.82 +                    byte[] green = new byte[16];
    1.83 +                    byte[] blue = new byte[16];
    1.84 +                    for (int i = 0; i < 15; i++) {
    1.85 +                        red[i] = (byte) rnd.nextInt(16);
    1.86 +                        green[i] = (byte) rnd.nextInt(16);
    1.87 +                        blue[i] = (byte) rnd.nextInt(16);
    1.88 +                    }
    1.89 +                    rnd.setSeed(0); // set back to 0 for reproducable output
    1.90 +                    img = new BufferedImage(320, 160, BufferedImage.TYPE_BYTE_BINARY, new IndexColorModel(4, 16, red, green, blue));
    1.91 +                    break;
    1.92 +                }
    1.93 +            }
    1.94 +            g = img.createGraphics();
    1.95 +            g.setBackground(Color.WHITE);
    1.96 +            g.clearRect(0, 0, img.getWidth(), img.getHeight());
    1.97 +
    1.98 +            for (int i = 0; i < 100; i++) {
    1.99 +                g.setColor(new Color(rnd.nextInt()));
   1.100 +                g.fillRect(rnd.nextInt(img.getWidth() - 30), rnd.nextInt(img.getHeight() - 30), 30, 30);
   1.101 +                out.writeFrame(img);
   1.102 +            }
   1.103 +
   1.104 +        } finally {
   1.105 +            if (g != null) {
   1.106 +                g.dispose();
   1.107 +            }
   1.108 +            if (out != null) {
   1.109 +                out.close();
   1.110 +            }
   1.111 +        }
   1.112 +    }
   1.113 +}