Ejemplo n.º 1
0
def test_loop():
    clip = get_test_video()
    clip1 = loop(clip).set_duration(3)  # infinite looping
    clip1.write_videofile(os.path.join(TMP_DIR, "loop1.webm"))

    return  # Still buggy. TODO fix
    clip2 = loop(clip, duration=10)  # loop for 10 seconds
    clip2.write_videofile(os.path.join(TMP_DIR, "loop2.webm"))

    clip3 = loop(clip, n=3)  # loop 3 times
    clip3.write_videofile(os.path.join(TMP_DIR, "loop3.webm"))
    close_all_clips(objects=locals())
Ejemplo n.º 2
0
def combine_video_with_audio(video_path: str,
                             audio_path: str,
                             result_path: str,
                             fps: int = 60):
    short_clip = VideoFileClip(filename=video_path)
    audio_background = AudioFileClip(filename=audio_path)

    full_video = loop(short_clip, duration=audio_background.duration)
    final_clip = full_video.set_audio(audioclip=audio_background)

    final_clip.write_videofile(result_path, fps=fps)
Ejemplo n.º 3
0
def test_loop():
    clip = BitmapClip([["R"], ["G"], ["B"]], fps=1)

    clip1 = loop(clip, n=2)  # loop 2 times
    target1 = BitmapClip([["R"], ["G"], ["B"], ["R"], ["G"], ["B"]], fps=1)
    assert clip1 == target1

    clip2 = loop(clip, duration=8)  # loop 8 seconds
    target2 = BitmapClip(
        [["R"], ["G"], ["B"], ["R"], ["G"], ["B"], ["R"], ["G"]], fps=1)
    assert clip2 == target2

    clip3 = loop(clip).with_duration(5)  # infinite loop
    target3 = BitmapClip([["R"], ["G"], ["B"], ["R"], ["G"]], fps=1)
    assert clip3 == target3

    clip = get_test_video()
    clip1 = loop(clip).with_duration(3)  # infinite looping
    clip1.write_videofile(os.path.join(TMP_DIR, "loop1.webm"))

    return  # Still buggy. TODO fix
Ejemplo n.º 4
0
def test_find_audio_period(mono_wave, stereo_wave, wave_type):
    if wave_type == "mono":
        wave1 = mono_wave(freq=400)
        wave2 = mono_wave(freq=100)
    else:
        wave1 = stereo_wave(left_freq=400, right_freq=220)
        wave2 = stereo_wave(left_freq=100, right_freq=200)
    clip = CompositeAudioClip([
        AudioClip(make_frame=wave1, duration=0.3, fps=22050),
        multiply_volume(
            AudioClip(make_frame=wave2, duration=0.3, fps=22050),
            0,
            end_time=0.1,
        ),
    ])
    loop_clip = loop(clip, 4)
    assert round(find_audio_period(loop_clip),
                 6) == pytest.approx(0.29932, 0.1)
Ejemplo n.º 5
0
def process_clip(clip, sound):
    base_clip = clip
    base_clip = resize.resize(base_clip, width=640, height=480)
    title_tts = mp.AudioFileClip(sound.dest + "/title" + sound.filename +
                                 ".mp3").set_start(0)
    title_clip = mp.TextClip(sound.title,
                             fontsize=50,
                             color="white",
                             font="garamond",
                             method="caption",
                             size=(base_clip.size[0], None))
    title_clip = title_clip.on_color(
        size=(title_clip.size[0] + 10, title_clip.size[1] + 10),
        col_opacity=0.5).set_duration(
            title_tts.duration).set_position("center")
    title_clip = fadein.fadein(title_clip, 0.2, (255, 255, 255))

    comment_tts = mp.AudioFileClip(sound.dest + "/comment" + sound.filename +
                                   ".mp3")
    comment_time = max(
        min(base_clip.duration - comment_tts.duration, base_clip.duration / 2),
        title_tts.duration + 1)
    comment_clip = mp.TextClip(sound.top_comment,
                               fontsize=20,
                               color="white",
                               method="caption",
                               size=(base_clip.size[0],
                                     None)).on_color(col_opacity=0.5)
    comment_clip = comment_clip.set_duration(
        comment_tts.duration).set_start(comment_time).set_position("bottom")
    comment_clip = fadein.fadein(comment_clip, 0.2, (255, 255, 255))
    comment_tts = comment_tts.set_start(comment_time)

    audio = mp.CompositeAudioClip([title_tts, comment_tts])
    base_clip = loop.loop(base_clip,
                          duration=max(base_clip.duration, audio.duration + 1))
    newclip = mp.CompositeVideoClip([base_clip, title_clip, comment_clip])
    return newclip.set_audio(audio)
Ejemplo n.º 6
0
def create_scene(face):
    # Scenes are 10 seconds long and consist of:
    # - A background video
    # - The face overlay in a frame
    # - Random interspersed vaporgifs OOPS MOVIEPY SCREWED UP THE GIFS
    composites = []

    # Frame the face
    frame = get_random_frame_clip()
    framed_face = insert_image_into_frame(frame, face)

    f = instantiate_overlay(framed_face)
    framed_face = framed_face.set_pos(f)
    
    composites.append(framed_face)

    # Place the frame on a random video
    bg = get_random_bg()
    composites.insert(0, bg)

    # Place some random overlays
    for i in range(random.randint(1, 3)):
        path = pick_random_entry_from_dir('sources/secondary/')
        clip = None
        hover = False

        if path.endswith('.mp4'):
            clip = VideoFileClip(path)
            clip = clip.resize((220, 220))
            clip = loop.loop(clip, duration=10)
        else:
            clip = ImageClip(path)
            hover = True

        f = instantiate_overlay(clip, hover)
        clip = clip.set_pos(f)

        standardize_clip(clip)
        composites.append(clip)

    # Jaden Smith quote?
    with open('sources/text-overlays.txt', 'r') as texts:
        lines = texts.readlines()
        quote = random.choice(lines).split(' - ')

        quote_layer = TextClip(txt=quote[1], color='white',
            font='Times-New-Roman', stroke_color='black', stroke_width=2.0,
            fontsize=64, method='caption', size=(1100, 200))

        date_layer = TextClip(txt=quote[0], color='white',
            font='Courier', stroke_color='black', stroke_width=2.0,
            fontsize=50)

        quote_layer = quote_layer.set_pos((30, 30))
        date_layer = date_layer.set_pos((10, 650))

        composites.append(quote_layer)
        composites.append(date_layer)
    
    composite = CompositeVideoClip(composites, (1280, 720))
    standardize_clip(composite)

    return composite