Spaces:
Runtime error
Runtime error
Delete test.py
Browse files
test.py
DELETED
@@ -1,34 +0,0 @@
|
|
1 |
-
import av
|
2 |
-
import time
|
3 |
-
|
4 |
-
def sample(N, K):
|
5 |
-
array = list(range(N))
|
6 |
-
length = len(array)
|
7 |
-
if K >= length or K<2:
|
8 |
-
return array
|
9 |
-
|
10 |
-
k = length // K
|
11 |
-
sampled_points = [array[i] for i in range(0, length, k)][:K-1]
|
12 |
-
sampled_points.append(array[-1])
|
13 |
-
return sampled_points
|
14 |
-
|
15 |
-
start = time.time()
|
16 |
-
|
17 |
-
with av.open('/Users/monius/Documents/YueZhang/Video/Sora/1.mp4') as container:
|
18 |
-
frames = []
|
19 |
-
src = container.streams.video[0]
|
20 |
-
time_base = src.time_base
|
21 |
-
framerate = src.average_rate
|
22 |
-
N = src.frames
|
23 |
-
K = 10
|
24 |
-
|
25 |
-
for i in sample(N, K):
|
26 |
-
n = round((i / framerate) / time_base)
|
27 |
-
container.seek(n, backward=True, stream=src)
|
28 |
-
frame = next(container.decode(video=0))
|
29 |
-
im = frame.to_image()
|
30 |
-
frames.append(im)
|
31 |
-
|
32 |
-
elapsed = time.time() - start
|
33 |
-
|
34 |
-
print(elapsed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|