fffiloni commited on
Commit
d17fb07
·
1 Parent(s): b9d1cfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -30
app.py CHANGED
@@ -37,38 +37,22 @@ def get_video_dimension(filepath):
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 / new_width))
50
-
51
-
52
- # Adjust height to be a multiple of 32
53
- while new_height % 32 != 0:
54
- new_height += 1
55
-
56
- return new_width, new_height
57
-
58
  def resize_video(input_path, output_path, target_width):
59
  # Load the video clip
60
- video = VideoFileClip(input_path)
61
 
62
- # Calculate the new dimensions while maintaining the aspect ratio and multiples of 32
63
- new_width, new_height = get_new_dimensions(target_width, video.size[1])
 
64
 
65
- # Resize the video
66
- resized_video = video.resize(width=new_width, height=new_height)
67
 
68
- # Write the resized video to the output path
69
- resized_video.write_videofile(output_path, codec='libx264')
70
 
71
- return output_path
 
72
 
73
  def run_inference(prompt, video_path, condition, video_length):
74
 
@@ -77,8 +61,8 @@ def run_inference(prompt, video_path, condition, video_length):
77
  resized_vid = 'resized.mp4'
78
 
79
  # Call the function to resize the video
80
- video_path = resize_video(input_vid, resized_vid, target_width=512)
81
- width, height, fps = get_video_dimension(video_path)
82
 
83
  print(f"{width} x {height} | {fps}")
84
 
@@ -94,9 +78,9 @@ def run_inference(prompt, video_path, condition, video_length):
94
  os.remove(video_path_output)
95
 
96
  if video_length > 12:
97
- command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{video_path}' --output_path '{output_path}' --width {width} --height {height} --fps {fps} --video_length {video_length} --is_long_video"
98
  else:
99
- command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{video_path}' --output_path '{output_path}' --width {width} --height {height} --fps {fps} --video_length {video_length}"
100
  subprocess.run(command, shell=True)
101
 
102
  # Construct the video path
 
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
  def run_inference(prompt, video_path, condition, video_length):
58
 
 
61
  resized_vid = 'resized.mp4'
62
 
63
  # Call the function to resize the video
64
+ resized_video_path = resize_video(input_vid, resized_vid, target_width=512)
65
+ width, height, fps = get_video_dimension(resized_video_path)
66
 
67
  print(f"{width} x {height} | {fps}")
68
 
 
78
  os.remove(video_path_output)
79
 
80
  if video_length > 12:
81
+ command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{resized_video_path}' --output_path '{output_path}' --width {width} --height {height} --fps {fps} --video_length {video_length} --is_long_video"
82
  else:
83
+ command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{resized_video_path}' --output_path '{output_path}' --width {width} --height {height} --fps {fps} --video_length {video_length}"
84
  subprocess.run(command, shell=True)
85
 
86
  # Construct the video path