Update app.py
Browse files
app.py
CHANGED
@@ -39,8 +39,6 @@ def compress_video(video_file, target_width, target_height, progress=gr.Progress
|
|
39 |
raise gr.Error("Could not open video file for compression.")
|
40 |
|
41 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
42 |
-
|
43 |
-
# Use the target resolution directly.
|
44 |
new_width = int(target_width)
|
45 |
new_height = int(target_height)
|
46 |
|
@@ -187,11 +185,14 @@ def read_motion_csv(csv_filename):
|
|
187 |
print("[INFO] Completed reading motion CSV.")
|
188 |
return motion_data
|
189 |
|
190 |
-
def stabilize_video_using_csv(video_file, csv_file, zoom=1.0, vertical_only=False,
|
|
|
|
|
191 |
"""
|
192 |
Stabilizes the video using motion data from the CSV.
|
193 |
If vertical_only is True, only vertical motion is corrected.
|
194 |
Updates progress from progress_offset to progress_offset+progress_scale.
|
|
|
195 |
"""
|
196 |
start_time = time.time()
|
197 |
print(f"[INFO] Starting stabilization using CSV: {csv_file}")
|
@@ -235,7 +236,8 @@ def stabilize_video_using_csv(video_file, csv_file, zoom=1.0, vertical_only=Fals
|
|
235 |
dx = 0 # Only vertical stabilization.
|
236 |
transform = np.array([[1, 0, dx],
|
237 |
[0, 1, dy]], dtype=np.float32)
|
238 |
-
|
|
|
239 |
|
240 |
out.write(stabilized_frame)
|
241 |
if frame_idx % 10 == 0 or frame_idx == total_frames:
|
|
|
39 |
raise gr.Error("Could not open video file for compression.")
|
40 |
|
41 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
|
|
|
|
42 |
new_width = int(target_width)
|
43 |
new_height = int(target_height)
|
44 |
|
|
|
185 |
print("[INFO] Completed reading motion CSV.")
|
186 |
return motion_data
|
187 |
|
188 |
+
def stabilize_video_using_csv(video_file, csv_file, zoom=1.0, vertical_only=False,
|
189 |
+
progress=gr.Progress(), progress_offset=0.6, progress_scale=0.4,
|
190 |
+
output_file=None):
|
191 |
"""
|
192 |
Stabilizes the video using motion data from the CSV.
|
193 |
If vertical_only is True, only vertical motion is corrected.
|
194 |
Updates progress from progress_offset to progress_offset+progress_scale.
|
195 |
+
Uses cv2.BORDER_REPLICATE to fill any gaps, preventing black borders.
|
196 |
"""
|
197 |
start_time = time.time()
|
198 |
print(f"[INFO] Starting stabilization using CSV: {csv_file}")
|
|
|
236 |
dx = 0 # Only vertical stabilization.
|
237 |
transform = np.array([[1, 0, dx],
|
238 |
[0, 1, dy]], dtype=np.float32)
|
239 |
+
# Use BORDER_REPLICATE to avoid black borders
|
240 |
+
stabilized_frame = cv2.warpAffine(frame, transform, (width, height), borderMode=cv2.BORDER_REPLICATE)
|
241 |
|
242 |
out.write(stabilized_frame)
|
243 |
if frame_idx % 10 == 0 or frame_idx == total_frames:
|