from moviepy.editor import VideoFileClip, concatenate_videoclips,vfx from moviepy.editor import AudioFileClip, CompositeAudioClip import os def combine_videos(folder_name): length = len(os.listdir(folder_name)) vids = [VideoFileClip(os.path.join(folder_name,x)) for x in sorted(os.listdir(folder_name))] combined = concatenate_videoclips( [vid.subclip(0,7).fx(vfx.fadein,0.5).fx(vfx.fadeout,0.5) if vid.duration > 7 else vid.fx(vfx.fadein,0.5).fx(vfx.fadeout,0.5) for vid in vids], # [VideoFileClip(os.path.join(folder_name,x)).subclip(0,7).fx(vfx.fadein,0.5).fx(vfx.fadeout,0.5) for x in sorted(os.listdir(folder_name))], "compose",bg_color=None, padding=0 ) combined.write_videofile(os.path.join(folder_name, "Final_Ad_Video.mp4")) # if length <= 6: # combined = concatenate_videoclips([VideoFileClip(os.path.join(folder_name,x)).subclip(0,10) for x in os.listdir(folder_name)]) # combined.write_videofile(os.path.join(folder_name, "Ad_Video.mp4")) # else : # combined = concatenate_videoclips([VideoFileClip(os.path.join(folder_name,x)).subclip(0,60//length) for x in os.listdir(folder_name)]) # combined.write_videofile(os.path.join(folder_name, "Ad_Video.mp4")) print("Done! Your ads video has been created") def combine_audio_video(folder_name, vid, speech): videoclip = VideoFileClip(vid) audioclip = AudioFileClip(speech) new_audioclip = CompositeAudioClip([audioclip]) videoclip.audio = new_audioclip videoclip.write_videofile(os.path.join(folder_name,"new_filename.mp4"))