0

I need to add text effect with a background image using Moviepy but for some reason its not working. I am using moviepy and have a jpg background image file. It is resulting in black background video. here is the code

import numpy as np

from moviepy.editor import *
from moviepy.video.tools.segmenting import findObjects

# WE CREATE THE TEXT THAT IS GOING TO MOVE, WE CENTER IT.

screensize = (720,460)
txtClip = TextClip('Cool effect',color='white', font="Amiri-Bold",
                   kerning = 5, fontsize=100)
image_clip =  ImageClip("newback.jpg", duration=5)
cvc = CompositeVideoClip( [image_clip,txtClip.set_pos('center')],
                        size=screensize)


# helper function
rotMatrix = lambda a: np.array( [[np.cos(a),np.sin(a)], 
                                 [-np.sin(a),np.cos(a)]] )

def arrive(screenpos,i,nletters):
    v = np.array([-1,0])
    d = lambda t : max(0, 3-3*t)
    return lambda t: screenpos-400*v*d(t-0.2*i)



# WE USE THE PLUGIN findObjects TO LOCATE AND SEPARATE EACH LETTER

letters = findObjects(cvc) # a list of ImageClips


# WE ANIMATE THE LETTERS

def moveLetters(letters, funcpos):
    return [ letter.set_pos(funcpos(letter.screenpos,i,len(letters)))
              for i,letter in enumerate(letters)]

clips = [ CompositeVideoClip( moveLetters(letters,funcpos),
                              size = screensize).subclip(0,5)
          for funcpos in [arrive] ]

# WE CONCATENATE EVERYTHING AND WRITE TO A FILE

final_clip = concatenate_videoclips(clips)
final_clip.write_videofile('coolTextEffects.avi',fps=25,codec='mpeg4')

1 Answers1

0

You can try this:

import numpy as np

from moviepy.editor import *
from moviepy.video.tools.segmenting import findObjects

# WE CREATE THE TEXT THAT IS GOING TO MOVE, WE CENTER IT.

screensize = (720,460)
txtClip = TextClip('Cool effect',color='white', font="Amiri-Bold",
                   kerning = 5, fontsize=100)
#image_clip = ImageClip("newback.jpg", duration=5)
#cvc = CompositeVideoClip( [image_clip,txtClip.set_pos('center')],
#                        size=screensize)


# helper function
rotMatrix = lambda a: np.array( [[np.cos(a),np.sin(a)], 
                                 [-np.sin(a),np.cos(a)]] )

def arrive(screenpos,i,nletters):
    v = np.array([-1,0])
    d = lambda t : max(0, 3-3*t)
    return lambda t: screenpos-400*v*d(t-0.2*i)



# WE USE THE PLUGIN findObjects TO LOCATE AND SEPARATE EACH LETTER

#letters = findObjects(cvc) # a list of ImageClips
letters = findObjects(txtClip)

# WE ANIMATE THE LETTERS

def moveLetters(letters, funcpos):
    return [ letter.set_pos(funcpos(letter.screenpos,i,len(letters)))
              for i,letter in enumerate(letters)]

clips = [ CompositeVideoClip( moveLetters(letters,funcpos),
                              size = screensize).subclip(0,5)
          for funcpos in [arrive] ]

# WE CONCATENATE EVERYTHING AND WRITE TO A FILE

final_clip = concatenate_videoclips(clips)
image_clip =  ImageClip("image.jpg", duration=final_clip.duration)
final_clip = CompositeVideoClip([image_clip,final_clip.set_pos('center')])
final_clip.write_videofile('coolTextEffects.avi',fps=25,codec='mpeg4')
  • Please use the right and appropriate tag for any question, whether it belongs to html, css, java or any other! You can use multiple tag as well! – name_doesnt_matters May 11 '21 at 09:38