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