-
Notifications
You must be signed in to change notification settings - Fork 10
/
Record_Desktop_fix.py
69 lines (62 loc) · 1.92 KB
/
Record_Desktop_fix.py
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
# Take a snapshot of the desktop every X miliseconds,
# and then make a stack out of it.
# Limited by RAM for speed, this plugin is intended
# for short recordings.
import thread
import time
import ij
from java.awt import Robot, Rectangle
from java.lang.System import out, currentTimeMillis
def run(title):
gd = ij.gui.GenericDialog('Record Desktop')
gd.addNumericField('Max. frames:', 50, 0)
gd.addNumericField('Milisecond interval:', 300, 0)
gd.addSlider('Start in (seconds):', 0, 20, 5)
gd.showDialog()
if gd.wasCanceled():
return
n_frames = int(gd.getNextNumber())
interval = gd.getNextNumber() / 1000.0 # in seconds
delay = int(gd.getNextNumber())
snaps = []
try:
while delay > 0:
ij.IJ.showStatus('Starting in ' + str(delay) + 's.')
time.sleep(1) # one second
delay -= 1
ij.IJ.showStatus('')
ij.IJ.showStatus("Starting...")
out.println("Starting...")
# start capturing
robot = Robot()
box = Rectangle(ij.IJ.getScreenSize())
start = currentTimeMillis() / 1000.0 # in seconds
last = start
intervals = []
real_interval = 0
# Initial shot
snaps.append(robot.createScreenCapture(box))
while len(snaps) < n_frames and last - start < n_frames * interval:
now = currentTimeMillis() / 1000.0 # in seconds
real_interval = now - last
if real_interval >= interval:
last = now
snaps.append(robot.createScreenCapture(box))
intervals.append(real_interval)
else:
time.sleep(interval / 5) # time in seconds
# Create stack
out.println("End")
awt = snaps[0]
stack = ij.ImageStack(awt.getWidth(None), awt.getHeight(None), None)
t = 0
for snap,real_interval in zip(snaps,intervals):
stack.addSlice(str(ij.IJ.d2s(t, 3)), ij.ImagePlus('', snap).getProcessor())
snap.flush()
t += real_interval
ImagePlus("Desktop recording", stack).show()
except Exception, e:
print "Some error ocurred:"
print e
for snap in snaps: snap.flush()
thread.start_new_thread(run, ("Do it",))