Spaces:
Runtime error
Runtime error
Linoy Tsaban
commited on
Commit
·
8c6a211
1
Parent(s):
e9ae397
Update utils.py
Browse filespadding and aspect ratio changes
utils.py
CHANGED
|
@@ -40,6 +40,15 @@ def video_to_frames(video_path, img_size=(512,512)):
|
|
| 40 |
for i in range(len(video)):
|
| 41 |
ind = str(i).zfill(5)
|
| 42 |
image = T.ToPILImage()(video[i])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
image_resized = image.resize((img_size), resample=Image.Resampling.LANCZOS)
|
| 44 |
# image_resized.save(f'data/{video_name}/{ind}.png')
|
| 45 |
frames.append(image_resized)
|
|
|
|
| 40 |
for i in range(len(video)):
|
| 41 |
ind = str(i).zfill(5)
|
| 42 |
image = T.ToPILImage()(video[i])
|
| 43 |
+
|
| 44 |
+
# get new height and width to maintain aspect ratio
|
| 45 |
+
height, width = image.shape
|
| 46 |
+
new_height = img_size[0] * height / width
|
| 47 |
+
new_width = img_size[1] * width / height
|
| 48 |
+
|
| 49 |
+
# pad
|
| 50 |
+
image = Image.new(image.mode, (new_width, new_height), (0, 0, 0))
|
| 51 |
+
|
| 52 |
image_resized = image.resize((img_size), resample=Image.Resampling.LANCZOS)
|
| 53 |
# image_resized.save(f'data/{video_name}/{ind}.png')
|
| 54 |
frames.append(image_resized)
|