Salimshakeel commited on
Commit
c41bf9c
·
1 Parent(s): c5e3f79
Files changed (1) hide show
  1. 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
- out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (h, w))
 
 
 
58
  for frame in frames:
59
  out.write(frame)
60
  out.release()
61
 
62
- # print("Fixing the video with ffmpeg")
63
- # fix_video_with_ffmpeg(output_path)
64
 
65
- def fix_video_with_ffmpeg(path):
66
- temp_path = path + ".fixed.mp4"
67
- subprocess.run([
68
- "ffmpeg", "-y", "-i", path,
69
- "-vcodec", "libx264", "-pix_fmt", "yuv420p", temp_path
70
- ])
71
- os.replace(temp_path, path)
 
 
 
 
 
 
 
 
 
 
 
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)