本文整理汇总了Python中moviepy.Clip.Clip类的典型用法代码示例。如果您正苦于以下问题:Python Clip类的具体用法?Python Clip怎么用?Python Clip使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Clip类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, clips):
Clip.__init__(self)
self.clips = clips
ends = [c.end for c in self.clips]
self.nchannels = max([c.nchannels for c in self.clips])
if not any([(e is None) for e in ends]):
self.duration = max(ends)
self.end = max(ends)
def make_frame(t):
played_parts = [c.is_playing(t) for c in self.clips]
sounds= [c.get_frame(t - c.start)*np.array([part]).T
for c,part in zip(self.clips, played_parts)
if (part is not False) ]
if isinstance(t,np.ndarray):
zero = np.zeros((len(t),self.nchannels))
else:
zero = np.zeros(self.nchannels)
return zero + sum(sounds)
self.make_frame = make_frame
示例2: __init__
def __init__(self, ismask=False):
Clip.__init__(self)
self.mask = None
self.audio = None
self.pos = lambda t: (0, 0)
self.relative_pos = False
self.ismask = ismask
示例3: __init__
def __init__(self, get_frame = None):
Clip.__init__(self)
if get_frame:
self.get_frame = get_frame
frame0 = self.get_frame(0)
if hasattr(frame0, '__iter__'):
self.nchannels = len(list(frame0))
else:
self.nchannels = 1
示例4: __init__
def __init__(self, filename, buffersize=200000, nbytes=2, fps=44100):
Clip.__init__(self)
self.filename = filename
self.reader = FFMPEG_AudioReader(filename,fps=fps,nbytes=nbytes,
bufsize=buffersize+100)
self.fps = fps
self.duration = self.reader.duration
self.end = self.duration
self.nframes = self.reader.nframes
self.buffersize= buffersize
self.buffer= None
self._fstart_buffer = 1
self._buffer_around(1)
def gf(t):
bufsize = self.buffersize
if isinstance(t,np.ndarray):
# lazy implementation, but should not cause problems in
# 99.99 % of the cases
result = np.zeros((len(t),2))
in_time = (t>=0) & (t < self.duration)
inds = (self.fps*t+1).astype(int)[in_time]
f_tmin, f_tmax = inds.min(), inds.max()
if not (0 <= (f_tmin - self._fstart_buffer) < len(self.buffer)):
self._buffer_around(f_tmin)
elif not (0 <= (f_tmax - self._fstart_buffer) < len(self.buffer)):
self._buffer_around(f_tmax)
try:
tup = in_time.nonzero()
inds2 = inds - self._fstart_buffer
result[in_time] = self.buffer[inds - self._fstart_buffer]
return result
except IndexError as error:
print ("Error: wrong indices in video buffer. Maybe"+
" buffer too small.")
raise error
else:
ind = int(self.fps*t)
if ind<0 or ind> self.nframes: # out of time: return 0
return np.zeros(self.nchannels)
if not (0 <= (ind - self._fstart_buffer) <len(self.buffer)):
# out of the buffer: recenter the buffer
self._buffer_around(ind)
# read the frame in the buffer
return self.buffer[ind - self._fstart_buffer]
self.get_frame = gf
示例5: __init__
def __init__(self, clips):
Clip.__init__(self)
self.clips = clips
ends = [c.end for c in self.clips]
if not any([(e is None) for e in ends]):
self.duration = max(ends)
def gf(t):
sounds= [c.get_frame(t - c.start)
for c in clips if c.is_playing(t)]
if isinstance(t,np.ndarray):
zero = np.zeros((len(t),2))
else:
zero = np.zeros(2)
return zero + sum(sounds)
self.get_frame = gf
示例6: set_get_frame
def set_get_frame(self, gf):
newclip = Clip.set_get_frame(self, gf)
newclip.size = newclip.get_frame(0).shape[:2][::-1]
return newclip