Ejemplo n.º 1
0
 def _make_circle(radius, color=(0, 255, 0)):
     circle_clip = ImageClip(
         circle((2 * radius, 2 * radius), (radius, radius), radius, color,
                (0, 0, 0)))
     #Make mask from it (channel 1 - green) since it's single color
     circle_mask = ImageClip(circle((2 * radius, 2 * radius),
                                    (radius, radius), radius, 1, 0),
                             ismask=True)
     #And use it as a mask
     circle_clip = circle_clip.set_mask(circle_mask)
     return circle_clip, radius
Ejemplo n.º 2
0
    def step5(self, text, images, save_name):
        blackimage = np.zeros([self.screen[1], self.screen[0], 3], dtype=np.uint8)
        blackimage.fill(0)
        gap = self.step5_duration / len(images)
        step5_video = ImageClip(blackimage).set_duration(self.step5_duration)
        clip_images = [
            ImageClip(x).set_duration(gap).set_position('center').set_start(i * gap).resize(height=self.screen[1])
            for i,x in enumerate(images)
        ]
        step5_text_video = TextClip(text.encode('utf-8'), fontsize=20, color='white',
                                    font=self.font) \
            .set_duration(3).set_position("center")



        step5_video = CompositeVideoClip([step5_video] + clip_images+ [step5_text_video]).fadein(1)

        step5_video.mask.get_frame = lambda t: circle(screensize=(step5_video.w, step5_video.h),
                                               center=(step5_video.w / 2, step5_video.h / 4),
                                               radius=max(0, int(500 - 50 * (t+2) * 2)),
                                               col1=1, col2=0, blur=4)

        self.saveVideo(step5_video, save_name)

        return True
Ejemplo n.º 3
0
def test_color_gradient(
    size,
    p1,
    p2,
    vector,
    radius,
    color_1,
    color_2,
    shape,
    offset,
    expected_result,
):
    if isinstance(expected_result, np.ndarray):
        result = color_gradient(
            size,
            p1,
            p2=p2,
            vector=vector,
            radius=radius,
            color_1=color_1,
            color_2=color_2,
            shape=shape,
            offset=offset,
        )

        assert expected_result.shape == result.shape
        assert np.array_equal(result, expected_result)

        if shape == "radial":

            circle_result = circle(
                size,
                p1,
                radius,
                color=color_1,
                bg_color=color_2,
            )
            assert np.array_equal(result, circle_result)
    else:
        if isinstance(expected_result, (list, tuple)):
            expected_error, expected_message = expected_result
        else:
            expected_error, expected_message = (expected_result, None)

        with pytest.raises(expected_error) as exc:
            color_gradient(
                size,
                p1,
                p2=p2,
                vector=vector,
                radius=radius,
                color_1=color_1,
                color_2=color_2,
                shape=shape,
                offset=offset,
            )
        if expected_message is not None:
            assert str(exc.value) == expected_message
Ejemplo n.º 4
0
def makeVideoRPS(gif_filename,
                 winner_screen_name,
                 winner_rpc,
                 loser_screen_name,
                 loser_rpc,
                 hashtext,
                 winner_rhs=True):

    duel_filename = duelFilename(winner_screen_name, winner_rpc,
                                 loser_screen_name, loser_rpc, hashtext,
                                 winner_rhs)

    duel = VideoFileClip(duel_filename).add_mask()

    w, h = duel.size
    duel.mask.get_frame = lambda t: circle(screensize=(duel.w, duel.h),
                                           center=(duel.w / 2, duel.h / 4),
                                           radius=max(0, int(1000 - 200 * t)),
                                           col1=1,
                                           col2=0,
                                           blur=4)
    v_text = vText(winner_screen_name, loser_screen_name, winner_rhs)
    v = TextClip(v_text, fontsize=30, font='Xolonium-Bold', color='yellow')
    v = v.set_pos('center').set_duration(1)
    v_sized = CompositeVideoClip([v.set_pos('center')], size=(w, h))

    bot = TextClip("#RockPaperScissors referee: @RPSrobot ",
                   font="Amiri-Bold",
                   fontsize=20,
                   color="white")
    bot = bot.set_duration(3.5)
    bot = CompositeVideoClip([bot.set_pos(("right", "top"))], size=(w, h))

    winner = TextClip(wText(winner_screen_name),
                      font="Amiri-bold",
                      color="red",
                      fontsize=60)
    winner_end = winner.set_duration(1)
    winner_end_sized = CompositeVideoClip(
        [winner_end.set_pos(("center", "bottom"))], size=(w, h))

    winner_mask = winner.set_duration(duel.duration)

    final = CompositeVideoClip(
        [winner_mask.set_pos(("center", "bottom")), duel], size=duel.size)

    duel_bot = CompositeVideoClip([final, bot])
    final_clip = concatenate_videoclips([v_sized, duel_bot,
                                         winner_end_sized]).resize(width=496)
    final_clip.write_gif(gif_filename, fps=10)
Ejemplo n.º 5
0
from moviepy import *
from moviepy.video.tools.drawing import circle

clip = (
    VideoFileClip("../../videos/badl-0006.mov", audio=False).subclip(26, 31).add_mask()
)

w, h = clip.size

# The mask is a circle with vanishing radius r(t) = 800-200*t
clip.mask.get_frame = lambda t: circle(
    screensize=(clip.w, clip.h),
    center=(clip.w / 2, clip.h / 4),
    radius=max(0, int(800 - 200 * t)),
    color=1,
    bg_color=0,
    blur=4,
)


the_end = TextClip(
    "The End", font="Amiri-bold", color="white", font_size=70
).with_duration(clip.duration)

final = CompositeVideoClip([the_end.set_pos("center"), clip], size=clip.size)

final.write_videofile("../../theEnd.avi")
Ejemplo n.º 6
0
from moviepy.editor import *
from moviepy.video.tools.drawing import circle

clip = VideoFileClip("../../videos/badl-0006.mov", audio=False).\
           subclip(26,31).\
           add_mask()
           
w,h = clip.size

# The mask is a circle with vanishing radius r(t) = 800-200*t               
clip.mask.get_frame = lambda t: circle(screensize=(clip.w,clip.h),
                                       center=(clip.w/2,clip.h/4),
                                       radius=max(0,int(800-200*t)),
                                       col1=1, col2=0, blur=4)


the_end = TextClip("The End", font="Amiri-bold", color="white",
                   fontsize=70).set_duration(clip.duration)

final = CompositeVideoClip([the_end.set_pos('center'),clip],
                           size =clip.size)
                           
final.write_videofile("../../theEnd.avi")
Ejemplo n.º 7
0
# -*- coding: utf-8 -*-
from moviepy.editor import *
from moviepy.video.tools.drawing import circle

main_clip = VideoFileClip("Thanksgiving.mp4")
start_clip = main_clip.subclip("00:00:00.00", "00:02:34.00")
end_clip = main_clip.subclip("00:02:34.00", "00:02:37.00").add_mask()

w, h = main_clip.size

# The mask is a circle with vanishing radius r(t) = 800-200*t
end_clip.mask.get_frame = lambda t: circle(
    screensize=(main_clip.w, main_clip.h),
    center=(main_clip.w / 2, main_clip.h / 4),
    radius=max(0, int(800 - 200 * t)),
    col1=1,
    col2=0,
    blur=4)

the_end = TextClip("The End", font="Amiri-bold", color="white",
                   fontsize=70).set_duration(end_clip.duration)
#set_duration(clip.duration)
#the_end.set_start("00:00:10.00")
#end_clip.set_start("00:00:10.00")
final = CompositeVideoClip([the_end.set_pos('center'), end_clip],
                           size=main_clip.size)

final.write_videofile("theEnd.mp4")

#end_clip = VideoFileClip("theEnd.mp4")
#final = concatenate_videoclips([start_clip, end_clip]).write_videofile("final.mp4")
Ejemplo n.º 8
0
from moviepy.editor import *
from moviepy.video.tools.drawing import circle

clip = VideoFileClip("../sub1.mp4", audio=False).add_mask()

w, h = clip.size
print(clip.size)
# The mask is a circle with vanishing radius r(t) = 800-200*t
clip.mask.get_frame = lambda t: circle(screensize=(clip.w, clip.h),
                                       center=(clip.w / 2, clip.h / 4),
                                       radius=max(0, int(100 - 1 * t)),
                                       col1=1,
                                       col2=0,
                                       blur=4)

the_end = TextClip("The End", font="Amiri-bold", color="white",
                   fontsize=70).set_duration(clip.duration)

final = CompositeVideoClip([the_end.set_pos('center'), clip], size=clip.size)

# final.write_videofile("../../theEnd.avi")
final.preview()
Ejemplo n.º 9
0
print test_mask.shape

# In[ ]:

from moviepy.editor import *
from moviepy.video.tools.drawing import circle

clip = VideoFileClip("motion_test.mov", audio=False).add_mask()
clip2 = VideoFileClip("motion_test.mov", audio=False).add_mask()

w, h = clip.size

# This mask creates a persistent black circle.
clip.mask.get_frame = lambda t: circle(screensize=(clip.w, clip.h),
                                       center=(clip.w / 10, clip.h / 5),
                                       radius=50,
                                       col1=0,
                                       col2=1,
                                       blur=4)

# The mask is a circle with vanishing radius r(t) = 800-200*t that
# conditionally "erases" the persistent circle when motion is detected.
clip2.mask.get_frame = lambda t: circle(screensize=(clip.w, clip.h),
                                        center=(clip.w / 10, clip.h / 5),
                                        radius=test_func(t),
                                        col1=1,
                                        col2=0,
                                        blur=4)

final = CompositeVideoClip([clip, clip2], size=clip.size)

final.write_videofile("motion_test_outcomeII.mp4")