From 849a84e1a41462ba62eea738331e942fa127932b Mon Sep 17 00:00:00 2001 From: orenkaizer Date: Sat, 4 Jun 2022 21:14:07 +0300 Subject: [PATCH] refactor: refactor the final_video.py functioanlity --- video_creation/background.py | 2 -- video_creation/final_video.py | 16 ++++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/video_creation/background.py b/video_creation/background.py index dce46bd..085ff2a 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -1,7 +1,5 @@ from random import randrange - from yt_dlp import YoutubeDL - from pathlib import Path from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.editor import VideoFileClip diff --git a/video_creation/final_video.py b/video_creation/final_video.py index e1f71ff..6568527 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -18,6 +18,7 @@ def make_final_video(number_of_clips): VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) + # Define the background of the clip background_clip = ( VideoFileClip("assets/mp4/clip.mp4") .without_audio() @@ -25,22 +26,17 @@ def make_final_video(number_of_clips): .crop(x1=1166.6, y1=0, x2=2246.6, y2=1920) ) # Gather all audio clips - audio_clips = [] - for i in range(0, number_of_clips): - audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) + audio_clips = [AudioFileClip(f"assets/mp3/{i}.mp3") for i in range(0, number_of_clips)] audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) - # Gather all images - image_clips = [] - for i in range(0, number_of_clips): - image_clips.append( - ImageClip(f"assets/png/comment_{i}.png") + # Gather all images, duration of each is equal to duration of the audio + image_clips = [ImageClip(f"assets/png/comment_{i}.png") .set_duration(audio_clips[i + 1].duration) .set_position("center") - .resize(width=W - 100), - ) + .resize(width=W - 100) for i in range(0, number_of_clips)] + image_clips.insert( 0, ImageClip(f"assets/png/title.png")