I am making a video with subtitle using moviepy in python 3.6.
from moviepy.video.tools.subtitles import SubtitlesClip
from moviepy.video.io.VideoFileClip import VideoFileClip
generator = (lambda txt: TextClip(txt, font='Georgia-Regular', fontsize=24, color='white'))
subtitles = SubtitlesClip("sub.md", generator)
myvideo = VideoFileClip("video.mp4")
final = CompositeVideoClip([myvideo, subtitles])
final.write_videofile("final.mp4", fps=myvideo.fps)
i am geting an error:
self.duration = max([tb for ((ta,tb), txt) in self.subtitles])
ValueError: max() arg is an empty sequence
Look at this sample code to see if there are hints you can derive corrections from. I also dropped a link to the GitHub error repo for moviepy.
def add_text_to_movie(movie_fol, movie_name, out_movie_name, subs, fontsize=50, txt_color='red', font='Xolonium-Bold'):
from moviepy import editor
def annotate(clip, txt, txt_color=txt_color, fontsize=fontsize, font=font):
""" Writes a text at the bottom of the clip. """
txtclip = editor.TextClip(txt, fontsize=fontsize, font=font, color=txt_color)
cvc = editor.CompositeVideoClip([clip, txtclip.set_pos(('center', 'bottom'))])
return cvc.set_duration(clip.duration)
video = editor.VideoFileClip(op.join(movie_fol, movie_name))
annotated_clips = [annotate(video.subclip(from_t, to_t), txt) for (from_t, to_t), txt in subs]
final_clip = editor.concatenate_videoclips(annotated_clips)
final_clip.write_videofile(op.join(movie_fol, out_movie_name))