Spaces:
Build error
Build error
Iskaj
commited on
Commit
•
b117448
1
Parent(s):
3b3290d
add data generator and rename variables, clean up code
Browse files- Matching Exploration.ipynb +0 -0
- app.py +25 -6
- clip_data.ipynb +669 -0
Matching Exploration.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
app.py
CHANGED
@@ -20,10 +20,22 @@ import numpy as np
|
|
20 |
import pandas as pd
|
21 |
import faiss
|
22 |
|
|
|
|
|
23 |
FPS = 5
|
24 |
|
25 |
video_directory = tempfile.gettempdir()
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
def download_video_from_url(url):
|
28 |
"""Download video from url or return md5 hash as video name"""
|
29 |
filename = os.path.join(video_directory, hashlib.md5(url.encode()).hexdigest())
|
@@ -64,8 +76,11 @@ def compute_hashes(clip, fps=FPS):
|
|
64 |
hashed = np.array(binary_array_to_uint8s(compute_hash(frame).hash), dtype='uint8')
|
65 |
yield {"frame": 1+index*fps, "hash": hashed}
|
66 |
|
67 |
-
def index_hashes_for_video(url):
|
68 |
-
|
|
|
|
|
|
|
69 |
if os.path.exists(f'{filename}.index'):
|
70 |
logging.info(f"Loading indexed hashes from {filename}.index")
|
71 |
binary_index = faiss.read_index_binary(f'{filename}.index')
|
@@ -88,20 +103,24 @@ def index_hashes_for_video(url):
|
|
88 |
logging.info(f"Indexed hashes for {index.ntotal} frames to {filename}.index.")
|
89 |
return index
|
90 |
|
91 |
-
def compare_videos(url, target, MIN_DISTANCE = 3):
|
92 |
"""" The comparison between the target and the original video will be plotted based
|
93 |
on the matches between the target and the original video over time. The matches are determined
|
94 |
based on the minimum distance between hashes (as computed by faiss-vectors) before they're considered a match.
|
95 |
|
96 |
args:
|
97 |
-
- url: url of the source video you want to
|
98 |
-
- target: url of the target video
|
99 |
- MIN_DISTANCE: integer representing the minimum distance between hashes on bit-level before its considered a match
|
100 |
"""
|
101 |
# TODO: Fix crash if no matches are found
|
|
|
|
|
|
|
|
|
102 |
|
103 |
# Url (short video)
|
104 |
-
video_index = index_hashes_for_video(url)
|
105 |
video_index.make_direct_map() # Make sure the index is indexable
|
106 |
hash_vectors = np.array([video_index.reconstruct(i) for i in range(video_index.ntotal)]) # Retrieve original indices
|
107 |
|
|
|
20 |
import pandas as pd
|
21 |
import faiss
|
22 |
|
23 |
+
import shutil
|
24 |
+
|
25 |
FPS = 5
|
26 |
|
27 |
video_directory = tempfile.gettempdir()
|
28 |
|
29 |
+
def move_video_to_tempdir(input_dir, filename):
|
30 |
+
new_filename = os.path.join(video_directory, filename)
|
31 |
+
input_file = os.path.join(input_dir, filename)
|
32 |
+
if not os.path.exists(new_filename):
|
33 |
+
shutil.copyfile(input_file, new_filename)
|
34 |
+
logging.info(f"Copied {input_file} to {new_filename}.")
|
35 |
+
else:
|
36 |
+
logging.info(f"Skipping copying from {input_file} because {new_filename} already exists.")
|
37 |
+
return new_filename
|
38 |
+
|
39 |
def download_video_from_url(url):
|
40 |
"""Download video from url or return md5 hash as video name"""
|
41 |
filename = os.path.join(video_directory, hashlib.md5(url.encode()).hexdigest())
|
|
|
76 |
hashed = np.array(binary_array_to_uint8s(compute_hash(frame).hash), dtype='uint8')
|
77 |
yield {"frame": 1+index*fps, "hash": hashed}
|
78 |
|
79 |
+
def index_hashes_for_video(url, is_file = False):
|
80 |
+
if not is_file:
|
81 |
+
filename = download_video_from_url(url)
|
82 |
+
else:
|
83 |
+
filename = url
|
84 |
if os.path.exists(f'{filename}.index'):
|
85 |
logging.info(f"Loading indexed hashes from {filename}.index")
|
86 |
binary_index = faiss.read_index_binary(f'{filename}.index')
|
|
|
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.
|
110 |
|
111 |
args:
|
112 |
+
- url: url of the source video (short video which you want to be checked)
|
113 |
+
- target: url of the target video (longer video which is a superset of the source video)
|
114 |
- MIN_DISTANCE: integer representing the minimum distance between hashes on bit-level before its considered a match
|
115 |
"""
|
116 |
# TODO: Fix crash if no matches are found
|
117 |
+
if url.endswith('dl=1'):
|
118 |
+
is_file = False
|
119 |
+
elif url.endswith('.mp4'):
|
120 |
+
is_file = True
|
121 |
|
122 |
# Url (short video)
|
123 |
+
video_index = index_hashes_for_video(url, is_file)
|
124 |
video_index.make_direct_map() # Make sure the index is indexable
|
125 |
hash_vectors = np.array([video_index.reconstruct(i) for i in range(video_index.ntotal)]) # Retrieve original indices
|
126 |
|
clip_data.ipynb
ADDED
@@ -0,0 +1,669 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
{
|
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 |
+
},
|
46 |
+
{
|
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 |
+
{
|
96 |
+
"name": "stdout",
|
97 |
+
"output_type": "stream",
|
98 |
+
"text": [
|
99 |
+
"MoviePy - Done.\n",
|
100 |
+
"Moviepy - Writing video videos/Ploumen_CO_5.0s_to_10.0_at_15.0.mp4\n",
|
101 |
+
"\n"
|
102 |
+
]
|
103 |
+
},
|
104 |
+
{
|
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 |
+
{
|
560 |
+
"name": "stdout",
|
561 |
+
"output_type": "stream",
|
562 |
+
"text": [
|
563 |
+
"Moviepy - Done !\n",
|
564 |
+
"Moviepy - video ready videos/Ploumen_CO_5.0s_to_10.0_at_15.0.mp4\n"
|
565 |
+
]
|
566 |
+
}
|
567 |
+
],
|
568 |
+
"source": [
|
569 |
+
"import moviepy\n",
|
570 |
+
"from moviepy.editor import concatenate_videoclips\n",
|
571 |
+
"from moviepy.video.io.VideoFileClip import VideoFileClip\n",
|
572 |
+
"from moviepy.audio.io.AudioFileClip import AudioFileClip\n",
|
573 |
+
"from moviepy.audio.AudioClip import CompositeAudioClip\n",
|
574 |
+
"\n",
|
575 |
+
"from app import change_ffmpeg_fps\n",
|
576 |
+
"\n",
|
577 |
+
"def add_logo(input_clip, output_clip_name, logo_file_name, logo_duration, position=(\"right\", \"top\")):\n",
|
578 |
+
" logo = (moviepy.ImageClip(logo_file_name)\n",
|
579 |
+
" .set_duration(logo_duration)\n",
|
580 |
+
" .resize(height=50) # if you need to resize...\n",
|
581 |
+
" .margin(right=8, top=8, opacity=0) # (optional) logo-border padding\n",
|
582 |
+
" .set_pos(position))\n",
|
583 |
+
"\n",
|
584 |
+
" output_clip = moviepy.CompositeVideoClip([input_clip, logo])\n",
|
585 |
+
" output_clip.write_videofile(output_clip_name)\n",
|
586 |
+
" return output_clip\n",
|
587 |
+
"\n",
|
588 |
+
"def edit_remove_part(input_filename, start_s, end_s, FPS=5):\n",
|
589 |
+
" \"\"\"Remove a segment of an .mp4 by and change its FPS. Keeps the audio intact by audio_codec='aac' parameter\"\"\"\n",
|
590 |
+
" # input_video = change_ffmpeg_fps(VideoFileClip(input_filename), fps=FPS) # Load video and change fps for faster processing\n",
|
591 |
+
" input_filename_no_ext, ext = input_filename.split('.')\n",
|
592 |
+
" input_video = VideoFileClip(input_filename)\n",
|
593 |
+
"\n",
|
594 |
+
" # Remove part video and return result\n",
|
595 |
+
" video = input_video.cutout(start_s, end_s)\n",
|
596 |
+
"\n",
|
597 |
+
" # Write Video\n",
|
598 |
+
" output_filename = input_filename_no_ext + f\"_RM_{start_s}s_to_{end_s}.{ext}\"\n",
|
599 |
+
" video.write_videofile(output_filename, audio_codec='aac')\n",
|
600 |
+
"\n",
|
601 |
+
"def edit_change_order(input_filename, start_s, end_s, insert_s, FPS=5):\n",
|
602 |
+
" \"\"\"Take start_s to end_s out of the video and insert it at insert_s. Keeps the audio intact by audio_codec='aac' parameter\"\"\"\n",
|
603 |
+
" # input_video = change_ffmpeg_fps(VideoFileClip(input_filename), fps=FPS) # Load video and change fps for faster processing\n",
|
604 |
+
" input_filename_no_ext, ext = input_filename.split('.')\n",
|
605 |
+
" input_video = VideoFileClip(input_filename)\n",
|
606 |
+
" assert not (insert_s > start_s and insert_s < end_s), \"Insert time can't be in cutout time!\"\n",
|
607 |
+
" assert (end_s > start_s), \"End_s should be higher than start_s!\"\n",
|
608 |
+
"\n",
|
609 |
+
" # Cut out a part and insert it somewhere else\n",
|
610 |
+
" if insert_s < start_s and insert_s < end_s:\n",
|
611 |
+
" part_start = input_video.subclip(0.0, insert_s)\n",
|
612 |
+
" part_cutout = input_video.subclip(start_s, end_s)\n",
|
613 |
+
" part_mid = input_video.subclip(insert_s, start_s)\n",
|
614 |
+
" part_end = input_video.subclip(end_s, input_video.duration)\n",
|
615 |
+
" video = concatenate_videoclips([part_start, part_cutout, part_mid, part_end])\n",
|
616 |
+
" elif insert_s > start_s and insert_s > end_s:\n",
|
617 |
+
" part_start = input_video.subclip(0.0, start_s)\n",
|
618 |
+
" part_cutout = input_video.subclip(start_s, end_s)\n",
|
619 |
+
" part_mid = input_video.subclip(end_s, insert_s)\n",
|
620 |
+
" part_end = input_video.subclip(insert_s, input_video.duration)\n",
|
621 |
+
" print(f\"Part Start = {part_start.duration}, Part Cutout = {part_cutout.duration}, Part Mid = {part_mid.duration}, Part End = {part_end.duration}\")\n",
|
622 |
+
" video = concatenate_videoclips([part_start, part_mid, part_cutout, part_end])\n",
|
623 |
+
"\n",
|
624 |
+
" # Write Video\n",
|
625 |
+
" output_filename = input_filename_no_ext + f\"_CO_{start_s}s_to_{end_s}_at_{insert_s}.{ext}\"\n",
|
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,
|
637 |
+
"metadata": {},
|
638 |
+
"outputs": [],
|
639 |
+
"source": []
|
640 |
+
}
|
641 |
+
],
|
642 |
+
"metadata": {
|
643 |
+
"kernelspec": {
|
644 |
+
"display_name": "Python 3.9.13 64-bit",
|
645 |
+
"language": "python",
|
646 |
+
"name": "python3"
|
647 |
+
},
|
648 |
+
"language_info": {
|
649 |
+
"codemirror_mode": {
|
650 |
+
"name": "ipython",
|
651 |
+
"version": 3
|
652 |
+
},
|
653 |
+
"file_extension": ".py",
|
654 |
+
"mimetype": "text/x-python",
|
655 |
+
"name": "python",
|
656 |
+
"nbconvert_exporter": "python",
|
657 |
+
"pygments_lexer": "ipython3",
|
658 |
+
"version": "3.9.13"
|
659 |
+
},
|
660 |
+
"orig_nbformat": 4,
|
661 |
+
"vscode": {
|
662 |
+
"interpreter": {
|
663 |
+
"hash": "397704579725e15f5c7cb49fe5f0341eb7531c82d19f2c29d197e8b64ab5776b"
|
664 |
+
}
|
665 |
+
}
|
666 |
+
},
|
667 |
+
"nbformat": 4,
|
668 |
+
"nbformat_minor": 2
|
669 |
+
}
|