You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi All,
I am trying to create a custom class for VideoClip to generate some animation and txt effects. I notice that once I create a subclip on my custom class, the masking fail.
To be exact:
importgizehfrommoviepy.editorimport*frommoviepy.configimportchange_settingsfromPILimportImage, ImageDraw, ImageFontimportnumpyasnp# Use local ffmpegchange_settings({"FFMPEG_BINARY":"ffmpeg"})
start_time='00:10'end_time='00:12'duration=10ncircles=20W,H=1280, 720# Demo videodefmake_frame(t):
surface=gizeh.Surface(W,H)
foriinrange(ncircles):
angle=2*np.pi*(1.0*i/ncircles+t/duration)
center=W*( 0.5+gizeh.polar2cart(0.1,angle))
circle=gizeh.circle(r=W*(1.0-1.0*i/ncircles),
xy=center, fill= (i%2,i%2,i%2))
circle.draw(surface)
returnsurface.get_npimage()
classCustomClip(VideoClip):
def__init__(self, size, font_path='font/TangYuan.ttf'):
self.size=sizeself.font=ImageFont.truetype(font_path, 40)
# Call the parent constructor. Duration must be set or alpha does not workVideoClip.__init__(self, duration=10)
defmake_frame(self, t):
img=Image.new('RGBA', self.size)
draw=ImageDraw.Draw(img)
txt=f"Current sec: {t}"draw.text(
(10,120),
txt,
fill='blue',
font=self.font,
stroke_width=4,
stroke_fill='white',
align='center',
)
np_img=np.array(img)
self.mask=ImageClip(1.0*np_img[:, :, 3] /255, ismask=True)
returnnp_img[:, :, :3]
clip=VideoClip(make_frame, duration=duration).subclip(start_time, end_time)
# subclip does not work# custom_clip = CustomClip(size=video.size)custom_clip=CustomClip(size=clip.size).subclip(start_time, end_time)
result=CompositeVideoClip([clip, custom_clip])
result.write_videofile("assets/test.mp4", fps=30, codec='h264_nvenc', bitrate="5M")
Expected Behavior
Actual Behavior
Steps to Reproduce the Problem
Specifications
Python Version: 3.10
MoviePy Version: 1.0.3
Platform Name: Ubuntu
Platform Version: 20.02
The text was updated successfully, but these errors were encountered:
Hi All,
I am trying to create a custom class for VideoClip to generate some animation and txt effects. I notice that once I create a subclip on my custom class, the masking fail.
To be exact:
Expected Behavior
Actual Behavior
Steps to Reproduce the Problem
Specifications
The text was updated successfully, but these errors were encountered: