aneela-pervez commited on
Commit
12d0475
·
verified ·
1 Parent(s): 347a592

Update final_lipsync.py

Browse files
Files changed (1) hide show
  1. final_lipsync.py +2 -21
final_lipsync.py CHANGED
@@ -208,24 +208,19 @@ def full_analysis(video_path):
208
  fps = cap.get(cv2.CAP_PROP_FPS) or 25.0
209
  frames = []
210
 
211
- # --- ADDED: FAST PROCESSING LOGIC ---
212
  frame_count = 0
213
  while cap.isOpened():
214
  ret, frame = cap.read()
215
  if not ret: break
216
 
217
- # Har 5th frame process karein (10x Fast Speedup)
218
  if frame_count % 5 == 0:
219
  temp_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
220
- # Resolution Downscaling taake RetinaFace fast chalay
221
  small_frame = cv2.resize(temp_frame, (640, 360))
222
  frames.append(small_frame)
223
 
224
  frame_count += 1
225
- # Limit processing to max 150 frames (Safety against memory overload)
226
  if len(frames) > 150: break
227
- # ------------------------------------
228
-
229
  cap.release()
230
 
231
  if len(frames) == 0: return None, 0, 0, 0, 0, 0, 0, 0, 0, 0
@@ -242,10 +237,9 @@ def full_analysis(video_path):
242
  except: custom_v_score = clip_v_score
243
  final_v_score = (clip_v_score * 0.7) + (custom_v_score * 0.3)
244
 
245
- # --- ADDED: FAST AUDIO LOADING LOGIC (Duration=10) ---
246
  y, sr = librosa.load(video_path, sr=48000, duration=10)
247
  y_16, _ = librosa.load(video_path, sr=16000, duration=10)
248
- # ----------------------------------------------------
249
 
250
  with torch.no_grad():
251
  a_emb = torch.from_numpy(models["clap"].get_audio_embedding_from_data(x=[y])).to(DEVICE)
@@ -282,13 +276,6 @@ def full_analysis(video_path):
282
 
283
  def master_pipeline(video_path):
284
  if not video_path: return None, "No video provided.", "Error"
285
-
286
- # --- ADDED: HEAVY VIDEO KAGGLE CHECK ---
287
- file_size_mb = os.path.getsize(video_path) / (1024 * 1024)
288
- if file_size_mb > 50:
289
- return None, f"⚠️ Video is too heavy ({file_size_mb:.1f}MB) for local CPU. Processing routed to Kaggle API (check Dashboard).", "Kaggle Triggered"
290
- # ---------------------------------------
291
-
292
  res = full_analysis(video_path)
293
  if res is None or res[0] is None:
294
  return None, "Analysis failed to process video.", "Error"
@@ -311,10 +298,4 @@ def master_pipeline(video_path):
311
  except: reason = "Reasoning unavailable."
312
 
313
  summary = f"## 📂 {case}\n\nVision: {v_score:.1f}% | Audio: {a_score:.1f}% | Sync: {sync_score:.1f}%"
314
-
315
- # --- ADDED: MEMORY CLEANUP ---
316
- gc.collect()
317
- if torch.cuda.is_available(): torch.cuda.empty_cache()
318
- # -----------------------------
319
-
320
  return img, summary, reason
 
208
  fps = cap.get(cv2.CAP_PROP_FPS) or 25.0
209
  frames = []
210
 
211
+ # Fast Processing Logic (Har 5th frame use karega taake GPU pe time bache)
212
  frame_count = 0
213
  while cap.isOpened():
214
  ret, frame = cap.read()
215
  if not ret: break
216
 
 
217
  if frame_count % 5 == 0:
218
  temp_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
 
219
  small_frame = cv2.resize(temp_frame, (640, 360))
220
  frames.append(small_frame)
221
 
222
  frame_count += 1
 
223
  if len(frames) > 150: break
 
 
224
  cap.release()
225
 
226
  if len(frames) == 0: return None, 0, 0, 0, 0, 0, 0, 0, 0, 0
 
237
  except: custom_v_score = clip_v_score
238
  final_v_score = (clip_v_score * 0.7) + (custom_v_score * 0.3)
239
 
240
+ # Fast Audio Loading Logic
241
  y, sr = librosa.load(video_path, sr=48000, duration=10)
242
  y_16, _ = librosa.load(video_path, sr=16000, duration=10)
 
243
 
244
  with torch.no_grad():
245
  a_emb = torch.from_numpy(models["clap"].get_audio_embedding_from_data(x=[y])).to(DEVICE)
 
276
 
277
  def master_pipeline(video_path):
278
  if not video_path: return None, "No video provided.", "Error"
 
 
 
 
 
 
 
279
  res = full_analysis(video_path)
280
  if res is None or res[0] is None:
281
  return None, "Analysis failed to process video.", "Error"
 
298
  except: reason = "Reasoning unavailable."
299
 
300
  summary = f"## 📂 {case}\n\nVision: {v_score:.1f}% | Audio: {a_score:.1f}% | Sync: {sync_score:.1f}%"
 
 
 
 
 
 
301
  return img, summary, reason