Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import requests
|
|
7 |
from ultralytics import YOLO
|
8 |
import time
|
9 |
import numpy as np
|
|
|
10 |
|
11 |
# Page config first
|
12 |
st.set_page_config(
|
@@ -139,10 +140,20 @@ if process_button and source_file and model:
|
|
139 |
|
140 |
if st.session_state.processed_frames:
|
141 |
out_path = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False).name
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
for frame in st.session_state.processed_frames:
|
144 |
-
writer.
|
145 |
-
writer.
|
146 |
|
147 |
with open(out_path, 'rb') as f:
|
148 |
st.session_state.processed_video = f.read()
|
|
|
7 |
from ultralytics import YOLO
|
8 |
import time
|
9 |
import numpy as np
|
10 |
+
import imageio_ffmpeg as ffmpeg
|
11 |
|
12 |
# Page config first
|
13 |
st.set_page_config(
|
|
|
140 |
|
141 |
if st.session_state.processed_frames:
|
142 |
out_path = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False).name
|
143 |
+
# Use imageio-ffmpeg instead of cv2 for more reliable MP4 output
|
144 |
+
writer = ffmpeg.write_frames(
|
145 |
+
out_path,
|
146 |
+
(width, height),
|
147 |
+
fps=output_fps or orig_fps,
|
148 |
+
codec='libx264', # Widely supported codec
|
149 |
+
pix_fmt_in='bgr24', # Match OpenCV frame format
|
150 |
+
pix_fmt_out='yuv420p' # Standard for MP4
|
151 |
+
)
|
152 |
+
writer.send(None) # Initialize writer
|
153 |
+
|
154 |
for frame in st.session_state.processed_frames:
|
155 |
+
writer.send(frame)
|
156 |
+
writer.close()
|
157 |
|
158 |
with open(out_path, 'rb') as f:
|
159 |
st.session_state.processed_video = f.read()
|