本文整理汇总了Python中moviepy.Clip.Clip.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Clip.__init__方法的具体用法?Python Clip.__init__怎么用?Python Clip.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moviepy.Clip.Clip
的用法示例。
在下文中一共展示了Clip.__init__方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from moviepy.Clip import Clip [as 别名]
# 或者: from moviepy.Clip.Clip import __init__ [as 别名]
def __init__(self, array, fps):
Clip.__init__(self)
self.array = array
self.fps = fps
self.duration = 1.0 * len(array) / fps
def make_frame(t):
""" complicated, but must be able to handle the case where t
is a list of the form sin(t) """
if isinstance(t, np.ndarray):
array_inds = (self.fps*t).astype(int)
in_array = (array_inds>0) & (array_inds < len(self.array))
result = np.zeros((len(t),2))
result[in_array] = self.array[array_inds[in_array]]
return result
else:
i = int(self.fps * t)
if i < 0 or i >= len(self.array):
return 0*self.array[0]
else:
return self.array[i]
self.make_frame = make_frame
self.nchannels = len(list(self.get_frame(0)))
示例2: __init__
# 需要导入模块: from moviepy.Clip import Clip [as 别名]
# 或者: from moviepy.Clip.Clip import __init__ [as 别名]
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__
# 需要导入模块: from moviepy.Clip import Clip [as 别名]
# 或者: from moviepy.Clip.Clip import __init__ [as 别名]
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__
# 需要导入模块: from moviepy.Clip import Clip [as 别名]
# 或者: from moviepy.Clip.Clip import __init__ [as 别名]
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__
# 需要导入模块: from moviepy.Clip import Clip [as 别名]
# 或者: from moviepy.Clip.Clip import __init__ [as 别名]
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