-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecordVideo.java
More file actions
60 lines (55 loc) · 1.68 KB
/
Copy pathRecordVideo.java
File metadata and controls
60 lines (55 loc) · 1.68 KB
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
import javax.imageio.stream.FileImageOutputStream;
import javax.imageio.stream.ImageOutputStream;
import java.awt.image.BufferedImage;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by Linus Karsai (312070209) on 28/05/2014.
*/
public class RecordVideo {
private boolean recording = false;
private GifSequenceWriter writer;
private ImageOutputStream output;
/**
* Create GIF from webcam, GifSequenceWriter care of Elliot Kroo
*/
public RecordVideo() {
}
public void start() {
// start creating img from GifSequence Writer
String home = System.getProperty("user.home");
File dir = new File(home + "/PhotoBooth/");
DateFormat dateFormat = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss");
Date date = new Date();
try {
output = new FileImageOutputStream(new File(dir + "/" + dateFormat.format(date) + ".gif"));
writer = new GifSequenceWriter(output, 1, 1, true);
recording = true;
} catch (Exception e) {
System.out.println("error creating file..");
}
}
public void addFrame(BufferedImage img) {
// add image to writer
synchronized (this) {
try {
writer.writeToSequence(img);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void stop() {
// finish writing
synchronized (this) {
try {
writer.close();
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}