Ejemplo n.º 1
0
def create_linear_mask_clip(lsz,dir='r'):
	if dir == 'r' or dir == 'l':
		dh = lsz[0]/3
		ph1 = (dh*1,0)
		ph2 = (dh*2,0)
		if dir == 'r':
			c1 = 0
			c2 = 1.0
		else:
			c1 = 1.0
			c2 = 0
		grad = color_gradient(lsz, p1=ph1, p2=ph2, col1=c1, col2=c2)
	elif dir == 'u' or dir == 'd':
		dh = lsz[1]/3
		ph1 = (0,dh*1)
		ph2 = (0,dh*2)
		if dir == 'u':
			c1 = 0
			c2 = 1.0
		else:
			c1 = 1.0
			c2 = 0
		grad = color_gradient(lsz, p1=ph1, p2=ph2, col1=c1, col2=c2)

	return ImageClip(grad,ismask=True)
Ejemplo n.º 2
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.º 3
0
def clip_brush_fade_in(clip,easefxn=None,dur=0.5,dir='r'):
	efxn = eas.easeOutExpo if easefxn == None else easefxn
	w, h = clip.size
	stx = 0
	edx = 0
	dtype = ''
	if dir == 'r' or dir == 'l':
		dtype = 'h'
		wsz = (w*3,h)
		dhh = wsz[0]
		dh = w
		ph1 = (dh*1,0)
		ph2 = (dh*2,0)
		if dir == 'r':
			c1 = 0
			c2 = 1.0
			stx = dhh - dh
			edx = 0
		else:
			c1 = 1.0
			c2 = 0
			stx = 0
			edx = dhh - dh
	elif dir == 'u' or dir == 'd':
		dtype = 'v'
		wsz = (w,h*3)
		dhh = wsz[1]
		dh = h
		ph1 = (0,dh*1)
		ph2 = (0,dh*2)
		if dir == 'u':
			c1 = 1.
			c2 = 0
			stx = 0
			edx = dhh - dh
		else:
			c1 = 0
			c2 = 1.
			stx = dhh - dh
			edx = 0
			
	mgrad = color_gradient(wsz, p1=ph1, p2=ph2, col1=c1, col2=c2)
	
	chx = edx - stx
	
	def fl(gf, t):
		curx = eas.tween(efxn, t, stx, chx, dur)
		curg = mgrad[:,int(curx):int(curx+dh)] if dtype=='h' else mgrad[int(curx):int(curx+dh),:]
		f = gf(t)
		om = np.zeros(f.shape)
		om[:,:] = 1-curg
		return np.clip(f-om,0.,1.)

	if clip.mask is None:
		clip = clip.add_mask()
	clip.mask = clip.mask.fl(fl)
	return clip
Ejemplo n.º 4
0
 def make_transparent_map_clip(self, map_clip_coordinate):
     map_clip, center_coordinate = map_clip_coordinate
     map_w = map_clip.w
     map_h = map_clip.h
     #Makes radial mask which is used to blur map as a circle with transparent
     #background
     map_mask = color_gradient((map_w, map_h), (map_w / 2, map_h / 2),
                               (map_h / 2, 0),
                               offset=0.9,
                               shape='radial',
                               col1=1,
                               col2=0.0)
     map_mask_clip = ImageClip(map_mask, ismask=True)
     map_clip = map_clip.set_mask(map_mask_clip)
     map_clip = map_clip.set_opacity(0.7)
     return self.make_map_clip((map_clip, center_coordinate))
Ejemplo n.º 5
0
def test_ffmpeg_write_image(util, size, logfile, pixel_format,
                            expected_result):
    filename = os.path.join(util.TMP_DIR, "moviepy_ffmpeg_write_image.png")
    if os.path.isfile(filename):
        try:
            os.remove(filename)
        except PermissionError:
            pass

    image_array = color_gradient(
        size,
        (0, 0),
        p2=(5, 0),
        color_1=(255, 0, 0),
        color_2=(0, 255, 0),
    )

    if hasattr(expected_result[0], "__traceback__"):
        with pytest.raises(expected_result[0]) as exc:
            ffmpeg_write_image(
                filename,
                image_array,
                logfile=logfile,
                pixel_format=pixel_format,
            )
        assert expected_result[1] in str(exc.value)
        return
    else:
        ffmpeg_write_image(
            filename,
            image_array,
            logfile=logfile,
            pixel_format=pixel_format,
        )

    assert os.path.isfile(filename)

    if logfile:
        assert os.path.isfile(filename + ".log")
        os.remove(filename + ".log")

    im = Image.open(filename, mode="r")
    for i in range(im.width):
        for j in range(im.height):
            assert im.getpixel((i, j)) == expected_result[j][i]
Ejemplo n.º 6
0

clip_txt = TextClip(txt,color='white', align='West',fontsize=25,
                    font='Xolonium-Bold', method='label')


# SCROLL THE TEXT IMAGE BY CROPPING A MOVING AREA

txt_speed = 27
fl = lambda gf,t : gf(t)[int(txt_speed*t):int(txt_speed*t)+h,:]
moving_txt= clip_txt.fl(fl, apply_to=['mask'])


# ADD A VANISHING EFFECT ON THE TEXT WITH A GRADIENT MASK

grad = color_gradient(moving_txt.size,p1=(0,2*h/3),
                p2=(0,h/4),col1=0.0,col2=1.0)
gradmask = ImageClip(grad,ismask=True)
fl = lambda pic : np.minimum(pic,gradmask.img)
moving_txt.mask = moving_txt.mask.fl_image(fl)


# WARP THE TEXT INTO A TRAPEZOID (PERSPECTIVE EFFECT)

def trapzWarp(pic,cx,cy,ismask=False):
    """ Complicated function (will be latex packaged as a fx) """
    Y,X = pic.shape[:2]
    src = np.array([[0,0],[X,0],[X,Y],[0,Y]])
    dst = np.array([[cx*X,cy*Y],[(1-cx)*X,cy*Y],[X,Y],[0,Y]])
    tform = tf.ProjectiveTransform()
    tform.estimate(src,dst)
    im = tf.warp(pic, tform.inverse, output_shape=(Y,X))
Ejemplo n.º 7
0
                    align="West",
                    font_size=25,
                    font="Xolonium-Bold",
                    method="label")

# SCROLL THE TEXT IMAGE BY CROPPING A MOVING AREA

txt_speed = 27
fl = lambda gf, t: gf(t)[int(txt_speed * t):int(txt_speed * t) + h, :]
moving_txt = clip_txt.transform(fl, apply_to=["mask"])

# ADD A VANISHING EFFECT ON THE TEXT WITH A GRADIENT MASK

grad = color_gradient(moving_txt.size,
                      p1=(0, 2 * h / 3),
                      p2=(0, h / 4),
                      color_1=0.0,
                      color_2=1.0)
gradmask = ImageClip(grad, is_mask=True)
fl = lambda pic: np.minimum(pic, gradmask.img)
moving_txt.mask = moving_txt.mask.image_transform(fl)

# WARP THE TEXT INTO A TRAPEZOID (PERSPECTIVE EFFECT)


def trapzWarp(pic, cx, cy, is_mask=False):
    """ Complicated function (will be latex packaged as a fx) """
    Y, X = pic.shape[:2]
    src = np.array([[0, 0], [X, 0], [X, Y], [0, Y]])
    dst = np.array([[cx * X, cy * Y], [(1 - cx) * X, cy * Y], [X, Y], [0, Y]])
    tform = tf.ProjectiveTransform()
Ejemplo n.º 8
0


# === MY HANDS PLAYING THE PIANO

# layered semi-transparent mask

piano = ( VideoFileClip("./limehouse_me.mp4")
           .subclip(0.5, 36)
           .set_audio(audio_shifted)
           .set_mask(mask))

W,H = piano.size

mask = ImageClip(color_gradient(piano.size,
                 p1=[0,0], p2=[0, 2*H/3],
                col1=1.0, col2=0), ismask=True)

piano = piano.set_mask(mask)



# === THE SHEET-MUSIC, WITH A SCROLLING EFFECT

sheet = ( ImageClip("./final.png")
           .fx( vfx.scroll,h= 1.5*H, y_speed=43)
           .set_duration(piano_s.duration)
           .fx( vfx.freeze_at_start, .5)
           .resize(width=W))

Ejemplo n.º 9
0
            face_index = 0

    movie_clip = concatenate_videoclips(scenes)

    # Place the sound
    sound_path = pick_random_entry_from_dir('sources/soundtrack/')
    soundtrack = AudioFileClip(sound_path)
    soundtrack = soundtrack.subclip(0, 30)
    movie_clip = movie_clip.set_audio(soundtrack)

    return movie_clip


movie = create_movie(face_images)
gradient = color_gradient(size=(1280, 720),
    p1=(640, 60), p2=(640, 660),
    col1=np.array([195, 75, 99], 'uint8'),
    col2=np.array([127, 251, 19], 'uint8'),
    shape='linear')

gradient_clip = ImageClip(gradient)
gradient_clip = gradient_clip.set_opacity(0.20)
standardize_clip(gradient_clip)

movie = CompositeVideoClip([movie, gradient_clip], movie.size)
movie.duration = 30

movie.save_frame('frame.jpg')
#movie.preview(fps=10, audio=False)
#movie.duration = 1
movie.write_videofile('composite.mp4')
Ejemplo n.º 10
0

clip_txt = TextClip(txt,color='white', align='West',fontsize=25,
                    font='Xolonium-Bold', method='label')


# SCROLL THE TEXT IMAGE BY CROPPING A MOVING AREA

txt_speed = 27
fl = lambda gf,t : gf(t)[int(txt_speed*t):int(txt_speed*t)+h,:]
moving_txt= clip_txt.fl(fl, apply_to=['mask'])


# ADD A VANISHING EFFECT ON THE TEXT WITH A GRADIENT MASK

grad = color_gradient(moving_txt.tamano,p1=(0,2*h/3),
                p2=(0,h/4),col1=0.0,col2=1.0)
gradmask = ImageClip(grad,ismask=True)
fl = lambda pic : np.minimum(pic,gradmask.img)
moving_txt.mask = moving_txt.mask.fl_image(fl)


# WARP THE TEXT INTO A TRAPEZOID (PERSPECTIVE EFFECT)

def trapzWarp(pic,cx,cy,ismask=False):
    """ Complicated function (will be latex packaged as a fx) """
    Y,X = pic.shape[:2]
    src = np.array([[0,0],[X,0],[X,Y],[0,Y]])
    dst = np.array([[cx*X,cy*Y],[(1-cx)*X,cy*Y],[X,Y],[0,Y]])
    tform = tf.ProjectiveTransform()
    tform.estimate(src,dst)
    im = tf.warp(pic, tform.inverse, output_shape=(Y,X))