How to use moviepy - 10 common examples

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 achalddave / vid / vid / vid.py View on Github external
from .utils.moviepy_wrappers.composite_clip import clips_array_maybe_none

    if len(videos) % num_rows != 0:
        raise ValueError('Number of videos (%s) is not evenly divisible by '
                         '--num_rows (%s). This is not supported right now.' %
                         (len(videos), num_rows))

    num_cols = len(videos) / num_rows

    from moviepy.video.io.VideoFileClip import VideoFileClip
    grid = [[] for _ in range(num_rows)]

    for i, video in enumerate(videos):
        row = int(i // num_cols)
        if video != blank_path:
            clip = VideoFileClip(str(video))
        else:
            clip = None
        grid[row].append(clip)

    set_image_clip_duration(grid)
    output_clip = clips_array_maybe_none(grid)
    if not save_audio:
        output_clip = output_clip.without_audio()
    output_clip.write_videofile(output, verbose=verbose, progress_bar=verbose)
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 metalbubble / moments_models / test_video.py View on Github external
with torch.no_grad():
    logits = model(input)
    h_x = F.softmax(logits, 1).mean(dim=0)
    probs, idx = h_x.sort(0, True)

# Output the prediction.
video_name = args.frame_folder if args.frame_folder is not None else args.video_file
print('RESULT ON ' + video_name)
for i in range(0, 5):
    print('{:.3f} -> {}'.format(probs[i], categories[idx[i]]))

# Render output frames with prediction text.
if args.rendered_output is not None:
    prediction = categories[idx[0]]
    rendered_frames = render_frames(frames, prediction)
    clip = mpy.ImageSequenceClip(rendered_frames, fps=4)
    clip.write_videofile(args.rendered_output)
github Zulko / moviepy / tests / test_PR.py View on Github external
def test_PR_515():
    # Won't actually work until video is in download_media
    with VideoFileClip("media/fire2.mp4", fps_source='tbr') as clip:
        assert clip.fps == 90000
    with VideoFileClip("media/fire2.mp4", fps_source='fps') as clip:
        assert clip.fps == 10.51
github ping / instagram_private_api_extensions / tests / test_media.py View on Github external
def test_remote_video(self):
        video_url = 'https://raw.githubusercontent.com/johndyer/mediaelement-files/master/big_buck_bunny.mp4'
        video_content, size, duration, thumbnail_content = media.prepare_video(
            video_url, aspect_ratios=1.0, max_duration=10.0)
        self.assertEqual(duration, 10.0, 'Invalid duration.')
        self.assertEqual(size[0], size[1], 'Invalid width/length.')
        self.assertGreater(len(video_content), 0, 'No video content returned.')
        self.assertGreater(len(thumbnail_content), 0, 'No thumbnail content returned.')

        # Save video, thumbnail content and verify attributes
        video_output = tempfile.NamedTemporaryFile(prefix='ipae_test_', suffix='.mp4', delete=False)
        video_output.write(video_content)
        video_output.close()
        with VideoFileClip(video_output.name) as vidclip_output:
            self.assertAlmostEqual(duration, vidclip_output.duration, places=0)
            self.assertEqual(size[0], vidclip_output.size[0])
            self.assertEqual(size[1], vidclip_output.size[1])

        im = Image.open(io.BytesIO(thumbnail_content))
        self.assertEqual(size[0], im.size[0])
        self.assertEqual(size[1], im.size[1])
github ping / instagram_private_api_extensions / tests / test_media.py View on Github external
def test_prepare_video3(self):
        video_content, size, duration, thumbnail_content = media.prepare_video(
            self.TEST_VIDEO_PATH, max_size=None, max_duration=1000.0,
            skip_reencoding=True, min_size=None)

        self.assertEqual(size[0], self.TEST_VIDEO_SIZE[0], 'Width changed.')
        self.assertEqual(size[1], self.TEST_VIDEO_SIZE[1], 'Height changed.')

        self.assertGreater(len(video_content), 0, 'No video content returned.')
        self.assertGreater(len(thumbnail_content), 0, 'No thumbnail content returned.')

        # Save video, thumbnail content and verify attributes
        video_output = tempfile.NamedTemporaryFile(prefix='ipae_test_', suffix='.mp4', delete=False)
        video_output.write(video_content)
        video_output.close()
        with VideoFileClip(video_output.name) as vidclip_output:
            self.assertAlmostEqual(duration, vidclip_output.duration, places=0)
            self.assertEqual(size[0], vidclip_output.size[0])
            self.assertEqual(size[1], vidclip_output.size[1])

        im = Image.open(io.BytesIO(thumbnail_content))
        self.assertEqual(size[0], im.size[0])
        self.assertEqual(size[1], im.size[1])

        self.assertEqual(
            os.path.getsize(video_output.name),
            os.path.getsize(self.TEST_VIDEO_PATH))
github Zulko / moviepy / tests / test_VideoClip.py View on Github external
def test_withoutaudio():
    clip = VideoFileClip("media/big_buck_bunny_432_433.webm").subclip(0.2, 0.6)
    new_clip = clip.without_audio()
    assert new_clip.audio is None
    close_all_clips(locals())
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 Zulko / moviepy / tests / test_TextClip.py View on Github external
def test_duration():

    clip = TextClip('hello world', size=(1280,720), color='white')
    clip = clip.set_duration(5) #  Changed due to #598.
    assert clip.duration == 5
    clip.close()

    clip2 = clip.fx(blink, d_on=1, d_off=1)
    clip2 = clip2.set_duration(5)
    assert clip2.duration == 5
    close_all_clips(locals())
github Zulko / moviepy / tests / test_fx.py View on Github external
def test_invert_colors():
    clip = get_test_video()
    clip1 = invert_colors(clip)
    clip1.write_videofile(os.path.join(TMP_DIR, "invert_colors1.webm"))
    close_all_clips(locals())