예제 #1
0
def test_slide_in():
    duration = 0.1
    size = (10, 1)
    fps = 10
    color = (255, 0, 0)

    # left and right sides
    clip = ColorClip(
        color=color,
        duration=duration,
        size=size,
    ).with_fps(fps)

    for side in ["left", "right"]:
        new_clip = CompositeVideoClip([slide_in(clip, duration, side)])

        for t in np.arange(0, duration, duration / fps):
            n_reds, n_reds_expected = (0, int(t * 100))

            if t:
                assert n_reds_expected

            if n_reds_expected == 7:  # skip 7 due to innacurate frame
                continue

            for r, g, b in new_clip.get_frame(t)[0]:
                if r == color[0] and g == color[1] and g == color[2]:
                    n_reds += 1

            assert n_reds == n_reds_expected

    # top and bottom sides
    clip = ColorClip(
        color=color,
        duration=duration,
        size=(size[1], size[0]),
    ).with_fps(fps)

    for side in ["top", "bottom"]:
        new_clip = CompositeVideoClip([slide_in(clip, duration, side)])
        for t in np.arange(0, duration, duration / fps):
            n_reds, n_reds_expected = (0, int(t * 100))

            if t:
                assert n_reds_expected

            if n_reds_expected == 7:  # skip 7 due to innacurate frame
                continue

            for row in new_clip.get_frame(t):
                r, g, b = row[0]

                if r == color[0] and g == color[1] and g == color[2]:
                    n_reds += 1

            assert n_reds == n_reds_expected
예제 #2
0
def make_comment(count=1, out_path="output", vid_file=None):
    vid_file = vid_file or get_random_mkv()
    log(u"Using {} as source...".format(os.path.basename(vid_file)))
    label = os.path.basename(vid_file).split(".")[0].replace(" ","").lower()
    vid_clip = VideoFileClip(vid_file)
    earliest = int(vid_clip.duration * 0.1)
    latest = int(vid_clip.duration * 0.9)
    valid_range = range(earliest, latest+1)

    sub_opts = make_sub_opts(vid_clip);
    with open("queue.txt", "a") as queue:
        real_lines = process_memorable_lines(20, 110)
        for n in range(1, count+1):
            ### this "None" will get a random SRT from corpora, by default.
            ### Can override with specific source file
            ### txt_line = get_nyer_caption(20, 110)
            ### txt_line = get_tweetable_line("corpora/tentacle-rough.txt", min_length=30, max_length=90)
            txt_line = choice(real_lines)
            debug(u"Using {} as subtitle...".format(txt_line.encode('utf8', 'ignore')))
            txt_clip = sub_generator(txt_line, **sub_opts)

            composed = CompositeVideoClip([vid_clip, txt_clip.set_pos("top")])
            frame = composed.get_frame(choice(valid_range))
            log(u"\tWriting {0} of {1:03d}...".format(n, count) )
            image_path = u"{0}/{1}_{2:03d}.png".format(out_path, label, n)
            imwrite(image_path, frame)
            queue.write(u"{0}{1}{2}\n".format(image_path, queue_separator, txt_line).encode('utf8', 'replace') )
예제 #3
0
def show(clip, t=0, with_mask=True, interactive=False):
    """
    Splashes the frame of clip corresponding to time ``t``.

    Parameters
    ----------

    t : float or tuple or str, optional
      Time in seconds of the frame to display.

    with_mask : bool, optional
      ``False`` if the clip has a mask but you want to see the clip without
      the mask.

    interactive : bool, optional
      Displays the image freezed and you can clip in each pixel to see the
      pixel number and its color.

    Examples
    --------

    >>> from moviepy.editor import *
    >>>
    >>> clip = VideoFileClip("media/chaplin.mp4")
    >>> clip.show(t=4, interactive=True)
    """
    if with_mask and (clip.mask is not None):
        clip = CompositeVideoClip([clip.with_position((0, 0))])

    img = clip.get_frame(t)
    imdisplay(img)

    if interactive:
        result = []
        while True:
            for event in pg.event.get():
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_ESCAPE:
                        print("Keyboard interrupt")
                        return result
                elif event.type == pg.MOUSEBUTTONDOWN:
                    x, y = pg.mouse.get_pos()
                    rgb = img[y, x]
                    result.append({"position": (x, y), "color": rgb})
                    print("position, color : ", "%s, %s" % (str(
                        (x, y)), str(rgb)))
            time.sleep(0.03)
예제 #4
0
파일: preview.py 프로젝트: zivzone/moviepy
def show(clip, t=0, with_mask=True, interactive=False):
    """
    Splashes the frame of clip corresponding to time ``t``.

    Parameters
    ------------

    t
      Time in seconds of the frame to display.

    with_mask
      ``False`` if the clip has a mask but you want to see the clip
      without the mask.

    """

    if isinstance(t, tuple):
        t = convert_to_seconds(*t)

    if with_mask and (clip.mask is not None):
        clip = CompositeVideoClip([clip.with_position((0, 0))])

    img = clip.get_frame(t)
    imdisplay(img)

    if interactive:
        result = []
        while True:
            for event in pg.event.get():
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_ESCAPE:
                        print("Keyboard interrupt")
                        return result
                elif event.type == pg.MOUSEBUTTONDOWN:
                    x, y = pg.mouse.get_pos()
                    rgb = img[y, x]
                    result.append({"position": (x, y), "color": rgb})
                    print("position, color : ", "%s, %s" % (str(
                        (x, y)), str(rgb)))
            time.sleep(0.03)