Iskaj commited on
Commit
a7b0fd6
1 Parent(s): 12bf9f5

add generate randomizer, restructure app.py

Browse files
Files changed (2) hide show
  1. app.py +19 -6
  2. clip_data.ipynb +261 -507
app.py CHANGED
@@ -23,6 +23,7 @@ import faiss
23
  import shutil
24
 
25
  FPS = 5
 
26
 
27
  video_directory = tempfile.gettempdir()
28
 
@@ -103,7 +104,14 @@ def index_hashes_for_video(url, is_file = False):
103
  logging.info(f"Indexed hashes for {index.ntotal} frames to {filename}.index.")
104
  return index
105
 
106
- def compare_videos(url, target, MIN_DISTANCE = 3): # , is_file = False):
 
 
 
 
 
 
 
107
  """" The comparison between the target and the original video will be plotted based
108
  on the matches between the target and the original video over time. The matches are determined
109
  based on the minimum distance between hashes (as computed by faiss-vectors) before they're considered a match.
@@ -126,13 +134,18 @@ def compare_videos(url, target, MIN_DISTANCE = 3): # , is_file = False):
126
 
127
  # Target video (long video)
128
  target_indices = [index_hashes_for_video(x) for x in [target]]
129
-
 
 
 
130
  # The results are returned as a triplet of 1D arrays
131
  # lims, D, I, where result for query i is in I[lims[i]:lims[i+1]]
132
  # (indices of neighbors), D[lims[i]:lims[i+1]] (distances).
133
  lims, D, I = target_indices[0].range_search(hash_vectors, MIN_DISTANCE)
 
134
 
135
- return plot_comparison(lims, D, I, hash_vectors, MIN_DISTANCE = MIN_DISTANCE)
 
136
 
137
  def plot_comparison(lims, D, I, hash_vectors, MIN_DISTANCE = 3):
138
  sns.set_theme()
@@ -177,15 +190,15 @@ index_iface = gr.Interface(fn=lambda url: index_hashes_for_video(url).ntotal,
177
  inputs="text", outputs="text",
178
  examples=video_urls, cache_examples=True)
179
 
180
- compare_iface = gr.Interface(fn=compare_videos,
181
- inputs=["text", "text", gr.Slider(1, 25, 3, step=1)], outputs="plot",
182
  examples=[[x, video_urls[-1]] for x in video_urls[:-1]])
183
 
184
  iface = gr.TabbedInterface([index_iface, compare_iface], ["Index", "Compare"])
185
 
186
  if __name__ == "__main__":
187
  import matplotlib
188
- matplotlib.use('SVG')
189
 
190
  logging.basicConfig()
191
  logging.getLogger().setLevel(logging.DEBUG)
 
23
  import shutil
24
 
25
  FPS = 5
26
+ MAX_DISTANCE = 30
27
 
28
  video_directory = tempfile.gettempdir()
29
 
 
104
  logging.info(f"Indexed hashes for {index.ntotal} frames to {filename}.index.")
105
  return index
106
 
107
+ def get_comparison(url, target, MIN_DISTANCE = 3):
108
+ """ Function for Gradio to combine all helper functions"""
109
+ video_index, hash_vectors, target_indices = get_video_indices(url, target, MIN_DISTANCE = MIN_DISTANCE)
110
+ lims, D, I, hash_vectors = compare_videos(video_index, hash_vectors, target_indices, MIN_DISTANCE = MIN_DISTANCE)
111
+ fig = plot_comparison(lims, D, I, hash_vectors, MIN_DISTANCE = MIN_DISTANCE)
112
+ return fig
113
+
114
+ def get_video_indices(url, target, MIN_DISTANCE = 4):
115
  """" The comparison between the target and the original video will be plotted based
116
  on the matches between the target and the original video over time. The matches are determined
117
  based on the minimum distance between hashes (as computed by faiss-vectors) before they're considered a match.
 
134
 
135
  # Target video (long video)
136
  target_indices = [index_hashes_for_video(x) for x in [target]]
137
+
138
+ return video_index, hash_vectors, target_indices
139
+
140
+ def compare_videos(video_index, hash_vectors, target_indices, MIN_DISTANCE = 3): # , is_file = False):
141
  # The results are returned as a triplet of 1D arrays
142
  # lims, D, I, where result for query i is in I[lims[i]:lims[i+1]]
143
  # (indices of neighbors), D[lims[i]:lims[i+1]] (distances).
144
  lims, D, I = target_indices[0].range_search(hash_vectors, MIN_DISTANCE)
145
+ return lims, D, I, hash_vectors
146
 
147
+ def plot_distances(target_indices, hash_vectors, MIN_DISTANCE, MAX_DISTANCE):
148
+ pass
149
 
150
  def plot_comparison(lims, D, I, hash_vectors, MIN_DISTANCE = 3):
151
  sns.set_theme()
 
190
  inputs="text", outputs="text",
191
  examples=video_urls, cache_examples=True)
192
 
193
+ compare_iface = gr.Interface(fn=get_comparison,
194
+ inputs=["text", "text", gr.Slider(2, 30, 4, step=2)], outputs="plot",
195
  examples=[[x, video_urls[-1]] for x in video_urls[:-1]])
196
 
197
  iface = gr.TabbedInterface([index_iface, compare_iface], ["Index", "Compare"])
198
 
199
  if __name__ == "__main__":
200
  import matplotlib
201
+ matplotlib.use('SVG') # To be able to plot in gradio
202
 
203
  logging.basicConfig()
204
  logging.getLogger().setLevel(logging.DEBUG)
clip_data.ipynb CHANGED
@@ -2,44 +2,55 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 27,
6
  "metadata": {},
7
  "outputs": [
8
  {
9
  "name": "stderr",
10
  "output_type": "stream",
11
  "text": [
12
- " \n",
13
- "\n",
14
- "\u001b[A\u001b[A \n",
15
- "chunk: 4%|▎ | 111/3088 [2:30:34<67:18:26, 81.39s/it, now=None]\n",
16
- "\u001b[A\n",
17
- "chunk: 4%|▎ | 111/3088 [2:27:17<65:50:31, 79.62s/it, now=None]"
 
 
 
 
18
  ]
19
  },
20
  {
21
  "name": "stdout",
22
  "output_type": "stream",
23
  "text": [
24
- "Part Start = 5.0, Part Cutout = 5.0, Part Mid = 5.0, Part End = 135.03\n",
25
- "Moviepy - Building video videos/Ploumen_CO_5.0s_to_10.0_at_15.0.mp4.\n"
26
  ]
27
  },
28
  {
29
  "name": "stderr",
30
  "output_type": "stream",
31
  "text": [
32
- " \n",
33
- "\n",
34
- "\u001b[A\u001b[A \n",
35
- "chunk: 4%|▎ | 111/3088 [2:30:34<67:18:26, 81.39s/it, now=None]\n",
36
- "\u001b[A"
 
 
 
 
 
 
37
  ]
38
  },
39
  {
40
  "name": "stdout",
41
  "output_type": "stream",
42
  "text": [
 
 
43
  "MoviePy - Writing audio in Ploumen_CO_5.0s_to_10.0_at_15.0TEMP_MPY_wvf_snd.mp4\n"
44
  ]
45
  },
@@ -47,49 +58,7 @@
47
  "name": "stderr",
48
  "output_type": "stream",
49
  "text": [
50
- "\n",
51
- "\n",
52
- "\u001b[A\u001b[A\n",
53
- "\n",
54
- "\u001b[A\u001b[A\n",
55
- "\n",
56
- "\u001b[A\u001b[A\n",
57
- "\n",
58
- "\u001b[A\u001b[A\n",
59
- "\n",
60
- "\u001b[A\u001b[A\n",
61
- "\n",
62
- "\u001b[A\u001b[A\n",
63
- "\n",
64
- "\u001b[A\u001b[A\n",
65
- "\n",
66
- "\u001b[A\u001b[A\n",
67
- "\n",
68
- "\u001b[A\u001b[A\n",
69
- "\n",
70
- "\u001b[A\u001b[A\n",
71
- "\n",
72
- "\u001b[A\u001b[A\n",
73
- "\n",
74
- "\u001b[A\u001b[A\n",
75
- "\n",
76
- "\u001b[A\u001b[A\n",
77
- "\n",
78
- "\u001b[A\u001b[A\n",
79
- "\n",
80
- "\u001b[A\u001b[A\n",
81
- "\n",
82
- "\u001b[A\u001b[A\n",
83
- "\n",
84
- " \n",
85
- "\n",
86
- "\u001b[A\u001b[A \n",
87
- "chunk: 4%|▎ | 111/3088 [2:30:36<67:19:11, 81.41s/it, now=None]\n",
88
- " \n",
89
- "\n",
90
- "\u001b[A\u001b[A \n",
91
- "chunk: 4%|▎ | 111/3088 [2:30:36<67:19:11, 81.41s/it, now=None]\n",
92
- "\u001b[A"
93
  ]
94
  },
95
  {
@@ -105,455 +74,7 @@
105
  "name": "stderr",
106
  "output_type": "stream",
107
  "text": [
108
- "\n",
109
- "\n",
110
- "\u001b[A\u001b[A\n",
111
- "\n",
112
- "\u001b[A\u001b[A\n",
113
- "\n",
114
- "\u001b[A\u001b[A\n",
115
- "\n",
116
- "\u001b[A\u001b[A\n",
117
- "\n",
118
- "\u001b[A\u001b[A\n",
119
- "\n",
120
- "\u001b[A\u001b[A\n",
121
- "\n",
122
- "\u001b[A\u001b[A\n",
123
- "\n",
124
- "\u001b[A\u001b[A\n",
125
- "\n",
126
- "\u001b[A\u001b[A\n",
127
- "\n",
128
- "\u001b[A\u001b[A\n",
129
- "\n",
130
- "\u001b[A\u001b[A\n",
131
- "\n",
132
- "\u001b[A\u001b[A\n",
133
- "\n",
134
- "\u001b[A\u001b[A\n",
135
- "\n",
136
- "\u001b[A\u001b[A\n",
137
- "\n",
138
- "\u001b[A\u001b[A\n",
139
- "\n",
140
- "\u001b[A\u001b[A\n",
141
- "\n",
142
- "\u001b[A\u001b[A\n",
143
- "\n",
144
- "\u001b[A\u001b[A\n",
145
- "\n",
146
- "\u001b[A\u001b[A\n",
147
- "\n",
148
- "\u001b[A\u001b[A\n",
149
- "\n",
150
- "\u001b[A\u001b[A\n",
151
- "\n",
152
- "\u001b[A\u001b[A\n",
153
- "\n",
154
- "\u001b[A\u001b[A\n",
155
- "\n",
156
- "\u001b[A\u001b[A\n",
157
- "\n",
158
- "\u001b[A\u001b[A\n",
159
- "\n",
160
- "\u001b[A\u001b[A\n",
161
- "\n",
162
- "\u001b[A\u001b[A\n",
163
- "\n",
164
- "\u001b[A\u001b[A\n",
165
- "\n",
166
- "\u001b[A\u001b[A\n",
167
- "\n",
168
- "\u001b[A\u001b[A\n",
169
- "\n",
170
- "\u001b[A\u001b[A\n",
171
- "\n",
172
- "\u001b[A\u001b[A\n",
173
- "\n",
174
- "\u001b[A\u001b[A\n",
175
- "\n",
176
- "\u001b[A\u001b[A\n",
177
- "\n",
178
- "\u001b[A\u001b[A\n",
179
- "\n",
180
- "\u001b[A\u001b[A\n",
181
- "\n",
182
- "\u001b[A\u001b[A\n",
183
- "\n",
184
- "\u001b[A\u001b[A\n",
185
- "\n",
186
- "\u001b[A\u001b[A\n",
187
- "\n",
188
- "\u001b[A\u001b[A\n",
189
- "\n",
190
- "\u001b[A\u001b[A\n",
191
- "\n",
192
- "\u001b[A\u001b[A\n",
193
- "\n",
194
- "\u001b[A\u001b[A\n",
195
- "\n",
196
- "\u001b[A\u001b[A\n",
197
- "\n",
198
- "\u001b[A\u001b[A\n",
199
- "\n",
200
- "\u001b[A\u001b[A\n",
201
- "\n",
202
- "\u001b[A\u001b[A\n",
203
- "\n",
204
- "\u001b[A\u001b[A\n",
205
- "\n",
206
- "\u001b[A\u001b[A\n",
207
- "\n",
208
- "\u001b[A\u001b[A\n",
209
- "\n",
210
- "\u001b[A\u001b[A\n",
211
- "\n",
212
- "\u001b[A\u001b[A\n",
213
- "\n",
214
- "\u001b[A\u001b[A\n",
215
- "\n",
216
- "\u001b[A\u001b[A\n",
217
- "\n",
218
- "\u001b[A\u001b[A\n",
219
- "\n",
220
- "\u001b[A\u001b[A\n",
221
- "\n",
222
- "\u001b[A\u001b[A\n",
223
- "\n",
224
- "\u001b[A\u001b[A\n",
225
- "\n",
226
- "\u001b[A\u001b[A\n",
227
- "\n",
228
- "\u001b[A\u001b[A\n",
229
- "\n",
230
- "\u001b[A\u001b[A\n",
231
- "\n",
232
- "\u001b[A\u001b[A\n",
233
- "\n",
234
- "\u001b[A\u001b[A\n",
235
- "\n",
236
- "\u001b[A\u001b[A\n",
237
- "\n",
238
- "\u001b[A\u001b[A\n",
239
- "\n",
240
- "\u001b[A\u001b[A\n",
241
- "\n",
242
- "\u001b[A\u001b[A\n",
243
- "\n",
244
- "\u001b[A\u001b[A\n",
245
- "\n",
246
- "\u001b[A\u001b[A\n",
247
- "\n",
248
- "\u001b[A\u001b[A\n",
249
- "\n",
250
- "\u001b[A\u001b[A\n",
251
- "\n",
252
- "\u001b[A\u001b[A\n",
253
- "\n",
254
- "\u001b[A\u001b[A\n",
255
- "\n",
256
- "\u001b[A\u001b[A\n",
257
- "\n",
258
- "\u001b[A\u001b[A\n",
259
- "\n",
260
- "\u001b[A\u001b[A\n",
261
- "\n",
262
- "\u001b[A\u001b[A\n",
263
- "\n",
264
- "\u001b[A\u001b[A\n",
265
- "\n",
266
- "\u001b[A\u001b[A\n",
267
- "\n",
268
- "\u001b[A\u001b[A\n",
269
- "\n",
270
- "\u001b[A\u001b[A\n",
271
- "\n",
272
- "\u001b[A\u001b[A\n",
273
- "\n",
274
- "\u001b[A\u001b[A\n",
275
- "\n",
276
- "\u001b[A\u001b[A\n",
277
- "\n",
278
- "\u001b[A\u001b[A\n",
279
- "\n",
280
- "\u001b[A\u001b[A\n",
281
- "\n",
282
- "\u001b[A\u001b[A\n",
283
- "\n",
284
- "\u001b[A\u001b[A\n",
285
- "\n",
286
- "\u001b[A\u001b[A\n",
287
- "\n",
288
- "\u001b[A\u001b[A\n",
289
- "\n",
290
- "\u001b[A\u001b[A\n",
291
- "\n",
292
- "\u001b[A\u001b[A\n",
293
- "\n",
294
- "\u001b[A\u001b[A\n",
295
- "\n",
296
- "\u001b[A\u001b[A\n",
297
- "\n",
298
- "\u001b[A\u001b[A\n",
299
- "\n",
300
- "\u001b[A\u001b[A\n",
301
- "\n",
302
- "\u001b[A\u001b[A\n",
303
- "\n",
304
- "\u001b[A\u001b[A\n",
305
- "\n",
306
- "\u001b[A\u001b[A\n",
307
- "\n",
308
- "\u001b[A\u001b[A\n",
309
- "\n",
310
- "\u001b[A\u001b[A\n",
311
- "\n",
312
- "\u001b[A\u001b[A\n",
313
- "\n",
314
- "\u001b[A\u001b[A\n",
315
- "\n",
316
- "\u001b[A\u001b[A\n",
317
- "\n",
318
- "\u001b[A\u001b[A\n",
319
- "\n",
320
- "\u001b[A\u001b[A\n",
321
- "\n",
322
- "\u001b[A\u001b[A\n",
323
- "\n",
324
- "\u001b[A\u001b[A\n",
325
- "\n",
326
- "\u001b[A\u001b[A\n",
327
- "\n",
328
- "\u001b[A\u001b[A\n",
329
- "\n",
330
- "\u001b[A\u001b[A\n",
331
- "\n",
332
- "\u001b[A\u001b[A\n",
333
- "\n",
334
- "\u001b[A\u001b[A\n",
335
- "\n",
336
- "\u001b[A\u001b[A\n",
337
- "\n",
338
- "\u001b[A\u001b[A\n",
339
- "\n",
340
- "\u001b[A\u001b[A\n",
341
- "\n",
342
- "\u001b[A\u001b[A\n",
343
- "\n",
344
- "\u001b[A\u001b[A\n",
345
- "\n",
346
- "\u001b[A\u001b[A\n",
347
- "\n",
348
- "\u001b[A\u001b[A\n",
349
- "\n",
350
- "\u001b[A\u001b[A\n",
351
- "\n",
352
- "\u001b[A\u001b[A\n",
353
- "\n",
354
- "\u001b[A\u001b[A\n",
355
- "\n",
356
- "\u001b[A\u001b[A\n",
357
- "\n",
358
- "\u001b[A\u001b[A\n",
359
- "\n",
360
- "\u001b[A\u001b[A\n",
361
- "\n",
362
- "\u001b[A\u001b[A\n",
363
- "\n",
364
- "\u001b[A\u001b[A\n",
365
- "\n",
366
- "\u001b[A\u001b[A\n",
367
- "\n",
368
- "\u001b[A\u001b[A\n",
369
- "\n",
370
- "\u001b[A\u001b[A\n",
371
- "\n",
372
- "\u001b[A\u001b[A\n",
373
- "\n",
374
- "\u001b[A\u001b[A\n",
375
- "\n",
376
- "\u001b[A\u001b[A\n",
377
- "\n",
378
- "\u001b[A\u001b[A\n",
379
- "\n",
380
- "\u001b[A\u001b[A\n",
381
- "\n",
382
- "\u001b[A\u001b[A\n",
383
- "\n",
384
- "\u001b[A\u001b[A\n",
385
- "\n",
386
- "\u001b[A\u001b[A\n",
387
- "\n",
388
- "\u001b[A\u001b[A\n",
389
- "\n",
390
- "\u001b[A\u001b[A\n",
391
- "\n",
392
- "\u001b[A\u001b[A\n",
393
- "\n",
394
- "\u001b[A\u001b[A\n",
395
- "\n",
396
- "\u001b[A\u001b[A\n",
397
- "\n",
398
- "\u001b[A\u001b[A\n",
399
- "\n",
400
- "\u001b[A\u001b[A\n",
401
- "\n",
402
- "\u001b[A\u001b[A\n",
403
- "\n",
404
- "\u001b[A\u001b[A\n",
405
- "\n",
406
- "\u001b[A\u001b[A\n",
407
- "\n",
408
- "\u001b[A\u001b[A\n",
409
- "\n",
410
- "\u001b[A\u001b[A\n",
411
- "\n",
412
- "\u001b[A\u001b[A\n",
413
- "\n",
414
- "\u001b[A\u001b[A\n",
415
- "\n",
416
- "\u001b[A\u001b[A\n",
417
- "\n",
418
- "\u001b[A\u001b[A\n",
419
- "\n",
420
- "\u001b[A\u001b[A\n",
421
- "\n",
422
- "\u001b[A\u001b[A\n",
423
- "\n",
424
- "\u001b[A\u001b[A\n",
425
- "\n",
426
- "\u001b[A\u001b[A\n",
427
- "\n",
428
- "\u001b[A\u001b[A\n",
429
- "\n",
430
- "\u001b[A\u001b[A\n",
431
- "\n",
432
- "\u001b[A\u001b[A\n",
433
- "\n",
434
- "\u001b[A\u001b[A\n",
435
- "\n",
436
- "\u001b[A\u001b[A\n",
437
- "\n",
438
- "\u001b[A\u001b[A\n",
439
- "\n",
440
- "\u001b[A\u001b[A\n",
441
- "\n",
442
- "\u001b[A\u001b[A\n",
443
- "\n",
444
- "\u001b[A\u001b[A\n",
445
- "\n",
446
- "\u001b[A\u001b[A\n",
447
- "\n",
448
- "\u001b[A\u001b[A\n",
449
- "\n",
450
- "\u001b[A\u001b[A\n",
451
- "\n",
452
- "\u001b[A\u001b[A\n",
453
- "\n",
454
- "\u001b[A\u001b[A\n",
455
- "\n",
456
- "\u001b[A\u001b[A\n",
457
- "\n",
458
- "\u001b[A\u001b[A\n",
459
- "\n",
460
- "\u001b[A\u001b[A\n",
461
- "\n",
462
- "\u001b[A\u001b[A\n",
463
- "\n",
464
- "\u001b[A\u001b[A\n",
465
- "\n",
466
- "\u001b[A\u001b[A\n",
467
- "\n",
468
- "\u001b[A\u001b[A\n",
469
- "\n",
470
- "\u001b[A\u001b[A\n",
471
- "\n",
472
- "\u001b[A\u001b[A\n",
473
- "\n",
474
- "\u001b[A\u001b[A\n",
475
- "\n",
476
- "\u001b[A\u001b[A\n",
477
- "\n",
478
- "\u001b[A\u001b[A\n",
479
- "\n",
480
- "\u001b[A\u001b[A\n",
481
- "\n",
482
- "\u001b[A\u001b[A\n",
483
- "\n",
484
- "\u001b[A\u001b[A\n",
485
- "\n",
486
- "\u001b[A\u001b[A\n",
487
- "\n",
488
- "\u001b[A\u001b[A\n",
489
- "\n",
490
- "\u001b[A\u001b[A\n",
491
- "\n",
492
- "\u001b[A\u001b[A\n",
493
- "\n",
494
- "\u001b[A\u001b[A\n",
495
- "\n",
496
- "\u001b[A\u001b[A\n",
497
- "\n",
498
- "\u001b[A\u001b[A\n",
499
- "\n",
500
- "\u001b[A\u001b[A\n",
501
- "\n",
502
- "\u001b[A\u001b[A\n",
503
- "\n",
504
- "\u001b[A\u001b[A\n",
505
- "\n",
506
- "\u001b[A\u001b[A\n",
507
- "\n",
508
- "\u001b[A\u001b[A\n",
509
- "\n",
510
- "\u001b[A\u001b[A\n",
511
- "\n",
512
- "\u001b[A\u001b[A\n",
513
- "\n",
514
- "\u001b[A\u001b[A\n",
515
- "\n",
516
- "\u001b[A\u001b[A\n",
517
- "\n",
518
- "\u001b[A\u001b[A\n",
519
- "\n",
520
- "\u001b[A\u001b[A\n",
521
- "\n",
522
- "\u001b[A\u001b[A\n",
523
- "\n",
524
- "\u001b[A\u001b[A\n",
525
- "\n",
526
- "\u001b[A\u001b[A\n",
527
- "\n",
528
- "\u001b[A\u001b[A\n",
529
- "\n",
530
- "\u001b[A\u001b[A\n",
531
- "\n",
532
- "\u001b[A\u001b[A\n",
533
- "\n",
534
- "\u001b[A\u001b[A\n",
535
- "\n",
536
- "\u001b[A\u001b[A\n",
537
- "\n",
538
- "\u001b[A\u001b[A\n",
539
- "\n",
540
- "\u001b[A\u001b[A\n",
541
- "\n",
542
- "\u001b[A\u001b[A\n",
543
- "\n",
544
- "\u001b[A\u001b[A\n",
545
- "\n",
546
- "\u001b[A\u001b[A\n",
547
- "\n",
548
- " \n",
549
- "\n",
550
- "\u001b[A\u001b[A \n",
551
- "chunk: 4%|▎ | 111/3088 [2:31:01<67:30:15, 81.63s/it, now=None]\n",
552
- " \n",
553
- "\n",
554
- "\u001b[A\u001b[A \n",
555
- "chunk: 4%|▎ | 111/3088 [2:31:01<67:30:15, 81.63s/it, now=None]\n",
556
- "\u001b[A"
557
  ]
558
  },
559
  {
@@ -626,11 +147,244 @@
626
  " video.write_videofile(output_filename, audio_codec='aac')\n",
627
  "\n",
628
  "# edit_remove_part(\"videos/Ploumen.mp4\", start_s = 5.0, end_s = 10.0)\n",
629
- "edit_change_order(\"videos/Ploumen.mp4\", start_s = 5.0, end_s = 10.0, insert_s = 15.0)\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
630
  "\n",
 
 
631
  "\n"
632
  ]
633
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
634
  {
635
  "cell_type": "code",
636
  "execution_count": null,
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 5,
6
  "metadata": {},
7
  "outputs": [
8
  {
9
  "name": "stderr",
10
  "output_type": "stream",
11
  "text": [
12
+ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.ipify.org:443\n",
13
+ "DEBUG:urllib3.connectionpool:https://api.ipify.org:443 \"GET / HTTP/1.1\" 200 15\n",
14
+ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.gradio.app:443\n",
15
+ "DEBUG:urllib3.connectionpool:https://api.gradio.app:443 \"POST /gradio-initiated-analytics/ HTTP/1.1\" 200 31\n",
16
+ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.gradio.app:443\n",
17
+ "DEBUG:urllib3.connectionpool:https://api.gradio.app:443 \"POST /gradio-initiated-analytics/ HTTP/1.1\" 200 31\n",
18
+ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.gradio.app:443\n",
19
+ "DEBUG:urllib3.connectionpool:https://api.gradio.app:443 \"GET /pkg-version HTTP/1.1\" 200 20\n",
20
+ "DEBUG:asyncio:Using selector: KqueueSelector\n",
21
+ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.ipify.org:443\n"
22
  ]
23
  },
24
  {
25
  "name": "stdout",
26
  "output_type": "stream",
27
  "text": [
28
+ "Using cache from '/Users/ijanssen/videomatch/gradio_cached_examples/15' directory. If method or examples have changed since last caching, delete this folder to clear cache.\n"
 
29
  ]
30
  },
31
  {
32
  "name": "stderr",
33
  "output_type": "stream",
34
  "text": [
35
+ "DEBUG:urllib3.connectionpool:https://api.ipify.org:443 \"GET / HTTP/1.1\" 200 15\n",
36
+ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.gradio.app:443\n",
37
+ "DEBUG:urllib3.connectionpool:https://api.gradio.app:443 \"POST /gradio-initiated-analytics/ HTTP/1.1\" 200 31\n",
38
+ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.gradio.app:443\n",
39
+ "DEBUG:urllib3.connectionpool:https://api.gradio.app:443 \"POST /gradio-initiated-analytics/ HTTP/1.1\" 200 31\n",
40
+ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.gradio.app:443\n",
41
+ "DEBUG:urllib3.connectionpool:https://api.gradio.app:443 \"GET /pkg-version HTTP/1.1\" 200 20\n",
42
+ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.ipify.org:443\n",
43
+ "DEBUG:urllib3.connectionpool:https://api.ipify.org:443 \"GET / HTTP/1.1\" 200 15\n",
44
+ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.gradio.app:443\n",
45
+ "DEBUG:urllib3.connectionpool:https://api.gradio.app:443 \"POST /gradio-initiated-analytics/ HTTP/1.1\" 200 31\n"
46
  ]
47
  },
48
  {
49
  "name": "stdout",
50
  "output_type": "stream",
51
  "text": [
52
+ "Part Start = 5.0, Part Cutout = 5.0, Part Mid = 5.0, Part End = 135.03\n",
53
+ "Moviepy - Building video videos/Ploumen_CO_5.0s_to_10.0_at_15.0.mp4.\n",
54
  "MoviePy - Writing audio in Ploumen_CO_5.0s_to_10.0_at_15.0TEMP_MPY_wvf_snd.mp4\n"
55
  ]
56
  },
 
58
  "name": "stderr",
59
  "output_type": "stream",
60
  "text": [
61
+ " \r"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  ]
63
  },
64
  {
 
74
  "name": "stderr",
75
  "output_type": "stream",
76
  "text": [
77
+ " \r"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  ]
79
  },
80
  {
 
147
  " video.write_videofile(output_filename, audio_codec='aac')\n",
148
  "\n",
149
  "# edit_remove_part(\"videos/Ploumen.mp4\", start_s = 5.0, end_s = 10.0)\n",
150
+ "# edit_change_order(\"videos/Ploumen.mp4\", start_s = 5.0, end_s = 10.0, insert_s = 15.0)\n",
151
+ "\n",
152
+ "\n"
153
+ ]
154
+ },
155
+ {
156
+ "cell_type": "code",
157
+ "execution_count": 21,
158
+ "metadata": {},
159
+ "outputs": [
160
+ {
161
+ "name": "stdout",
162
+ "output_type": "stream",
163
+ "text": [
164
+ "[(51, 92), (14, 98), (64, 85), (63, 90), (63, 96)]\n",
165
+ "[112, 0, 53, 96, 123]\n"
166
+ ]
167
+ }
168
+ ],
169
+ "source": [
170
+ "\n",
171
+ "import numpy as np\n",
172
+ "\n",
173
+ "MAX = 130\n",
174
+ "\n",
175
+ "# Get some random start_s and end_s pairs where start_s is always lower than end_s\n",
176
+ "rand_start_s = np.random.randint(low=0, high=MAX, size=5)\n",
177
+ "rand_end_s = np.random.randint(low=0, high=MAX, size=5)\n",
178
+ "rand_pairs = zip(rand_start_s, rand_end_s)\n",
179
+ "rand_pairs = [(x,y) if (x < y) else (y, x) for x, y in rand_pairs]\n",
180
+ "\n",
181
+ "def get_insert_s(start_s, end_s, max=MAX):\n",
182
+ " \"\"\" Get a insert_s that is outside the start_s and end_s \"\"\"\n",
183
+ " random_choice = bool(np.random.randint(low=0, high=2, size=1)[0])\n",
184
+ " if random_choice:\n",
185
+ " return np.random.randint(low=0, high=start_s, size=1)[0]\n",
186
+ " else:\n",
187
+ " return np.random.randint(low=end_s, high=MAX, size=1)[0]\n",
188
+ "\n",
189
+ "rand_insert_s = [get_insert_s(x, y) for x, y in rand_pairs]\n",
190
  "\n",
191
+ "print(rand_pairs)\n",
192
+ "print(rand_insert_s)\n",
193
  "\n"
194
  ]
195
  },
196
+ {
197
+ "cell_type": "code",
198
+ "execution_count": 22,
199
+ "metadata": {},
200
+ "outputs": [
201
+ {
202
+ "name": "stdout",
203
+ "output_type": "stream",
204
+ "text": [
205
+ "Part Start = 51.0, Part Cutout = 41, Part Mid = 20, Part End = 38.03\n",
206
+ "Moviepy - Building video videos/Ploumen_CO_51s_to_92_at_112.mp4.\n",
207
+ "MoviePy - Writing audio in Ploumen_CO_51s_to_92_at_112TEMP_MPY_wvf_snd.mp4\n"
208
+ ]
209
+ },
210
+ {
211
+ "name": "stderr",
212
+ "output_type": "stream",
213
+ "text": [
214
+ " \r"
215
+ ]
216
+ },
217
+ {
218
+ "name": "stdout",
219
+ "output_type": "stream",
220
+ "text": [
221
+ "MoviePy - Done.\n",
222
+ "Moviepy - Writing video videos/Ploumen_CO_51s_to_92_at_112.mp4\n",
223
+ "\n"
224
+ ]
225
+ },
226
+ {
227
+ "name": "stderr",
228
+ "output_type": "stream",
229
+ "text": [
230
+ " \r"
231
+ ]
232
+ },
233
+ {
234
+ "name": "stdout",
235
+ "output_type": "stream",
236
+ "text": [
237
+ "Moviepy - Done !\n",
238
+ "Moviepy - video ready videos/Ploumen_CO_51s_to_92_at_112.mp4\n",
239
+ "Moviepy - Building video videos/Ploumen_CO_14s_to_98_at_0.mp4.\n",
240
+ "MoviePy - Writing audio in Ploumen_CO_14s_to_98_at_0TEMP_MPY_wvf_snd.mp4\n"
241
+ ]
242
+ },
243
+ {
244
+ "name": "stderr",
245
+ "output_type": "stream",
246
+ "text": [
247
+ " \r"
248
+ ]
249
+ },
250
+ {
251
+ "name": "stdout",
252
+ "output_type": "stream",
253
+ "text": [
254
+ "MoviePy - Done.\n",
255
+ "Moviepy - Writing video videos/Ploumen_CO_14s_to_98_at_0.mp4\n",
256
+ "\n"
257
+ ]
258
+ },
259
+ {
260
+ "name": "stderr",
261
+ "output_type": "stream",
262
+ "text": [
263
+ " \r"
264
+ ]
265
+ },
266
+ {
267
+ "name": "stdout",
268
+ "output_type": "stream",
269
+ "text": [
270
+ "Moviepy - Done !\n",
271
+ "Moviepy - video ready videos/Ploumen_CO_14s_to_98_at_0.mp4\n",
272
+ "Moviepy - Building video videos/Ploumen_CO_64s_to_85_at_53.mp4.\n",
273
+ "MoviePy - Writing audio in Ploumen_CO_64s_to_85_at_53TEMP_MPY_wvf_snd.mp4\n"
274
+ ]
275
+ },
276
+ {
277
+ "name": "stderr",
278
+ "output_type": "stream",
279
+ "text": [
280
+ " \r"
281
+ ]
282
+ },
283
+ {
284
+ "name": "stdout",
285
+ "output_type": "stream",
286
+ "text": [
287
+ "MoviePy - Done.\n",
288
+ "Moviepy - Writing video videos/Ploumen_CO_64s_to_85_at_53.mp4\n",
289
+ "\n"
290
+ ]
291
+ },
292
+ {
293
+ "name": "stderr",
294
+ "output_type": "stream",
295
+ "text": [
296
+ " \r"
297
+ ]
298
+ },
299
+ {
300
+ "name": "stdout",
301
+ "output_type": "stream",
302
+ "text": [
303
+ "Moviepy - Done !\n",
304
+ "Moviepy - video ready videos/Ploumen_CO_64s_to_85_at_53.mp4\n",
305
+ "Part Start = 63.0, Part Cutout = 27, Part Mid = 6, Part End = 54.03\n",
306
+ "Moviepy - Building video videos/Ploumen_CO_63s_to_90_at_96.mp4.\n",
307
+ "MoviePy - Writing audio in Ploumen_CO_63s_to_90_at_96TEMP_MPY_wvf_snd.mp4\n"
308
+ ]
309
+ },
310
+ {
311
+ "name": "stderr",
312
+ "output_type": "stream",
313
+ "text": [
314
+ " \r"
315
+ ]
316
+ },
317
+ {
318
+ "name": "stdout",
319
+ "output_type": "stream",
320
+ "text": [
321
+ "MoviePy - Done.\n",
322
+ "Moviepy - Writing video videos/Ploumen_CO_63s_to_90_at_96.mp4\n",
323
+ "\n"
324
+ ]
325
+ },
326
+ {
327
+ "name": "stderr",
328
+ "output_type": "stream",
329
+ "text": [
330
+ " \r"
331
+ ]
332
+ },
333
+ {
334
+ "name": "stdout",
335
+ "output_type": "stream",
336
+ "text": [
337
+ "Moviepy - Done !\n",
338
+ "Moviepy - video ready videos/Ploumen_CO_63s_to_90_at_96.mp4\n",
339
+ "Part Start = 63.0, Part Cutout = 33, Part Mid = 27, Part End = 27.03\n",
340
+ "Moviepy - Building video videos/Ploumen_CO_63s_to_96_at_123.mp4.\n",
341
+ "MoviePy - Writing audio in Ploumen_CO_63s_to_96_at_123TEMP_MPY_wvf_snd.mp4\n"
342
+ ]
343
+ },
344
+ {
345
+ "name": "stderr",
346
+ "output_type": "stream",
347
+ "text": [
348
+ " \r"
349
+ ]
350
+ },
351
+ {
352
+ "name": "stdout",
353
+ "output_type": "stream",
354
+ "text": [
355
+ "MoviePy - Done.\n",
356
+ "Moviepy - Writing video videos/Ploumen_CO_63s_to_96_at_123.mp4\n",
357
+ "\n"
358
+ ]
359
+ },
360
+ {
361
+ "name": "stderr",
362
+ "output_type": "stream",
363
+ "text": [
364
+ " \r"
365
+ ]
366
+ },
367
+ {
368
+ "name": "stdout",
369
+ "output_type": "stream",
370
+ "text": [
371
+ "Moviepy - Done !\n",
372
+ "Moviepy - video ready videos/Ploumen_CO_63s_to_96_at_123.mp4\n"
373
+ ]
374
+ }
375
+ ],
376
+ "source": [
377
+ "for pair, insert_s in zip(rand_pairs, rand_insert_s):\n",
378
+ " edit_change_order(\"videos/Ploumen.mp4\", start_s = pair[0], end_s = pair[1], insert_s = insert_s)"
379
+ ]
380
+ },
381
+ {
382
+ "cell_type": "code",
383
+ "execution_count": null,
384
+ "metadata": {},
385
+ "outputs": [],
386
+ "source": []
387
+ },
388
  {
389
  "cell_type": "code",
390
  "execution_count": null,