Spaces:
Paused
Paused
Update app.py
Browse files
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 |
-
|
| 61 |
|
| 62 |
-
# Calculate the new dimensions while maintaining the aspect ratio
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
-
# Resize the video
|
| 66 |
-
|
| 67 |
|
| 68 |
-
# Write the resized video to the output
|
| 69 |
-
|
| 70 |
|
| 71 |
-
|
|
|
|
| 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 |
-
|
| 81 |
-
width, height, fps = get_video_dimension(
|
| 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 '{
|
| 98 |
else:
|
| 99 |
-
command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{
|
| 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
|