1from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip 2from moviepy.video.VideoClip import ColorClip 3 4 5def on_color(clip, size=None, color=(0, 0, 0), pos=None, col_opacity=None): 6 """ 7 Returns a clip made of the current clip overlaid on a color 8 clip of a possibly bigger size. Can serve to flatten transparent 9 clips (ideal for previewing clips with masks). 10 11 :param size: size of the final clip. By default it will be the 12 size of the current clip. 13 :param bg_color: the background color of the final clip 14 :param pos: the position of the clip in the final clip. 15 :param col_opacity: should the added zones be transparent ? 16 """ 17 18 if size is None: 19 size = clip.size 20 if pos is None: 21 pos = 'center' 22 colorclip = ColorClip(size, color=color) 23 if col_opacity: 24 colorclip = colorclip.with_mask().set_opacity(col_opacity) 25 26 return CompositeVideoClip([colorclip, clip.set_position(pos)], 27 transparent=(col_opacity is not None)) 28