Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -87,20 +87,16 @@ def fn(vid, bg_type="Color", bg_image=None, bg_video=None, color="#00FF00", fps=
|
|
87 |
|
88 |
processed_video = mp.ImageSequenceClip(processed_frames, fps=fps)
|
89 |
processed_video = processed_video.set_audio(audio)
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
94 |
|
95 |
elapsed_time = time.time() - start_time
|
96 |
yield gr.update(visible=False), gr.update(visible=True), f"Processing complete! Elapsed time: {elapsed_time:.2f} seconds"
|
97 |
|
98 |
-
|
99 |
-
yield processed_frames[-1], temp_filepath, f"Processing complete! Elapsed time: {elapsed_time:.2f} seconds"
|
100 |
-
finally:
|
101 |
-
# Ensure the file is deleted after yielding the result
|
102 |
-
os.remove(temp_filepath)
|
103 |
-
print(f"Temporary file deleted: {temp_filepath}")
|
104 |
|
105 |
except Exception as e:
|
106 |
print(f"Error: {e}")
|
|
|
87 |
|
88 |
processed_video = mp.ImageSequenceClip(processed_frames, fps=fps)
|
89 |
processed_video = processed_video.set_audio(audio)
|
90 |
+
|
91 |
+
# Write the video to an in-memory bytes buffer
|
92 |
+
buf = io.BytesIO()
|
93 |
+
processed_video.write_videofile(buf, codec="libx264")
|
94 |
+
buf.seek(0)
|
95 |
|
96 |
elapsed_time = time.time() - start_time
|
97 |
yield gr.update(visible=False), gr.update(visible=True), f"Processing complete! Elapsed time: {elapsed_time:.2f} seconds"
|
98 |
|
99 |
+
yield processed_frames[-1], buf, f"Processing complete! Elapsed time: {elapsed_time:.2f} seconds"
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
except Exception as e:
|
102 |
print(f"Error: {e}")
|