8
8
9
9
from PIL import Image
10
10
from imageio_ffmpeg import get_ffmpeg_exe
11
- from numpy import arange
12
11
13
12
from .ffmpeg import _FFMpeg
14
13
15
14
ffmpeg_bin = get_ffmpeg_exe ()
16
15
17
16
17
+ def arange (start , stop , step ):
18
+ def _generator ():
19
+ nonlocal start
20
+ while start < stop :
21
+ yield start
22
+ start += step
23
+
24
+ return tuple (_generator ())
25
+
26
+
18
27
class _ThumbnailMixin :
19
28
def __init__ (self , size ):
20
29
self ._w = None
@@ -99,7 +108,7 @@ def _calc_columns(frames_count, width, height):
99
108
100
109
def _extract_frame (self , start_time ):
101
110
_input_file = self .filename
102
- _output_file = "%s/%d -%s.png" % (self .tempdir .name , start_time , self .filename )
111
+ _output_file = "%s/%s -%s.png" % (self .tempdir .name , start_time , self .filename )
103
112
_timestamp = str (timedelta (seconds = start_time ))
104
113
105
114
cmd = (
@@ -124,7 +133,7 @@ def join_frames(self):
124
133
frames = sorted (glob .glob (self .tempdir .name + os .sep + "*.png" ))
125
134
frames_count = len (arange (0 , self .duration , self .interval ))
126
135
columns = self ._calc_columns (frames_count , self .width , self .height )
127
- master_height = self .height * int ( math .ceil (float ( frames_count ) / columns ) )
136
+ master_height = self .height * math .ceil (frames_count / columns )
128
137
master = Image .new (mode = "RGBA" , size = (self .width * columns , master_height ))
129
138
130
139
for n , frame in enumerate (frames ):
@@ -148,8 +157,9 @@ def join_frames(self):
148
157
self .tempdir .cleanup ()
149
158
150
159
def to_vtt (self ):
151
- def _format_time (seconds ):
152
- return "0%s.000" % str (timedelta (seconds = seconds ))
160
+ def _format_time (secs ):
161
+ delta = timedelta (seconds = secs )
162
+ return ("0%s.000" % delta )[:12 ]
153
163
154
164
_lines = ["WEBVTT\n \n " ]
155
165
_img_src = self .basepath + self ._image_name
0 commit comments