Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,11 +50,18 @@ def run_inference(prompt, video_path, condition, video_length):
|
|
| 50 |
chunk_size = 12
|
| 51 |
chunks = cut_mp4_into_chunks(video_path, chunk_size)
|
| 52 |
|
|
|
|
|
|
|
| 53 |
output_path = 'output/'
|
| 54 |
os.makedirs(output_path, exist_ok=True)
|
| 55 |
|
| 56 |
# Accessing chunks and frame counts by index
|
| 57 |
for i, (chunk, frame_count) in enumerate(chunks):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
chunk.write_videofile(f'chunk_{i}.mp4') # Saving the chunk to a file
|
| 59 |
chunk_path = f'chunk_{i}.mp4'
|
| 60 |
print(f"Chunk {i}: Frame Count = {frame_count}")
|
|
@@ -62,6 +69,26 @@ def run_inference(prompt, video_path, condition, video_length):
|
|
| 62 |
command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{chunk_path}' --output_path '{output_path}' --video_length {frame_count}"
|
| 63 |
subprocess.run(command, shell=True)
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
def working_run_inference(prompt, video_path, condition, video_length):
|
| 66 |
|
| 67 |
|
|
|
|
| 50 |
chunk_size = 12
|
| 51 |
chunks = cut_mp4_into_chunks(video_path, chunk_size)
|
| 52 |
|
| 53 |
+
processed_chunks = []
|
| 54 |
+
|
| 55 |
output_path = 'output/'
|
| 56 |
os.makedirs(output_path, exist_ok=True)
|
| 57 |
|
| 58 |
# Accessing chunks and frame counts by index
|
| 59 |
for i, (chunk, frame_count) in enumerate(chunks):
|
| 60 |
+
# Check if the file already exists
|
| 61 |
+
if os.path.exists(os.path.join(output_path, f"{prompt}.mp4")):
|
| 62 |
+
# Delete the existing file
|
| 63 |
+
os.remove(video_path_output)
|
| 64 |
+
|
| 65 |
chunk.write_videofile(f'chunk_{i}.mp4') # Saving the chunk to a file
|
| 66 |
chunk_path = f'chunk_{i}.mp4'
|
| 67 |
print(f"Chunk {i}: Frame Count = {frame_count}")
|
|
|
|
| 69 |
command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{chunk_path}' --output_path '{output_path}' --video_length {frame_count}"
|
| 70 |
subprocess.run(command, shell=True)
|
| 71 |
|
| 72 |
+
# Construct the video path
|
| 73 |
+
video_path_output = os.path.join(output_path, f"{prompt}.mp4")
|
| 74 |
+
|
| 75 |
+
# rename
|
| 76 |
+
new_file_name = os.path.join(output_path, f"new_file_name_{i}.mp4")
|
| 77 |
+
os.rename(video_path_output, new_file_name)
|
| 78 |
+
processed_chunks.append(new_file_name)
|
| 79 |
+
|
| 80 |
+
output_path = "final_video.mp4"
|
| 81 |
+
clips = []
|
| 82 |
+
for path in processed_chunks:
|
| 83 |
+
clip = VideoFileClip(path)
|
| 84 |
+
clips.append(clip)
|
| 85 |
+
|
| 86 |
+
final_clip = concatenate_videoclips(clips)
|
| 87 |
+
final_clip.write_videofile(output_path, codec="libx264")
|
| 88 |
+
final_clip.close()
|
| 89 |
+
|
| 90 |
+
return "done", "final_video.mp4"
|
| 91 |
+
|
| 92 |
def working_run_inference(prompt, video_path, condition, video_length):
|
| 93 |
|
| 94 |
|