Skip to content

Commit 57f2d61

Browse files
committed
GH-61: Use -vf (video filters) option to resize the image
1 parent 31c2b53 commit 57f2d61

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/thumbnails/thumbnail.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ def prepare_frames(self):
108108
offset = extract_name(frame).replace("-", ":").split(".")[0]
109109
progress.update("Processing [bold]%s[/bold] frame" % offset)
110110
with Image.open(frame) as image:
111-
image = image.resize((self.width, self.height), Image.ANTIALIAS)
112111
master.paste(image, (x, y))
113112

114113
with Progress("Saving the result at '%s'" % master_path):
@@ -158,17 +157,15 @@ def generate(self):
158157
with Progress("Saving thumbnail metadata at '%s'" % self.metadata_path):
159158
for frame, start, *_ in self.thumbnails():
160159
frame = os.path.join(self.thumbnail_dir, os.path.basename(frame))
161-
with Image.open(frame) as image:
162-
image.resize((self.width, self.height), Image.ANTIALIAS).save(frame)
163-
base = os.path.join(self.base, os.path.basename(self.thumbnail_dir))
164-
prefix = base if self.base else os.path.relpath(self.thumbnail_dir)
165-
route = os.path.join(prefix, os.path.basename(frame))
166-
route = pathlib.Path(route).as_posix()
167-
thumbnail_data = {
168-
"src": route,
169-
"width": "%spx" % self.width,
170-
}
171-
metadata[int(start)] = thumbnail_data
160+
base = os.path.join(self.base, os.path.basename(self.thumbnail_dir))
161+
prefix = base if self.base else os.path.relpath(self.thumbnail_dir)
162+
route = os.path.join(prefix, os.path.basename(frame))
163+
route = pathlib.Path(route).as_posix()
164+
thumbnail_data = {
165+
"src": route,
166+
"width": "%spx" % self.width,
167+
}
168+
metadata[int(start)] = thumbnail_data
172169

173170
with open(self.metadata_path, "w") as fp:
174171
json.dump(metadata, fp, indent=2)

src/thumbnails/video.py

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def _extract_frame(self, start_time):
9292
"-i", self.filepath,
9393
"-loglevel", "error",
9494
"-vframes", "1",
95+
"-vf", "scale=%d:%d" % (self.width, self.height),
9596
output,
9697
"-y",
9798
)

0 commit comments

Comments
 (0)