-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.txt
executable file
·151 lines (138 loc) · 4 KB
/
code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Scanner;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.media.MediaLocator;
/**
* Main class that starts the Recording process of EasyCapture.
*
* @author Senthil Balakrishnan
*/
public class Recorder {
/**
* Screen Width.
*/
public static int screenWidth = (int) Toolkit.getDefaultToolkit()
.getScreenSize().getWidth();
/**
* Screen Height.
*/
public static int screenHeight = (int) Toolkit.getDefaultToolkit()
.getScreenSize().getHeight();
/**
* Interval between which the image needs to be captured.
*/
public static int captureInterval = 50;
/**
* Temporary folder to store the screenshot.
*/
public static String store = "tmp";
/**
* Status of the recorder.
*/
public static boolean record = false;
/**
*
*/
public static void startRecord() {
Thread recordThread = new Thread() {
@Override
public void run() {
Robot rt;
int cnt = 0;
try {
rt = new Robot();
while (cnt == 0 || record) {
BufferedImage img = rt
.createScreenCapture(new Rectangle(screenWidth,
screenHeight));
ImageIO.write(img, "jpeg", new File("./"+store+"/"
+ System.currentTimeMillis() + ".jpeg"));
if (cnt == 0) {
record = true;
cnt = 1;
}
// System.out.println(record);
Thread.sleep(captureInterval);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
recordThread.start();
}
/**
* @throws MalformedURLException
*
*/
public static void makeVideo(String movFile) throws MalformedURLException {
System.out
.println("#### Easy Capture making video, please wait!!! ####");
JpegImagesToMovie imageToMovie = new JpegImagesToMovie();
Vector<String> imgLst = new Vector<String>();
File f = new File(store);
File[] fileLst = f.listFiles();
for (int i = 0; i < fileLst.length; i++) {
imgLst.add(fileLst[i].getAbsolutePath());
}
// Generate the output media locators.
MediaLocator oml;
if ((oml = imageToMovie.createMediaLocator(movFile)) == null) {
System.err.println("Cannot build media locator from: " + movFile);
System.exit(0);
}
imageToMovie.doIt(screenWidth, screenHeight, (1000 / captureInterval),
imgLst, oml);
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
System.out.println("######### Starting Easy Capture Recorder #######");
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
System.out.println("Your Screen [Width,Height]:" + "["
+ screen.getWidth() + "," + screen.getHeight() + "]");
Scanner sc = new Scanner(System.in);
System.out.println("Rate 20 Frames/Per Sec.");
System.out
.print("Do you wanna change the screen capture area (y/n) ? ");
if (sc.next().equalsIgnoreCase("y")) {
System.out.print("Enter the width:");
screenWidth = sc.nextInt();
System.out.print("Enter the Height:");
screenHeight = sc.nextInt();
System.out.println("Your Screen [Width,Height]:" + "["
+ screen.getWidth() + "," + screen.getHeight() + "]");
}
System.out
.print("Now move to the screen you want to record");
for(int i=0;i<5;i++){
System.out.print(".");
Thread.sleep(1000);
}
File f = new File(store);
if(!f.exists()){
f.mkdir();
}
startRecord();
System.out
.println("\nEasy Capture is recording now!!!!!!!");
System.out.println("Press e to exit:");
String exit = sc.next();
while (exit == null || "".equals(exit) || !"e".equalsIgnoreCase(exit)) {
System.out.println("\nPress e to exit:");
exit = sc.next();
}
record = false;
System.out.println("Easy Capture has stopped.");
makeVideo(System.currentTimeMillis()+".mov");
}
}