Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -30,10 +30,39 @@ def get_frame_count_in_duration(filepath):
|
|
30 |
return gr.update(maximum=frame_count)
|
31 |
|
32 |
|
|
|
|
|
|
|
|
|
33 |
|
|
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def run_inference(prompt, video_path, condition, video_length):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
|
39 |
output_path = 'output/'
|
|
|
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 = 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}")
|
61 |
+
|
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 |
|
68 |
output_path = 'output/'
|