Commit
·
c41bf9c
1
Parent(s):
c5e3f79
fixing
Browse files- services/summarizer.py +23 -10
services/summarizer.py
CHANGED
|
@@ -54,18 +54,31 @@ def save_summary_video(video_path, selected_indices, output_path, fps=15):
|
|
| 54 |
h, w, _ = frames[0].shape
|
| 55 |
print("Video dimensions:", w, h)
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
for frame in frames:
|
| 59 |
out.write(frame)
|
| 60 |
out.release()
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
def fix_video_with_ffmpeg(
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
h, w, _ = frames[0].shape
|
| 55 |
print("Video dimensions:", w, h)
|
| 56 |
|
| 57 |
+
ext = output_path.split('.')[-1]
|
| 58 |
+
raw_output_path = output_path.replace(f".{ext}", f"_raw.{ext}")
|
| 59 |
+
|
| 60 |
+
out = cv2.VideoWriter(raw_output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (h, w))
|
| 61 |
for frame in frames:
|
| 62 |
out.write(frame)
|
| 63 |
out.release()
|
| 64 |
|
| 65 |
+
print("Fixing the video with ffmpeg")
|
| 66 |
+
fix_video_with_ffmpeg(raw_output_path, output_path)
|
| 67 |
|
| 68 |
+
def fix_video_with_ffmpeg(input_path, output_path):
|
| 69 |
+
# 2️⃣ Use FFmpeg to fix video (browser-compatible)
|
| 70 |
+
try:
|
| 71 |
+
subprocess.run([
|
| 72 |
+
"ffmpeg",
|
| 73 |
+
"-y", # overwrite if file exists
|
| 74 |
+
"-i", input_path,
|
| 75 |
+
"-vcodec", "libx264",
|
| 76 |
+
"-acodec", "aac",
|
| 77 |
+
output_path,
|
| 78 |
+
], check=True)
|
| 79 |
+
print(f"✅ FFmpeg re-encoded video saved to: {output_path}")
|
| 80 |
+
os.remove(input_path)
|
| 81 |
+
except subprocess.CalledProcessError as e:
|
| 82 |
+
print("❌ FFmpeg failed:", e)
|
| 83 |
+
print("⚠️ Using raw video instead.")
|
| 84 |
+
os.rename(input_path, output_path)
|