Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -30,66 +30,8 @@ def get_frame_count_in_duration(filepath):
|
|
30 |
return gr.update(maximum=frame_count)
|
31 |
|
32 |
|
33 |
-
def cut_mp4_into_chunks(input_file, chunk_size):
|
34 |
-
video = VideoFileClip(input_file)
|
35 |
-
frame_count = int(video.fps * video.duration)
|
36 |
-
num_chunks = (frame_count + chunk_size - 1) // chunk_size # Ceiling division
|
37 |
-
|
38 |
-
chunks = []
|
39 |
-
|
40 |
-
for i in range(num_chunks):
|
41 |
-
start_frame = i * chunk_size
|
42 |
-
end_frame = min((i + 1) * chunk_size, frame_count)
|
43 |
-
chunk = video.subclip(start_frame / video.fps, end_frame / video.fps)
|
44 |
-
chunk_frame_count = end_frame - start_frame
|
45 |
-
chunks.append((chunk, chunk_frame_count))
|
46 |
-
|
47 |
-
return chunks
|
48 |
-
|
49 |
-
def run_inference(prompt, video_path, condition, video_length):
|
50 |
-
chunk_size = 6
|
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}")
|
68 |
-
|
69 |
-
command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path 'chunk_{i}.mp4' --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
|
93 |
|
94 |
|
95 |
output_path = 'output/'
|
|
|
30 |
return gr.update(maximum=frame_count)
|
31 |
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
def run_inference(prompt, video_path, condition, video_length):
|
35 |
|
36 |
|
37 |
output_path = 'output/'
|