fffiloni commited on
Commit
449e320
·
1 Parent(s): 90e6ba4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -37,24 +37,33 @@ def get_video_dimension(filepath):
37
  video.release()
38
  return width, height, fps
39
 
40
- def resize_video(input_path, output_path, target_width):
 
 
 
 
 
 
 
41
  # Load the video clip
42
- clip = VideoFileClip(input_path)
43
 
44
- # Calculate the new dimensions while maintaining the aspect ratio
45
- target_height = int(clip.size[1] * target_width / clip.size[0])
46
- target_height = target_height + (32 - target_height % 32) if target_height % 32 != 0 else target_height
 
 
47
 
48
  # Resize the video clip
49
- resized_clip = clip.resize(width=target_width, height=target_height)
50
 
51
- # Write the resized video to the output file
52
- resized_clip.write_videofile(output_path, codec='libx264')
53
 
54
  # Close the video clip
55
  clip.close()
56
 
57
- return output_path
58
 
59
  def run_inference(prompt, video_path, condition, video_length):
60
 
 
37
  video.release()
38
  return width, height, fps
39
 
40
+ def adjust_to_multiple_of_12(number):
41
+ remainder = number % 12
42
+ if remainder != 0:
43
+ adjustment = 12 - remainder
44
+ number += adjustment
45
+ return number
46
+
47
+ def resize_video(input_file, output_file, new_width):
48
  # Load the video clip
49
+ clip = VideoFileClip(input_file)
50
 
51
+ # Calculate the aspect ratio
52
+ ratio = new_width / clip.size[0]
53
+ new_height = int(clip.size[1] * ratio)
54
+ new_height_adjusted = adjust_to_multiple_of_12(new_height)
55
+ print(f"OLD H: {new_height} | NEW H: {new_height_adjusted}")
56
 
57
  # Resize the video clip
58
+ resized_clip = clip.resize(width=new_width, height=new_height_adjusted)
59
 
60
+ # Write the resized video to a file
61
+ resized_clip.write_videofile(output_file, codec="libx264")
62
 
63
  # Close the video clip
64
  clip.close()
65
 
66
+ return output_file
67
 
68
  def run_inference(prompt, video_path, condition, video_length):
69