@@ -16,6 +16,7 @@ kernelspec:
16
16
17
17
import os
18
18
import functools
19
+ import subprocess
19
20
from pathlib import Path
20
21
21
22
import matplotlib.tri as mtri
@@ -80,7 +81,7 @@ def learner_till(till, learner, data):
80
81
81
82
def plot_tri(learner, ax):
82
83
tri = learner.ip().tri
83
- triang = mtri.Triangulation(*tri.points.T, triangles=tri.vertices )
84
+ triang = mtri.Triangulation(*tri.points.T, triangles=tri.simplices )
84
85
return ax.triplot(triang, c="k", lw=0.8, alpha=0.8)
85
86
86
87
@@ -140,17 +141,19 @@ def animate_mp4(fname="source/_static/logo_docs.mp4", nseconds=15):
140
141
get_new_artists(n, learner, data, rounded_corners, ax) for n in tqdm(npoints)
141
142
]
142
143
ani = animation.ArtistAnimation(fig, artists, blit=True)
143
- ani.save(fname, writer=FFMpegWriter(fps=24))
144
+ ani.save(fname, writer=FFMpegWriter(fps=24, codec="libvpx-vp9" ))
144
145
145
146
146
- def animate_png(folder="/tmp" , nseconds=15):
147
+ def animate_png(folder=None , nseconds=15):
147
148
npoints, learner, data, rounded_corners, fig, ax = setup(nseconds)
149
+ if folder is None:
150
+ folder = Path(tempfile.gettempdir()) / next(tempfile._get_candidate_names())
148
151
folder = Path(folder)
149
152
folder.mkdir(parents=True, exist_ok=True)
150
153
fnames = []
151
154
ims = []
152
- for n in tqdm(npoints):
153
- fname = folder / f"logo_docs_{n:03d }.png"
155
+ for i, n in tqdm(enumerate( npoints), total=len(npoints) ):
156
+ fname = folder / f"logo_docs_{i:07d }.png"
154
157
fnames.append(fname)
155
158
npoints, learner, data, _, fig, ax = setup(nseconds)
156
159
get_new_artists(n, learner, data, None, ax)
@@ -162,44 +165,52 @@ def animate_png(folder="/tmp", nseconds=15):
162
165
return fnames, ims
163
166
164
167
168
+ def save_webp(fname_webp, ims):
169
+ (im, *_ims) = ims
170
+ im.save(
171
+ fname_webp,
172
+ save_all=True,
173
+ append_images=_ims,
174
+ opimize=False,
175
+ durarion=2,
176
+ quality=70,
177
+ )
178
+
179
+
180
+ def save_webm(fname, fnames):
181
+ args = [
182
+ "ffmpeg",
183
+ "-framerate",
184
+ "24",
185
+ "-f",
186
+ "image2",
187
+ "-i",
188
+ str(fnames[0]).replace("0000000", "%07d"),
189
+ "-c:v",
190
+ "libvpx-vp9",
191
+ "-pix_fmt",
192
+ "yuva420p",
193
+ "-y",
194
+ fname,
195
+ ]
196
+ return subprocess.run(args, capture_output=True)
197
+
198
+
165
199
if __name__ == "__main__":
166
200
fname_mp4 = Path("_static/logo_docs.mp4")
167
- if not fname_mp4.exists():
168
- animate_mp4(fname_mp4)
169
- fname_webp = fname_mp4.with_suffix(".webp ")
201
+ # if not fname_mp4.exists():
202
+ # animate_mp4(fname_mp4)
203
+ fname_webm = fname_mp4.with_suffix(".webm ")
170
204
if not fname_webp.exists():
171
205
fnames, ims = animate_png()
172
- im.save(
173
- fname_webp,
174
- save_all=True,
175
- append_images=_ims,
176
- opimize=False,
177
- durarion=2,
178
- quality=70,
179
- )
206
+ save_webm(fname_webm, fnames)
180
207
```
181
208
182
209
``` {eval-rst}
183
210
.. raw:: html
184
211
185
- <style>
186
- .dark-video {
187
- display: none;
188
- }
189
-
190
- @media (prefers-color-scheme: dark) {
191
- .dark-video {
192
- display: block;
193
- }
194
-
195
- .light-video {
196
- display: none;
197
- }
198
- }
199
- </style>
200
- <video autoplay loop muted playsinline webkit-playsinline style="width: 400px; max-width: 100%; margin: 0 auto; display:block;">
201
- <source class="dark-video" src="_static/logo_docs.mp4" type="video/mp4">
202
- <source class="light-video" src="_static/logo_docs1.mp4" type="video/mp4">
203
- </video>
204
- <br>
212
+ <video autoplay loop muted playsinline webkit-playsinline
213
+ style="width: 400px; max-width: 100%; margin: 0 auto; display:block;">
214
+ <source src="_static/logo_docs.webm" type="video/mp4">
215
+ </video><br>
205
216
```
0 commit comments