from moviepy.editor import * from moviepy.video.tools.drawing import circle import sys def moviePyEndEffect(inVid, text, delta_t, fn_size, fn_colr, fps, full=1): ''' inVid: Name of the input video (string) text: Text to be added at the end such as "The End" or "Finish"... delta_t: duration at the end for which end effet is created fn_size: font size for the text in text clip fps: Frames per seconds of the new video If full = 0, Only the subclip of duration specified by delta_t is created. If full = 1, video duration is same as input video and last 'delta_t' seconds are converted into the End Effect. The name of output video is vid_EndEffect.mp4. Font Colour has to be specified explicitly in the 'the_end' clip created later like "red", "white", "blue"... and not RGB format. ''' clip = VideoFileClip(inVid, audio=False) vidLength = clip.duration if vidLength < delta_t: print("Video duration too short to create End Effect, existing! \n") sys.exit() # Calculate start and end time of the subclip from the main video ts = vidLength - delta_t te = vidLength #Clip before end effect is added clip1 = clip.subclip(0, ts) #Clip for which end effect is added clip2 = clip.subclip(ts, te).add_mask() # Get width and height of the video w, h = clip1.size # Get centre of the circle created for end effect wc = w // 2 hc = h // 4 # The mask is a circle with vanishing radius r(t) = 800-200*t. # get_frame: numpy array representing the RGB picture of the clip # at time t or (mono or stereo) value for a sound clip clip2.mask.get_frame = lambda t: circle(screensize=(w, h), center=(wc, hc), radius=max(0,int(800-200*t)), col1=1, col2=0, blur=4) xy = clip.size # The actual end effect by adding text the_end = TextClip(text, font="Amiri-bold", color=fn_colr, fontsize=fn_size).set_duration(clip2.duration) # Overlap the end effect with source video: each clip of the list # will be displayed below the clips appearing after it final = CompositeVideoClip([the_end.set_position('center'),clip2], size=xy) if full != 0: # Combine the initial sub-clip with clip created with end effect final = concatenate_videoclips([clip1, final]) final.write_videofile("vid_EndEffect.mp4", fps=fps) moviePyEndEffect('in.mp4', "The End", 5, 50, "red", 10, 0)