Skip to content

Commit 01de956

Browse files
GH-15: Collect the dependencies into the requirements.txt (GH-22)
* Fix the time format at VTT for floating intervals * Specify the dependencies in the requirements.txt * Remove `numpy` from dependencies
1 parent db5495c commit 01de956

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
imageio-ffmpeg>=0.4.7
2+
imageio>=2.23.0
3+
pillow>=8.4.0

thumbnails.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Read from the program arguments.
66
compress = 1
7-
interval = 20
7+
interval = .5
88
basepath = "/stc/"
99

1010
files = ["valerian-1080p.avi", "valerian-1080p.mkv", "valerian-1080p.mov", "valerian-1080p.mp4",

thumbnails/thumbnails.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@
88

99
from PIL import Image
1010
from imageio_ffmpeg import get_ffmpeg_exe
11-
from numpy import arange
1211

1312
from .ffmpeg import _FFMpeg
1413

1514
ffmpeg_bin = get_ffmpeg_exe()
1615

1716

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+
1827
class _ThumbnailMixin:
1928
def __init__(self, size):
2029
self._w = None
@@ -99,7 +108,7 @@ def _calc_columns(frames_count, width, height):
99108

100109
def _extract_frame(self, start_time):
101110
_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)
103112
_timestamp = str(timedelta(seconds=start_time))
104113

105114
cmd = (
@@ -124,7 +133,7 @@ def join_frames(self):
124133
frames = sorted(glob.glob(self.tempdir.name + os.sep + "*.png"))
125134
frames_count = len(arange(0, self.duration, self.interval))
126135
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)
128137
master = Image.new(mode="RGBA", size=(self.width * columns, master_height))
129138

130139
for n, frame in enumerate(frames):
@@ -148,8 +157,9 @@ def join_frames(self):
148157
self.tempdir.cleanup()
149158

150159
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]
153163

154164
_lines = ["WEBVTT\n\n"]
155165
_img_src = self.basepath + self._image_name

0 commit comments

Comments
 (0)