fffiloni commited on
Commit
76c1a8a
·
1 Parent(s): ba65f56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -37,15 +37,32 @@ def get_video_dimension(filepath):
37
  video.release()
38
  return width, height, fps
39
 
40
- def resize_video(input_path, output_path, width):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  # Load the video clip
42
  video = VideoFileClip(input_path)
43
 
44
- # Calculate the new height while maintaining the aspect ratio
45
- height = int(video.size[1] * (width / video.size[0]))
46
 
47
  # Resize the video
48
- resized_video = video.resize(width=width, height=512)
49
 
50
  # Write the resized video to the output path
51
  resized_video.write_videofile(output_path, codec='libx264')
 
37
  video.release()
38
  return width, height, fps
39
 
40
+ def get_new_dimensions(width, height):
41
+ new_width = width
42
+ new_height = height
43
+
44
+ # Adjust width to be a multiple of 32
45
+ while new_width % 32 != 0:
46
+ new_width += 1
47
+
48
+ # Adjust height to maintain the aspect ratio
49
+ new_height = int(new_width * (height / width))
50
+
51
+ # Adjust height to be a multiple of 32
52
+ while new_height % 32 != 0:
53
+ new_height += 1
54
+
55
+ return new_width, new_height
56
+
57
+ def resize_video(input_path, output_path, target_width):
58
  # Load the video clip
59
  video = VideoFileClip(input_path)
60
 
61
+ # Calculate the new dimensions while maintaining the aspect ratio and multiples of 32
62
+ new_width, new_height = get_new_dimensions(video.size[0], video.size[1])
63
 
64
  # Resize the video
65
+ resized_video = video.resize(width=new_width, height=new_height)
66
 
67
  # Write the resized video to the output path
68
  resized_video.write_videofile(output_path, codec='libx264')