-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathvideoMaker.m
68 lines (66 loc) · 2.18 KB
/
videoMaker.m
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
classdef videoMaker < handle
properties
nowCursor
hTimer
hGraphics
period
hStreamObj
videoFilename
tmin
tmax
paintCallback
end
properties(Hidden = true)
vObj
progressBar
statusBar
end
methods
function obj = videoMaker(hStreamObj,tmin,tmax,period, saveAs,hGraphics,paintCallback)
obj.hStreamObj = hStreamObj;
obj.tmin = tmin;
obj.tmax = tmax;
obj.period = period;
obj.videoFilename = saveAs;
obj.hGraphics = hGraphics;
obj.paintCallback = paintCallback;
obj.nowCursor = obj.tmin;
hFigure = get(get(hGraphics,'Parent'),'Parent');
obj.vObj = VideoWriter(obj.videoFilename, 'Motion JPEG AVI');
obj.vObj.FrameRate = 1/period;
open(obj.vObj);
obj.statusBar = com.mathworks.mwswing.MJStatusBar;
obj.progressBar = javax.swing.JProgressBar;
set(obj.progressBar, 'Minimum',obj.tmin, 'Maximum',obj.tmax, 'Value',obj.tmin);
obj.statusBar.add(obj.progressBar,'West');
jFrame = get(handle(hFigure),'JavaFrame');
jRootPane = jFrame.fHG1Client.getWindow;
jRootPane.setStatusBar(obj.statusBar)
obj.statusBar.setText('Writing...')
obj.hTimer = timer('TimerFcn',{@playCallback, obj}, 'Period', period,'BusyMode','queue','ExecutionMode','fixedRate');
start(obj.hTimer);
end
function delete(obj)
close(obj.vObj)
stop(obj.hTimer);
delete(obj.hTimer);
end
end
end
function playCallback(tobj,event,obj) %#ok
if obj.nowCursor+obj.period > obj.tmax
stop(obj.hTimer);
obj.statusBar.setText('Done')
hFigure = get(get(obj.hGraphics,'Parent'),'Parent');
close(hFigure);
delete(obj);
return
end
obj.paintCallback(obj.hGraphics,obj.nowCursor);
hAxes = get(obj.hGraphics,'Parent');
frame = getframe(hAxes);
if any(frame.cdata(:,end,1)), frame.cdata(:,end,:) = 0;end
writeVideo(obj.vObj,frame);
obj.nowCursor = obj.nowCursor+obj.period;
set(obj.progressBar,'Value',obj.nowCursor);
end