Krokodilpirat commited on
Commit
763ccb8
Β·
verified Β·
1 Parent(s): 8f4905c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -125,7 +125,7 @@ def generate_blip_name(frame: np.ndarray) -> str:
125
  print(f"BLIP error: {e}")
126
  return "video"
127
 
128
- # --- 🎨 NEW: Simple Thumbnail Generation Function ---
129
 
130
  def create_simple_gradient_thumbnail(rgb_frame, depth_frame):
131
  """
@@ -160,6 +160,8 @@ def create_simple_gradient_thumbnail(rgb_frame, depth_frame):
160
 
161
  # 2. Erstelle Gradient-Bereiche
162
  height = rgb_thumb.shape[0]
 
 
163
  rgb_end = int(height * 0.60) # 60% RGB
164
  gradient_start = rgb_end # Gradient startet bei 60%
165
  gradient_end = int(height * 0.80) # Gradient endet bei 80%
@@ -498,7 +500,7 @@ current_video_url = None
498
  blip_generated_name = ""
499
  original_filename = ""
500
 
501
- # --- MAIN INFERENCE FUNCTION - FINAL FIX ---
502
  def infer_video_depth_from_source(upload_video, video_url, filename, use_blip, create_thumbnail, *args):
503
  """Process video to generate depth maps and RGBD output - FINAL THUMBNAIL FIX"""
504
  try:
@@ -576,7 +578,7 @@ def infer_video_depth_from_source(upload_video, video_url, filename, use_blip, c
576
  stitched = cv2.hconcat([rgb, depth_resized])
577
  stitched_frames.append(stitched)
578
 
579
- # 🎯 FINAL FIX: Nutze erstes Frame-Pair für Thumbnail (bereits perfekt passend)
580
  if i == 0 and create_thumbnail:
581
  print("Creating thumbnail from first perfectly matched RGB+Depth pair...")
582
  try:
@@ -586,7 +588,7 @@ def infer_video_depth_from_source(upload_video, video_url, filename, use_blip, c
586
  # Erstelle Thumbnail mit den bereits perfekt passenden Frames
587
  thumbnail = create_simple_gradient_thumbnail(rgb, depth_resized)
588
 
589
- print("βœ… Thumbnail created from first RGBD pair")
590
 
591
  except Exception as e:
592
  print(f"❌ Thumbnail creation failed: {e}")
@@ -598,14 +600,6 @@ def infer_video_depth_from_source(upload_video, video_url, filename, use_blip, c
598
  save_video(np.array(stitched_frames), rgbd_video_path, fps=fps)
599
  print("βœ… RGBD video created successfully")
600
 
601
- # Embed thumbnail in videos if created
602
- if create_thumbnail and thumbnail is not None:
603
- embed_thumbnail_in_video(vis_video_path, thumbnail, base_name)
604
- embed_thumbnail_in_video(rgbd_video_path, thumbnail, base_name)
605
- print("βœ… Thumbnail embedded in videos")
606
- elif create_thumbnail:
607
- print("❌ No thumbnail to embed")
608
-
609
  # Add audio from original video if possible
610
  try:
611
  temp_audio_path = rgbd_video_path.replace('.mp4', '_audio.mp4')
@@ -617,10 +611,19 @@ def infer_video_depth_from_source(upload_video, video_url, filename, use_blip, c
617
  result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
618
  if result.returncode == 0:
619
  os.replace(temp_audio_path, rgbd_video_path)
620
- rgbd_path = rgbd_video_path
621
  except Exception as e:
622
  print(f"Audio processing failed: {e}")
623
- rgbd_path = rgbd_video_path
 
 
 
 
 
 
 
 
 
624
 
625
  else:
626
  # If no RGBD stitching, fallback to old thumbnail method
@@ -631,8 +634,7 @@ def infer_video_depth_from_source(upload_video, video_url, filename, use_blip, c
631
  if rgb_frame is not None:
632
  # Simple RGB thumbnail with logo
633
  thumbnail = add_depth_logo(rgb_frame)
634
- embed_thumbnail_in_video(vis_video_path, thumbnail, base_name)
635
- print("βœ… Fallback RGB thumbnail created and embedded")
636
  else:
637
  print("❌ Could not create fallback thumbnail")
638
  thumbnail = None
 
125
  print(f"BLIP error: {e}")
126
  return "video"
127
 
128
+ # --- 🎨 Thumbnail Generation Functions ---
129
 
130
  def create_simple_gradient_thumbnail(rgb_frame, depth_frame):
131
  """
 
160
 
161
  # 2. Erstelle Gradient-Bereiche
162
  height = rgb_thumb.shape[0]
163
+ print(f"DEBUG: Height for zones: {height}") # Debug height
164
+
165
  rgb_end = int(height * 0.60) # 60% RGB
166
  gradient_start = rgb_end # Gradient startet bei 60%
167
  gradient_end = int(height * 0.80) # Gradient endet bei 80%
 
500
  blip_generated_name = ""
501
  original_filename = ""
502
 
503
+ # --- MAIN INFERENCE FUNCTION - FINAL THUMBNAIL FIX ---
504
  def infer_video_depth_from_source(upload_video, video_url, filename, use_blip, create_thumbnail, *args):
505
  """Process video to generate depth maps and RGBD output - FINAL THUMBNAIL FIX"""
506
  try:
 
578
  stitched = cv2.hconcat([rgb, depth_resized])
579
  stitched_frames.append(stitched)
580
 
581
+ # 🎯 CREATE THUMBNAIL from first perfectly matched RGB+Depth pair (but don't embed yet)
582
  if i == 0 and create_thumbnail:
583
  print("Creating thumbnail from first perfectly matched RGB+Depth pair...")
584
  try:
 
588
  # Erstelle Thumbnail mit den bereits perfekt passenden Frames
589
  thumbnail = create_simple_gradient_thumbnail(rgb, depth_resized)
590
 
591
+ print("βœ… Thumbnail created from first RGBD pair (not embedded yet)")
592
 
593
  except Exception as e:
594
  print(f"❌ Thumbnail creation failed: {e}")
 
600
  save_video(np.array(stitched_frames), rgbd_video_path, fps=fps)
601
  print("βœ… RGBD video created successfully")
602
 
 
 
 
 
 
 
 
 
603
  # Add audio from original video if possible
604
  try:
605
  temp_audio_path = rgbd_video_path.replace('.mp4', '_audio.mp4')
 
611
  result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
612
  if result.returncode == 0:
613
  os.replace(temp_audio_path, rgbd_video_path)
614
+ print("βœ… Audio added successfully")
615
  except Exception as e:
616
  print(f"Audio processing failed: {e}")
617
+
618
+ rgbd_path = rgbd_video_path
619
+
620
+ # 🎯 FINAL FIX: Embed thumbnail ONLY in RGBD video AFTER all processing
621
+ if create_thumbnail and thumbnail is not None:
622
+ print("Embedding thumbnail in RGBD video only (after all processing)...")
623
+ embed_thumbnail_in_video(rgbd_video_path, thumbnail, base_name)
624
+ print("βœ… Thumbnail embedded in RGBD video only")
625
+ elif create_thumbnail:
626
+ print("❌ No thumbnail to embed")
627
 
628
  else:
629
  # If no RGBD stitching, fallback to old thumbnail method
 
634
  if rgb_frame is not None:
635
  # Simple RGB thumbnail with logo
636
  thumbnail = add_depth_logo(rgb_frame)
637
+ print("βœ… Fallback RGB thumbnail created")
 
638
  else:
639
  print("❌ Could not create fallback thumbnail")
640
  thumbnail = None