KingNish commited on
Commit
e8cb0da
1 Parent(s): 1b81f82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -51,10 +51,23 @@ def fn(vid, bg_type="Color", bg_image=None, bg_video=None, color="#00FF00", fps=
51
  background_video = mp.VideoFileClip(bg_video)
52
  if background_video.duration < video.duration:
53
  if video_handling == "slow_down":
54
- background_video = background_video.fx(mp.vfx.speedx, factor=video.duration / background_video.duration)
 
 
55
  else: # video_handling == "loop"
56
  background_video = mp.concatenate_videoclips([background_video] * int(video.duration / background_video.duration + 1))
57
- background_frames = background_video.iter_frames(fps=fps)
 
 
 
 
 
 
 
 
 
 
 
58
  else:
59
  background_frames = None
60
 
 
51
  background_video = mp.VideoFileClip(bg_video)
52
  if background_video.duration < video.duration:
53
  if video_handling == "slow_down":
54
+ speed_factor = video.duration / background_video.duration
55
+ background_video = background_video.fx(mp.vfx.speedx, factor=speed_factor)
56
+ background_frames = background_video.iter_frames(fps=fps) # Extract frames at desired FPS
57
  else: # video_handling == "loop"
58
  background_video = mp.concatenate_videoclips([background_video] * int(video.duration / background_video.duration + 1))
59
+ background_frames = background_video.iter_frames(fps=fps) # Extract frames at desired FPS
60
+ elif background_video.duration > video.duration:
61
+ if video_handling == "slow_down":
62
+ # Handle longer background video (e.g., trim or adjust logic)
63
+ background_video = background_video.subclip(0, video.duration)
64
+ background_frames = background_video.iter_frames(fps=fps)
65
+ else: # video_handling == "loop"
66
+ background_video = mp.concatenate_videoclips([background_video] * int(video.duration / background_video.duration + 1))
67
+ background_frames = background_video.iter_frames(fps=fps) # Extract frames at desired FPS
68
+
69
+ else:
70
+ background_frames = background_video.iter_frames(fps=fps) # Extract frames at desired FPS
71
  else:
72
  background_frames = None
73