Examples¶
Stitch Videos¶
from vidpy import Clip, Composition
clip1 = Clip('videos/hand1.mp4')
clip2 = Clip('videos/hand2.mp4')
clip3 = Clip('videos/hand3.mp4')
clips = [clip1, clip2, clip3]
# stitch all clips together
stiched = Composition(clips, singletrack=True)
stiched.save('allvids.mp4')
# stitch the first second of all clips
for clip in clips:
clip.cut(start=0, end=1)
stiched = Composition(clips, singletrack=True)
stiched.save('firstsecond.mp4')
Video Grid¶
from vidpy import Clip, Composition
video = 'videos/hand1.mp4'
canvas_width = 1280
canvas_height = 720
vid_width = canvas_width/3
vid_height = (vid_width/canvas_width) * canvas_height
x = 0
y = 0
clips = []
while y < canvas_height:
# create a clip
clip = Clip(video)
# set clip position
clip.position(x=x, y=y, w=vid_width, h=vid_height)
# fade in for 1/2 second
clip.fadein(0.5)
# repeat the clip three times
clip.repeat(3)
# start the clip based on existing clips
clip.set_offset(len(clips)*.1)
clips.append(clip)
# increment the x and y position
x += vid_width
if x > canvas_width:
y += vid_height
x = 0
grid = Composition(clips, width=canvas_width, height=canvas_height)
grid.save('grid.mp4')
Masks¶
from vidpy import Clip, Composition
background_clip = Clip('videos/hand1.mp4')
clip = Clip('videos/hand2.mp4')
# create a clip to use a as a mask
# you can use use a video,text clip or an image
mask = Clip('videos/mask.png')
# you can also add effects to the mask
mask.glow('0=0;200=.9')
# make sure that the duration of the mask is the same as the clip
# (or don't, if you only want the mask to affect part of the clip)
mask.set_duration(clip.duration)
# set the mask on the clip
clip.set_mask(mask)
comp = Composition([background_clip, clip])
comp.preview()
Auto Chroma Key¶
from vidpy import Clip, Composition
video = 'videos/hand1.mp4'
clips = []
for i in range(0, 5):
clip = Clip(video)
# attempt to automatically remove background color
# you can also specify a color with color='#00ff00'
clip.chroma(amount=0.2)
# start the clips 1/2 second after last clip
clip.set_offset(i * 0.5)
# change the clips x coordinate
clip.position(x=(i*100)-300)
# loop the clip 3 times
clip.repeat(3)
clips.append(clip)
comp = Composition(clips, bgcolor='#ff4dff', duration=4)
comp.save('chroma_overlay.mp4')
Text¶
import random
from vidpy import Text, Clip, Composition
lines = '''A spectre is haunting Europe -
the spectre of communism.
All the powers of old Europe
have entered into a holy alliance
to exorcise this spectre:
Pope and Tsar,
Metternich and Guizot,
French Radicals and German police-spies.
Where is the party in opposition that
has not been decried as communistic by its opponents in power?
Where is the opposition
that has not hurled back
the branding reproach of communism,
against the more advanced opposition parties,
as well as against its reactionary adversaries?
Two things result from this fact:
I. Communism is already acknowledged
by all European powers to be itself a power.
II. It is high time that Communists should openly,
in the face of the whole world,
publish their views,
their aims,
their tendencies,
and meet this nursery tale
of the Spectre of Communism
with a manifesto of the party itself.'''.split('\n')
# some random style choices
fonts = ['Helvetica', 'Comic Sans MS', 'Andale Mono']
styles = ['normal', 'italic']
colors = ['#ff5179', '#43f8ff', '#a0ff5f', '#ffed00']
clips = []
for line in lines:
# select random attributes
font = random.choice(fonts)
color = random.choice(colors)
outline_color = random.choice(colors)
outline_size = random.randint(3, 8)
weight = random.randint(100, 1000)
style = random.choice(styles)
# put the text in a bounding box that fills 90% of the screen
# (x, y, width, height)
boundingbox = ('10%', '10%', '80%', '80%')
# create a one second text clip with random parameters
text = Text(line, end=1, color=color, font=font, style=style, weight=weight, olcolor=outline_color, outline=outline_size, size=200, bbox=boundingbox, pad=50)
# add a glow for some reason!
text.glow(1)
clips.append(text)
comp = Composition(clips, singletrack=True, width=1280, height=720, fps=30)
comp.save('manifesto.mp4')
Filter gallery¶
from vidpy import Composition, Clip
vid = 'videos/hand3.mp4'
filters = {
'brightness': [.8],
'contrast': [.9],
'opacity': [.1],
'hue': [.8],
'saturate': [.9],
'grayscale': [],
'threshold': [],
'dynamic_threshold': [],
'invert': [],
'extract_color': [],
'glow': [],
'softglow': [],
'cartoon': [0.9],
'chroma': [],
'vflip': [],
'hflip': [],
'position': [100, 100, '30%', '30%'],
'move': [[(0, '-100%', '-100%', '100%', '100%'), (30, 0, 0, '100%', '100%')]],
'charcoal': [],
'dust': [],
'grain': [],
'vignette': [],
'mirror': [],
'squareblur': [.01],
'sharpness': [1],
'luminance': [],
'posterize': [],
'pixelize': [],
'gradient': [],
}
clips = []
for f in filters:
clip = Clip(vid, start=0, end=1)
clip.volume(0)
args = filters[f]
if len(args) > 0:
getattr(clip, f)(*args)
else:
getattr(clip, f)()
clip.text(f, olcolor='#000000', outline=10)
clips.append(clip)
Composition(clips, singletrack=True).preview()
Camera¶
from vidpy import Composition, Camera
clip = Camera(width=1280, height=720, start=0, end=5)
clip.spin(2)
Composition([clip]).save('camera.mp4')