Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,6 +29,16 @@ def get_frame_count_in_duration(filepath):
|
|
| 29 |
video.release()
|
| 30 |
return gr.update(maximum=frame_count)
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Function to split video into chunks
|
| 34 |
def split_video_into_chunks(video_path, chunk_size):
|
|
@@ -93,11 +103,12 @@ def run_inference(prompt, video_path, condition, video_length):
|
|
| 93 |
# Split the video into chunks
|
| 94 |
video_chunks = split_video_into_chunks(video_path, chunk_size)
|
| 95 |
|
| 96 |
-
# Process each chunk and store the processed chunk filenames
|
| 97 |
-
|
| 98 |
-
for i, chunk in enumerate(video_chunks):
|
|
|
|
| 99 |
# Count the frame number of the video chunk
|
| 100 |
-
frame_count = len(chunk)
|
| 101 |
command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{chunk}' --output_path '{output_path}' --video_length {frame_count} --smoother_steps 19 20"
|
| 102 |
subprocess.run(command, shell=True)
|
| 103 |
|
|
@@ -105,10 +116,11 @@ def run_inference(prompt, video_path, condition, video_length):
|
|
| 105 |
video_path_output = os.path.join(output_path, f"{prompt}_{i}.mp4")
|
| 106 |
|
| 107 |
processed_chunk_filename = video_path_output
|
| 108 |
-
processed_chunk_filenames.append(processed_chunk_filename)
|
|
|
|
| 109 |
|
| 110 |
# Load the processed video chunks
|
| 111 |
-
processed_chunks = [VideoFileClip(filename) for filename in
|
| 112 |
|
| 113 |
# Concatenate the processed video chunks into a final video
|
| 114 |
final_video = concatenate_videoclips(processed_chunks)
|
|
@@ -117,7 +129,7 @@ def run_inference(prompt, video_path, condition, video_length):
|
|
| 117 |
final_video.write_videofile('final_video.mp4')
|
| 118 |
|
| 119 |
# Clean up the temporary processed chunk files (optional)
|
| 120 |
-
for filename in
|
| 121 |
os.remove(filename)
|
| 122 |
|
| 123 |
return "done", 'final_video.mp4'
|
|
|
|
| 29 |
video.release()
|
| 30 |
return gr.update(maximum=frame_count)
|
| 31 |
|
| 32 |
+
# Function to process a video chunk and return the processed video
|
| 33 |
+
def process_video_chunk(chunk, index):
|
| 34 |
+
# Count the frame number of the video chunk
|
| 35 |
+
frame_count = len(chunk)
|
| 36 |
+
|
| 37 |
+
# Export the processed chunk to a file with the index in the file name
|
| 38 |
+
processed_chunk_filename = f'processed_chunk_{index}.mp4'
|
| 39 |
+
processed_chunk.write_videofile(processed_chunk_filename)
|
| 40 |
+
|
| 41 |
+
return processed_chunk_filename, frame_count
|
| 42 |
|
| 43 |
# Function to split video into chunks
|
| 44 |
def split_video_into_chunks(video_path, chunk_size):
|
|
|
|
| 103 |
# Split the video into chunks
|
| 104 |
video_chunks = split_video_into_chunks(video_path, chunk_size)
|
| 105 |
|
| 106 |
+
# Process each chunk and store the processed chunk filenames and frame counts
|
| 107 |
+
processed_chunk_info = []
|
| 108 |
+
for i, (chunk, _) in enumerate(video_chunks):
|
| 109 |
+
processed_chunk_filename, frame_count = process_video_chunk(chunk, i)
|
| 110 |
# Count the frame number of the video chunk
|
| 111 |
+
#frame_count = len(chunk)
|
| 112 |
command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{chunk}' --output_path '{output_path}' --video_length {frame_count} --smoother_steps 19 20"
|
| 113 |
subprocess.run(command, shell=True)
|
| 114 |
|
|
|
|
| 116 |
video_path_output = os.path.join(output_path, f"{prompt}_{i}.mp4")
|
| 117 |
|
| 118 |
processed_chunk_filename = video_path_output
|
| 119 |
+
#processed_chunk_filenames.append(processed_chunk_filename)
|
| 120 |
+
processed_chunk_info.append((processed_chunk_filename, frame_count))
|
| 121 |
|
| 122 |
# Load the processed video chunks
|
| 123 |
+
processed_chunks = [VideoFileClip(filename) for filename, _ in processed_chunk_info]
|
| 124 |
|
| 125 |
# Concatenate the processed video chunks into a final video
|
| 126 |
final_video = concatenate_videoclips(processed_chunks)
|
|
|
|
| 129 |
final_video.write_videofile('final_video.mp4')
|
| 130 |
|
| 131 |
# Clean up the temporary processed chunk files (optional)
|
| 132 |
+
for filename, _ in processed_chunk_info:
|
| 133 |
os.remove(filename)
|
| 134 |
|
| 135 |
return "done", 'final_video.mp4'
|