How to use the moviepy.editor.concatenate_videoclips 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 SenorPez / project-cars-replay-enhancer / test / integration_DefaultCards.py View on Github external
result_data.classification,
        size=source_video.size,
        **configuration)
    Image.fromarray(pcre_series_standings.to_frame()).save(
        output_prefix + '_series_standings.png')
    series_standings = mpy.ImageClip(pcre_series_standings.to_frame()).set_duration(20)

    pcre_champion = SeriesChampion(
        result_data.classification,
        size=source_video.size,
        **configuration)
    Image.fromarray(pcre_champion.to_frame()).save(
        output_prefix + '_champion.png')
    champion = mpy.ImageClip(pcre_champion.to_frame()).set_duration(20)

    output = mpy.concatenate_videoclips([
        starting_grid.fadeout(1),
        main_event,
        results.fadein(1).fadeout(1),
        series_standings.fadein(1)
    ], method="compose")
    output.write_videofile(output_prefix + '.mp4', fps=framerate)
github salil-gtm / SignDetect / main.py View on Github external
if l.isalpha():
                    c.append(mp.VideoFileClip("letters/%s-abc.mp4" % l).resize(height=320, width=240).speedx(factor=2))
            f = mp.concatenate_videoclips(c, method="compose")
            f.write_videofile("data/%d.mp4" % i)
        else:
            f = open("data/%d.mp4" % i, 'wb')
            for chunk in r.iter_content(chunk_size=255):
                if chunk:
                    f.write(chunk)
            f.close()

    clips = []
    for j in range(len(modified_urls)):
        clips.append(mp.VideoFileClip("data/%d.mp4" % j).resize(height=320, width=240))
                
    final_clip = mp.concatenate_videoclips(clips, method="compose")

    final_clip.write_videofile("final_clip.mp4")
    time.sleep(1)
    os.system("xdg-open final_clip.mp4")
    return spoken_text
github dannguyen / watson-word-watcher / foo / audio_video.py View on Github external
right_padding=0.01,
                                  video_codec=DEFAULT_VIDEO_CODEC,
                                  audio_codec=DEFAULT_VIDEO_AUDIO_CODEC):
    """
    creates a new video compiled from cuts of `src_path`

    timestamps (list): a sequence of tuples, in (start, end) (in seconds)
    """
    video = VideoFileClip(src_path)
    max_ts = video.duration
    clips = []
    for ts in timestamps:
        x = max(0, ts[0] - left_padding)
        y = min(max_ts, ts[1] + right_padding)
        clips.append(video.subclip(x, y))
    allclips = concatenate_videoclips(clips)
    allclips.write_videofile(dest_path, codec=video_codec, audio_codec=audio_codec)
    return dest_path
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)

    if isinstance(subs, str):
        subs = import_subs(movie_fol, subs, subs_delim)
    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))
github SenorPez / project-cars-replay-enhancer / replayenhancer / __init__.py View on Github external
except:
            pass

    if champion:
        pcre_series_champion = SeriesChampion(
            result_data.classification,
            size=source_video.size,
            **configuration)
        Image.fromarray(pcre_series_champion.to_frame()).save(
            output_prefix + '_series_champion.png')
        series_champion = mpy.ImageClip(
            pcre_series_champion.to_frame()).set_duration(20)

        end_titles.append(series_champion)

    output = mpy.concatenate_videoclips([starting_grid.fadeout(1), main_event] + [clip.fadein(1).fadeout(1) for clip in end_titles[:-1]] + [end_titles[-1].fadein(1)], method="compose")

    output.write_videofile(configuration['output_video'], fps=framerate)
github SenorPez / project-cars-replay-enhancer / replayenhancer / replayenhancer.py View on Github external
+ '_series_champion.png')
                series_standings = mpy.ImageClip(
                    pcre_series_standings.to_frame()).set_duration(20)
                end_titles.append(series_standings)
        else:
            pcre_series_champion = SeriesChampion(
                result_data.all_driver_classification,
                size=source_video.size,
                **configuration)
            Image.fromarray(pcre_series_champion.to_frame()).save(
                output_prefix + '_series_champion.png')
            series_champion = mpy.ImageClip(
                pcre_series_champion.to_frame()).set_duration(20)
            end_titles.append(series_champion)

    output = mpy.concatenate_videoclips(
        [starting_grid.fadeout(1), main_event]
        + [clip.fadein(1).fadeout(1) for clip in end_titles[:-1]]
        + [end_titles[-1].fadein(1)], method="compose")

    output.write_videofile(configuration['output_video'], fps=float(framerate))
github pelednoam / mmvt / src / utils / movies_utils.py View on Github external
def combine_movies(fol, final_movie_name, parts_names, fps=60, movie_type='mp4', threads=1):
    from moviepy.editor import VideoFileClip, concatenate_videoclips

    parts = [VideoFileClip(op.join(fol, '{}.{}'.format(movie_name, movie_type))) for movie_name in parts_names]
    final_movie = concatenate_videoclips(parts, method='chain')
    final_movie.write_videofile(op.join(fol, '{}.{}'.format(final_movie_name, movie_type)), fps=fps, threads=threads)
github balzss / compilation-bot / app.py View on Github external
clip = mp.VideoFileClip(f)
        bc_args = {'height':h}
        clip_args = {'width':w}
        center = {'x_center':w / 2}

        if clip.w / clip.h < 16 / 9:
            bc_args, clip_args = clip_args, bc_args
            center = {'y_center':h / 2}

        blurred_clip = clip.resize(**bc_args).crop(**center, **clip_args).fl_image(blur)
        clip = clip.resize(**clip_args).crop(x1=crop_size, width=w - crop_size * 2,
                y1=crop_size, height=h - crop_size * 2).margin(crop_size, color=(0, 0, 0))

        clip_list.append(mp.CompositeVideoClip([blurred_clip, clip.set_pos('center')]))

    final_clip = mp.concatenate_videoclips(clip_list).fadein(2).fadeout(2)
    final_clip.write_videofile('silent.mp4', fps=24, audio=None)

    FFmpeg(inputs={'silent.mp4': None, music_path: None}, outputs={'final.mp4': '-shortest'}).run()
    os.remove('silent.mp4')