How to use the moviepy.editor.CompositeVideoClip function in moviepy

To help you get started, we’ve selected a few moviepy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github minimaxir / magic-the-gifening / utils.py View on Github external
gif_height = 168 - card_upper_corner[1]

    mtg_card = Image.open(BytesIO(requests.get(get_mtg_image(id)).content))
    mtg_card = ImageClip(np.asarray(mtg_card)).resize((222, 310))

    get_giphy_gif(name)
    giphy_gif = (VideoFileClip('giphy_gif.mp4',
                               target_resolution=(gif_height, gif_width))
                 .set_pos(card_upper_corner)

                 )

    if giphy_gif.duration < 2:
        giphy_gif = giphy_gif.fx(loop, n=1+int(2 // giphy_gif.duration))

    mtg_gif = CompositeVideoClip([mtg_card, giphy_gif])
    mtg_gif = mtg_gif.set_start(0).set_duration(giphy_gif.duration)
    # mtg_gif.write_gif("mtg_gif.gif")
    mtg_gif.write_videofile("mtg_gif.mp4", codec='libx264',
                            bitrate=str(np.power(10, 7)), verbose=False,
                            progress_bar=False,
                            audio=False, ffmpeg_params=['-pix_fmt', 'yuv420p'])
github SenorPez / project-cars-replay-enhancer / test / integration_DefaultCards.py View on Github external
os.environ['HEADINGFONTOVERRIDE']
    if os.environ.get('DISPLAYFONTOVERRIDE') is not None:
        configuration['font'] = os.environ['DISPLAYFONTOVERRIDE']

    framerate = 30

    source_video = mpy.VideoFileClip(configuration['source_video']).subclip(configuration['video_skipstart'], configuration['video_skipend'])

    pcre_standings = GTStandings(race_data, ups=framerate, **configuration)
    standings_clip_mask = mpy.VideoClip(make_frame=pcre_standings.make_mask_frame, ismask=True)
    standings_clip = mpy.VideoClip(make_frame=pcre_standings.make_frame).set_mask(standings_clip_mask)

    # standings_clip = standings_clip.set_duration(source_video.duration)
    # standings_clip.write_videofile(output_prefix + "_standings.mp4", fps=framerate)

    main_event = mpy.CompositeVideoClip([source_video, standings_clip]).set_duration(source_video.duration)
    main_event = main_event.subclip(main_event.duration-30, main_event.duration)

    pcre_starting_grid = StartingGrid(
        sorted(race_data.starting_grid, key=lambda x: x.position),
        size=source_video.size,
        **configuration)
    Image.fromarray(pcre_starting_grid.to_frame()).save(
        output_prefix + "_starting_grid.png")
    starting_grid = mpy.ImageClip(pcre_starting_grid.to_frame()).set_duration(5)

    while True:
        try:
            result_data.get_data()
        except StopIteration:
            break
github SenorPez / project-cars-replay-enhancer / replay.py View on Github external
series_standings.mask = series_standings.mask.fx(vfx.fadein, 1)

	if g.showChampion:
		series_standings.mask = series_standings.mask.fx(vfx.fadein, 1).fx(vfx.fadeout, 1)
		champion = mpy.ImageClip(make_champion()).set_start(40).set_duration(20).set_position(('center', 'center'))
		champion.mask = champion.mask.fx(vfx.fadein, 1)
	else:
		series_standings.mask = series_standings.mask.fx(vfx.fadein, 1)

	intro = mpy.CompositeVideoClip([backdrop, title]).set_duration(6).fx(vfx.fadeout, 1)
	mainevent = mpy.CompositeVideoClip([video, standing, timer]).set_duration(video.duration)

	if g.showChampion:
		outro = mpy.CompositeVideoClip([backdrop, result, series_standings, champion]).set_duration(sum([x.duration for x in [result, series_standings, champion]])).fx(vfx.fadein, 1)
	else:
		outro = mpy.CompositeVideoClip([backdrop, result, series_standings]).set_duration(sum([x.duration for x in [result, series_standings]])).fx(vfx.fadein, 1)

	output = mpy.concatenate_videoclips([intro, mainevent, outro])

	#Full video.
	#output.write_videofile(g.outputvideo)
	
	#Full video, low framerate
	#output.write_videofile(g.outputvideo, fps=10)

	#Subclip video.
	output.subclip(0, 20).write_videofile(g.outputvideo, fps=30)
	#output.subclip(output.duration-80, output.duration).write_videofile(g.outputvideo, fps=10)
github pelednoam / mmvt / src / utils / movies_utils.py View on Github external
def annotate(clip, txt, txt_color=txt_color, fontsize=fontsize):
        """ Writes a text at the bottom of the clip. """
        # To make this code works the policy.xml should be editted
        #  identify -list policy
        # sudo gedit /etc/ImageMagick/policy.xml &
        # Put under comment the TEXT and LABEL lines
        txtclip = editor.TextClip(txt, fontsize=fontsize, color=txt_color)  # font=font
        # txtclip = txtclip.on_color((clip.w, txtclip.h + 6), color=(0, 0, 255), pos=(6, 'center'))
        cvc = editor.CompositeVideoClip([clip, txtclip.set_pos(('center', 'bottom'))])
        return cvc.set_duration(clip.duration)
github uber-research / atari-model-zoo / atari_zoo / utils.py View on Github external
for label in y_labels:
        txtClip = mpy.TextClip(label,color='black', fontsize=label_fontsize).set_position((0,label_padding+y_step*l_idx+(y_step/2)))
        l_idx+=1
        clip_list.append(txtClip)

    l_idx = 0
    for label in x_labels:
        txtClip = mpy.TextClip(label,color='black', fontsize=label_fontsize).set_position((label_padding+x_step*l_idx,label_padding/2))
        l_idx+=1
        clip_list.append(txtClip)

    
    for key in clip_dict:
        clip_list.append(clip_dict[key])
    
    cc = mpy.CompositeVideoClip(clip_list,composite_size)

    if length!=None:
        duration = length

    cc = cc.resize(1.0).subclip(0,duration)

    if out_fn != None:
        cc.write_videofile(out_fn)

    return cc,clip_dict
github google / starthinker / starthinker / task / video / run.py View on Github external
def edit_video(video):
  clips = [mp.VideoFileClip(video['file_or_url'])]

  for effect in video['effects']:
    clips.extend(get_effects(clips[0], effect))
 
  video = mp.CompositeVideoClip(clips)

  return video
github SenorPez / project-cars-replay-enhancer / replayenhancer / replayenhancer.py View on Github external
progress.update()
                except StopIteration:
                    end_time = start_time + 60
                    break

        if end_time is None:
            end_time = first_lap_data.elapsed_time + 10

        main_event = mpy.CompositeVideoClip(
            [source_video, standings_clip, timecode_clip]
        ).set_duration(
            source_video.duration
        ).subclip(start_time, end_time)

    else:
        main_event = mpy.CompositeVideoClip(
            [source_video, standings_clip]
        ).set_duration(source_video.duration)

    pcre_starting_grid = StartingGrid(
        sorted(race_data.starting_grid, key=lambda x: x.position),
        size=source_video.size,
        **configuration)
    Image.fromarray(pcre_starting_grid.to_frame()).save(
        output_prefix + "_starting_grid.png")
    starting_grid = mpy.ImageClip(
        pcre_starting_grid.to_frame()).set_duration(5)

    while True:
        try:
            result_data.get_data()
        except StopIteration:
github achyutreddy24 / RedditBots / TwitchToYoutube / FormatVideoFile.py View on Github external
def CompressVideo(fileName):
    fvd = importlib.reload(me) #Moviepy crashes when converting a second video, workaround for now
    # Load file and select the subclip
    clip = me.VideoFileClip(fileName).resize(width=1920, height=1080)
    
    final_clip = me.CompositeVideoClip([clip])

    # write the result to a file in any format
    final_clip.write_videofile(fileName+"_edited.mp4", fps=30)