def __make_image_video__(self, image_src, duration): file_path = "./tmp/{:s}.mp4".format(str(self.__next_index__())) clip = ImageClip(image_src, duration=duration) clip.write_videofile(file_path, fps=VIDEO_FPS) clip.close() file_path = self.__apply_transformation__(file_path, duration) return file_path
def generate(): """Genera los vídeos de finalización""" for png in Path('.').glob('end_*.png'): nombre = png.stem res = nombre.split('_')[1] clip = ImageClip(png.name).set_duration(NUM_SECONDS) clip.write_videofile('{}.mp4'.format(nombre, res), fps=24) print ("info: h: {}, w: {}".format(clip.h, clip.w)) clip.close()
def convert(nombre): # Generamos la entradilla clip = ImageClip('{}.png'.format(nombre)).set_duration(5) clip.write_videofile('{}_start.mp4'.format(nombre), fps=24) clip.close() # Generamos vídeo final clip1 = VideoFileClip('{}_start.mp4'.format(nombre)) clip2 = VideoFileClip('{}.mp4'.format(nombre)) clip3 = VideoFileClip('video_end.mp4') final = concatenate_videoclips([clip1, clip2, clip3], method="compose") final.write_videofile('{}_final.mp4'.format(nombre)) final.close()
def main(orientation, background_image_path): if orientation == "portrait": size = (1080, 1920) elif orientation == "landscape": size = (1920, 1080) background_image = ImageClip( os.path.join(background_image_path, "background.png")).set_duration(1).resize(size) # fps = (1/math.ceil(raw_square_video.duration)) # fps = 30 background_image.write_videofile(os.path.join(background_image_path, "background.mp4"), fps=60) background_image.close() return os.path.join(background_image_path, "background.mp4")
def generar_caratulas(num, clip_size): """generar_caratulas Genera y devuelve los vídeos de inicio y fin a partir de las imágnes de portada y finalización. (width, height) """ inicio_mp4, fin_mp4 = None, None # generamos la imagen final out="end_{}.mp4".format(clip_size[1]) if not Path(out).exists(): im = Image.open('end_1440.png') im.resize(clip_size, Image.ANTIALIAS) name="end_{}.png".format(clip_size[0]) im.save(name, "PNG") clip = ImageClip(name).set_duration(NUM_SECONDS) out="end_{}.mp4".format(clip_size[1]) clip.write_videofile(out, fps=24) clip.close() fin_mp4 = Path(out) for png in Path('.').glob('{}-*_1440.png'.format(num)): im = Image.open(png.name) im.resize(clip_size, Image.ANTIALIAS) name_png="{}_{}_start.png".format(png.stem, clip_size[1]) im.save(name_png, "PNG") clip = ImageClip(name_png).set_duration(NUM_SECONDS) name_mp4 = '{}_{}_start.mp4'.format(png.stem, clip_size[1]) clip.write_videofile(name_mp4, fps=24) clip.close() inicio_mp4 = Path(name_mp4) break return inicio_mp4, fin_mp4