My goal is to add a text overlay to a series of clips at a given timestamp and then concatenate them all to make a single video. Currently, the video that is output as 'movie.mp4' only plays the first text overlay and none of the others.
I have looked at other posts (here) to try to recreate this but I have been unsuccessful.
In the comments for create_final_video(clips, texts, totalDuration)
you can see what else I have tried in order to concatenate the clips. This method also requires removing clip = CompositeVideoClip([clip, text]).set_duration(float(clip_data['clipDuration']))
. This second version concatenates the videos but the text overlay doesn't have its position set to the bottom left but to the top right instead, and the text overlays play back to back after each other rather than at the end of each clip.
Below is the first version:
import os
import json
from moviepy.editor import VideoFileClip, CompositeVideoClip, concatenate_videoclips, vfx, TextClip
# reads clip valid clip names from file
def read_valid_clips_list():
# gets clip data
def get_clip_data(filename):
def create_clips(clip_list):
clips = []
texts = []
currentDuration = 0
for filename in clip_list:
filename = filename.strip()
clip_data = get_clip_data(filename)
video_file_path = os.path.join(PATH_TO_RAW_CLIPS, filename)
# create video clip
clip = VideoFileClip(video_file_path)
clip = clip.set_duration(float(clip_data['clipDuration']))
clip = clip.fx(vfx.fadein, .1).fx(vfx.fadeout, .15)
# create text overlay for clip
text = create_text_overlay(clip_data, currentDuration)
# combine clip and text before concatenation
clip = CompositeVideoClip([clip, text]).set_duration(float(clip_data['clipDuration']))
currentDuration += float(clip_data['clipDuration'])
texts.append(text)
clips.append(clip)
return clips, texts, currentDuration
def create_text_overlay(clip_data, currentDuration):
streamerName = str(clip_data.get('streamerName'))
text_clip = TextClip(txt = streamerName, font = FONT_PATH, size = (400,0), color = 'rgb(145, 70, 255)')
tc_width, tc_height = text_clip.size
print(currentDuration)
text_clip = text_clip.set_start(currentDuration)
text_clip = text_clip.set_position(('left', 'bottom'))
text_clip = text_clip.set_duration(2.5)
text_clip = text_clip.crossfadein(0.2).crossfadeout(0.5)
return text_clip
def create_final_video(clips, texts, totalDuration):
vid_clips = concatenate_videoclips(clips, method='compose').set_duration(totalDuration)
# print(type(vid_clips))
# text_clips = concatenate_videoclips(texts).set_duration(totalDuration)
# print(type(text_clips))
# final_movie = CompositeVideoClip([vid_clips, text_clips], size=(1920,1080)).set_duration(totalDuration)
return vid_clips
def create_movie():
valid_list = read_valid_clips_list()
clips, texts, totalDuration = create_clips(valid_list)
movie = create_final_video(clips, texts, totalDuration)
return movie
movie = create_movie()
movie.write_videofile('VideoCompilation\VideoFiles\\videos\movie.mp4')