From e16770b0a09b4f1d71ec753d302cdc6a9bdcb8f9 Mon Sep 17 00:00:00 2001 From: Chev Date: Sat, 24 May 2025 19:38:17 -0700 Subject: [PATCH] Prevent duplicated sound clips from going past a video clip (they will stick to the clip that they're applied on) --- main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ad0b70e..1666cc4 100644 --- a/main.py +++ b/main.py @@ -247,12 +247,18 @@ for index, audio in enumerate(randomSounds): for i in range(rng.randint(1, 5)): copiedSoundAmount += 1 - # Max 0 and clip position - 2 so it doesn't go into negative clip position (if near beginning of video) + dupe_clip_position = clipPosition + ((i * 0.4) * rng.uniform(0.8, 1.2)) + # If the duplicate clip goes over the final video duration, simply discard that duplicate clip + if dupe_clip_position > finalVideo.duration: + continue + + """# Max 0 and clip position - 2 so it doesn't go into negative clip position (if near beginning of video) minimumRange = max(0, clipPosition - 2) # Minimum between final video duration and clip position + 2 so it doesn't go over video length (if near end of video) maximumRange = min(finalVideo.duration, clipPosition + 2) - newClip.duration - copiedClip = newClip.set_start(rng.uniform(minimumRange, maximumRange)) # move audio around video length + copiedClip = newClip.set_start(rng.uniform(minimumRange, maximumRange)) # move audio around video length""" + copiedClip = newClip.set_start(dupe_clip_position) audioObjects.append(copiedClip) print(f"Compiling {audioAmount} sounds... {get_progress_bar_str(1, 1, progress_bar_len=40)}")