Skip to content

Commit

Permalink
chore: true shuffle video
Browse files Browse the repository at this point in the history
- random duration splits video
- shuffle splits video
  • Loading branch information
ATtendev committed May 16, 2024
1 parent 2976652 commit 2128a5f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/services/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,27 @@ def combine_videos(combined_video_path: str,

clips = []
video_duration = 0

raw_clips = []
for video_path in video_paths:
clip = VideoFileClip(video_path).without_audio()
clip_duration = clip.duration
start_time = 0

while start_time < clip_duration:
end_time = min(start_time + max_clip_duration, clip_duration)
split_clip = clip.subclip(start_time, end_time)
raw_clips.append(split_clip)
logger.info(f"splitting from {start_time:.2f} to {end_time:.2f}, clip duration {clip_duration:.2f}, split_clip duration {split_clip.duration:.2f}")
start_time = end_time
# Add downloaded clips over and over until the duration of the audio (max_duration) has been reached
while video_duration < audio_duration:
# random video_paths order
if video_concat_mode.value == VideoConcatMode.random.value:
random.shuffle(video_paths)
random.shuffle(raw_clips)

for video_path in video_paths:
clip = VideoFileClip(video_path).without_audio()

for clip in raw_clips:
# Check if clip is longer than the remaining audio
if (audio_duration - video_duration) < clip.duration:
clip = clip.subclip(0, (audio_duration - video_duration))
Expand Down

0 comments on commit 2128a5f

Please sign in to comment.