-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmakeMovie.m
More file actions
154 lines (93 loc) · 4.02 KB
/
makeMovie.m
File metadata and controls
154 lines (93 loc) · 4.02 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
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
function makeMovie()
%% Set animation settings
set(0,'DefaultAxesXMinorTick','on','DefaultAxesYMinorTick','on')
set(0,'DefaultAxesLineWidth', 2,'DefaultAxesFontName','Times',...
'DefaultAxesFontSize',18,'DefaultAxesBox','on')
ffmpegPath = {'/opt/homebrew/bin/ffmpeg'};
outputFormat = 'webm';
targetTime = 20;
size = [300,300];
mkdir('animations')
%% KPR Animation
problemName = 'bouncingball';
presetName = 'RandomTerrain';
filename = strcat('animations/', problemName,'-', presetName);
string = strcat(['otp.', problemName,'.presets.', presetName] );
problem = eval(string);
problem.TimeSpan = [0,30];
sol = problem.solve('RelTol', 1e-8);
mov = problem.movie(sol, 'Save', filename, ...
'TargetDuration',targetTime, ...
'Size', size, ...
'FrameRate', 15, ...
'view', [0,90]);
args = get_ffmpeg_args(outputFormat, filename);
command = strjoin(strcat([ffmpegPath,' ' , args]));
system(command);
% Nbody animation
problemName = 'nbody';
presetName = 'OuterSolarSystem';
filename = strcat('animations/', problemName,'-', presetName);
string = strcat(['otp.', problemName,'.presets.', presetName] );
problem = eval(string);
sol = problem.solve('RelTol', 1e-4);
mov = problem.movie(sol, 'Save', filename, ...
'TargetDuration',targetTime, ...
'Size', size, ...
'FrameRate', 15, ...
'view', [60,30]);
args = get_ffmpeg_args(outputFormat, filename);
command = strjoin(strcat([ffmpegPath,' ' , args]));
system(command);
%% Pendulum animation
problemName = 'pendulum';
presetName = 'Canonical';
filename = strcat('animations/', problemName,'-', presetName);
problem = otp.pendulum.presets.Canonical(4);
problem.Y0(1:4) = pi/3;
problem.Parameters.Masses = [1,1,3,3]';
sol = problem.solve('RelTol', 1e-9);
mov = problem.movie(sol, 'Save', filename, ...
'TargetDuration',targetTime, ...
'Size', size, ...
'FrameRate', 15, ...
'view', [0,90]);
args = get_ffmpeg_args(outputFormat, filename);
command = strjoin(strcat([ffmpegPath,' ' , args]));
system(command);
%% Lorenz63 animation
problemName = 'lorenz63';
presetName = 'Canonical';
filename = strcat('animations/', problemName,'-', presetName);
string = strcat(['otp.', problemName,'.presets.', presetName] );
problem = eval(string);
sol = problem.solve('RelTol', 1e-9);
problem.Y0 = sol.y(:,500);
problem.TimeSpan = [0,30];
sol = problem.solve('RelTol', 1e-9);
mov = problem.movie(sol, 'Save', filename, ...
'TargetDuration',targetTime, ...
'Size', size, ...
'FrameRate', 15, ...
'view', [60,30]);
args = get_ffmpeg_args(outputFormat, filename);
command = strjoin(strcat([ffmpegPath,' ' , args]));
system(command);
end
function [args] = get_ffmpeg_args(outputFormat, filename)
% convert vido format if neccessary
switch outputFormat
case 'avi'
case 'gif'
args = strcat(['-i ' ...
filename,'.avi ' ...
' -vf "fps=15,scale=500:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0' ...
' '...
filename,'.gif']);
case 'webm'
args = strcat(['-i ' ...
filename,'.avi ' ...
'-c:v libvpx -quality best -crf 5 -b:v 1M -c:a libvorbis '...
filename,'.webm']);
end
end