Create function from the code that can be called from other file. function should use…
- User
Create function from the code that can be called from other file. function should use text_center, main_video_path as atributes and return final clip. Use ’ instead of “ in final code This is the code : import os from moviepy.editor import VideoFileClip, ImageClip, TextClip, CompositeVideoClip from moviepy.video.fx import all as fx from create_image_with_text import create_image_with_text
Set the size of the final video and other parameters
size = (1080, 1920) delayins = 0 #delay for elements to appear fps_size = 1 text_center = 'AI CREATES WEBSITES OMG wow wow, omg...'
Set the directory where all the files are stored
dir_path = 'C:/Python/VideoCreationTiktok/Source/' dir_path_output = 'C:/Python/VideoCreationTiktok/Output/' main_video_path = os.path.join(dir_path, 'main_video1.mp4')
Set the paths to the source files
source_files = ['Background.jpg', 'Frame.png', 'Reaction1.mov', 'tools.png', 'arrow.gif'] background_path, frame_path, reaction_video_path, tools_path, gif_path = (os.path.join(dir_path, file) for file in source_files)
Get the length of the main video
main_video = VideoFileClip(main_video_path) main_video_length = main_video.duration
Load and resize the background and main video
background_resized = ImageClip(background_path).resize(height=size[1]).set_position('center') main_video_resized = main_video.resize(height=size[1]*0.73).set_position((60, 40))
Load and resize the frame image
frame_resized = ImageClip(frame_path).resize(height=size[1]*0.82).set_position((10, 20)).set_duration(main_video_length)
Load and trim the reaction video
reaction_video = VideoFileClip(reaction_video_path, has_mask=True).subclip(0, main_video_length)
Load and resize the tools image
tools_resized = ImageClip(tools_path).resize(width=int(size[0]*0.70)).set_position(('right', 'top'))
Add the text to the final clip
txt_clip = TextClip('All Links', fontsize=tools_resized.h*0.8, font='Impact', color='white', stroke_width=3, stroke_color='black').set_position(('left', 'top')).set_duration(main_video_length)
Load and resize the gif file
gif = VideoFileClip(gif_path, has_mask=True).resize((size[0]-tools_resized.w-txt_clip.w, tools_resized.h)).set_fps(fps_size) gif = gif.loop(duration=main_video_length).set_position((txt_clip.size[0], 0))
Set the start time for tools, gif, and txt_clip
tools_resized, gif, txt_clip = (clip.set_start(delayins) for clip in [tools_resized, gif, txt_clip])
Create text clip overlay
image_path = create_image_with_text(text_center) text_clip_red = ImageClip(image_path).set_position(('center', 'center'))
Create the final clip
final_clip = CompositeVideoClip([background_resized, main_video_resized, frame_resized, reaction_video.set_audio(None), tools_resized.set_duration(main_video_length), txt_clip, gif, text_clip_red], size=size)
Apply the 'Summer' color effect and set the audio
final_clip = fx.lum_contrast(final_clip, lum=0, contrast=0.2, contrast_thr=190).set_audio(main_video.audio)
final_clip.duration = main_video_length
Preview the final clip
final_clip.resize(0.5).preview()
- Assistant
def create_final_clip(text_center, main_video_path): import os from moviepy.editor import VideoFileClip, ImageClip, TextClip, CompositeVideoClip from moviepy.video.fx import all as fx from create_image_with_text import create_image_with_text
# Set the size of the final video and other parameters size = (1080, 1920) delayins = 0 # delay for elements to appear fps_size = 1 # Set the directory where all the files are stored dir_path = 'C:/Python/VideoCreationTiktok/Source/' dir_path_output = 'C:/Python/VideoCreationTiktok/Output/' # Set the paths to the source files source_files = ['Background.jpg', 'Frame.png', 'Reaction1.mov', 'tools.png', 'arrow.gif'] background_path, frame_path, reaction_video_path, tools_path, gif_path = ( os.path.join(dir_path, file) for file in source_files) # Get the length of the main video main_video = VideoFileClip(main_video_path) main_video_length = main_video.duration # Load and resize the background and main video background_resized = ImageClip(background_path).resize(height=size[1]).set_position('center') main_video_resized = main_video.resize(height=size[1] * 0.73).set_position((60, 40)) # Load and resize the frame image frame_resized = ImageClip(frame_path).resize(height=size[1] * 0.82).set_position((10, 20)).set_duration( main_video_length) # Load and trim the reaction video reaction_video = VideoFileClip(reaction_video_path, has_mask=True).subclip(0, main_video_length) # Load and resize the tools image tools_resized = ImageClip(tools_path).resize(width=int(size[0] * 0.70)).set_position(('right', 'top')) # Add the text to the final clip txt_clip = TextClip('All Links', fontsize=tools_resized.h * 0.8, font='Impact', color='white', stroke_width=3, stroke_color='black').set_position(('left', 'top')).set_duration(main_video_length) # Load and resize the gif file gif = VideoFileClip(gif_path, has_mask=True).resize( (size[0] - tools_resized.w - txt_clip.w, tools_resized.h)).set_fps(fps_size) gif = gif.loop(duration=main_video_length).set_position((txt_clip.size[0], 0)) # Set the start time for tools, gif, and txt_clip tools_resized, gif, txt_clip = (clip.set_start(delayins) for clip in [tools_resized, gif, txt_clip]) # Create text clip overlay image_path = create_image_with_text(text_center) text_clip_red = ImageClip(image_path).set_position(('center', 'center')) # Create the final clip final_clip = CompositeVideoClip([background_resized, main_video_resized, frame_resized, reaction_video.set_audio(None), tools_resized.set_duration(main_video_length), txt_clip, gif, text_clip_red], size=size) # Apply the 'Summer' color effect and set the audio final_clip = fx.lum_contrast(final_clip, lum=0, contrast=0.2, contrast_thr=190).set_audio(main_video.audio) final_clip.duration = main_video_length return final_clip