chore: true shuffle video

- random duration splits video
- shuffle splits video
This commit is contained in:
AT
2024-05-15 14:17:50 +07:00
parent 2976652509
commit 2128a5fae5

View File

@@ -49,14 +49,27 @@ def combine_videos(combined_video_path: str,
clips = [] clips = []
video_duration = 0 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 # Add downloaded clips over and over until the duration of the audio (max_duration) has been reached
while video_duration < audio_duration: while video_duration < audio_duration:
# random video_paths order # random video_paths order
if video_concat_mode.value == VideoConcatMode.random.value: 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 # Check if clip is longer than the remaining audio
if (audio_duration - video_duration) < clip.duration: if (audio_duration - video_duration) < clip.duration:
clip = clip.subclip(0, (audio_duration - video_duration)) clip = clip.subclip(0, (audio_duration - video_duration))