jonathanjordan21's picture
Update components/utils.py
e855c02
raw
history blame
1.26 kB
from moviepy.editor import VideoFileClip, concatenate_videoclips,vfx
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")