-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoFrameRate.m
70 lines (66 loc) · 2.19 KB
/
videoFrameRate.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
69
70
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% VIDEO FRAMERATE -- video editing tools
%%% Spencer Seiler
%%% Miroculus Inc.
%%% 08-02-2017
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while 1
[fileName, path] = uigetfile('*.*', 'Select Video to Alter');
filenameSplit = strsplit(fileName,'.');
switch char(filenameSplit{2})
case 'avi'
fileType = 'Motion JPEG AVI';
break
case 'mj2'
fileType = 'Motion JPEG 2000';
break
case 'mp4'
fileType = 'MPEG-4';
break
case 'm4v'
fileType = 'MPEG-4';
break
otherwise
uiwait(msgbox({'Unsupported filetype' 'Select from (*.avi, *.mj2, *.mp4, *.m4v)'},'Error','error'))
continue
end
end
vid = VideoReader([path fileName]);
while 1
vidRateMult = inputdlg('Frame rate multiplier:','Framerate Input',1,{'10'});
altVidPath = [path char(filenameSplit{1}) '_' char(vidRateMult{1}) 'X'];
vidRateMult = str2double(char(vidRateMult{1}));
if isnan(vidRateMult) || vidRateMult==0
uiwait(msgbox({'Unrecognized input' 'Choose a nonzero numerical value'},'Error','error'))
continue
elseif vid.FrameRate*vidRateMult < 1
uiwait(msgbox({'Frame rate multiplier too small' 'Choose a larger value'},'Error','error'))
continue
else
targFrameRate = vid.FrameRate*vidRateMult;
break
end
end
Msgbox = msgbox({'Edit in progress','Please wait.....'},'Notice');
altVid = VideoWriter(char(altVidPath),fileType);
altVidQuality = 100;
if targFrameRate <= 30
altVid.FrameRate = targFrameRate;
open(altVid);
while hasFrame(vid)
vidFrame = readFrame(vid);
writeVideo(altVid,vidFrame);
end
else
altVid.FrameRate = 30;
open(altVid);
while hasFrame(vid)
vidFrame = readFrame(vid);
if vid.CurrentTime >= altVid.FrameCount*(1/30)*vidRateMult
writeVideo(altVid,vidFrame);
end
end
end
close(altVid);
delete(Msgbox);
msgbox({'Edit complete','Your video is finished'},'Notice');