Brandon
Brandon

Reputation: 1

Moviepy V2 How do you position a TextClip and apply an effect?

I am trying to refactor my code to use the new Moviepy Version 2.0 and I'm having trouble with .with_position / SlideIn / SlideOut effect.

When I apply the SlideIn effect it seems to override any position I have applied. It there a way to explicitly set the position of a TextClip and apply a SlideIn and SlideOut effect without using nested CompositeVideoClip?

In the below example the with_position((0,0)) would not be implemented and the position of the TextClip would revert to the default centred position. If I remove the lines .with_effect... then the TextClip would be positioned as expected in the 0,0 location.

Any help would be much appreciated.

from moviepy import *

clips = []
clip = ImageClip("path1.png", duration=3).with_start(0)
clips.append(clip)
title = TextClip("path3.ttf", text="Text...", font_size=80, color="#fff", text_align="center", duration=1,)
title = title.with_start(1).with_position((0,0))
title = title.with_effects([vfx.SlideIn(0.25, "left")])
title = title.with_effects([vfx.SlideOut(0.25, "left")])
clips.append(title)

final_clip = CompositeVideoClip(clips)
final_clip.write_videofile("final_clip.mp4")

*EDIT To get the expected behaviour I need to use multiple nested CompositeVideoClips but this significantly slows it down. Is there anyway that I can make this code more efficient?

from moviepy import *

clips = []
clip = ImageClip("path1.png", duration=3).with_start(0)
clips.append(clip)
title = TextClip("path3.ttf", text="Text...", font_size=80, color="#fff", text_align="center", duration=1,)
title = CompositeVideoClip(title.with_effects([vfx.SlideIn(0.25, "left")]))
title = CompositeVideoClip(title.with_effects([vfx.SlideOut(0.25, "left")]))
title = title.with_start(1).with_position((0,0))
clips.append(title)

final_clip = CompositeVideoClip(clips)
final_clip.write_videofile("final_clip.mp4")

Upvotes: 0

Views: 133

Answers (0)

Related Questions