0
import glob
import os
from natsort import natsorted
from moviepy.editor import *

base_dir = os.path.realpath("./images/")
print(base_dir)

gif_name = 'pic'
fps = 24

file_list = glob.glob('./images/*.jpg')  # Get all the pngs in the current directory
file_list_sorted = natsorted(file_list,reverse=False)  # Sort the images

clips = [ImageClip(m).set_duration(5)
         for m in file_list_sorted]
print (clips)



text_list = ["Piggy", "Kermit", "Gonzo", "Fozzie"]
clip_list = []

for text in text_list:
    try:
        txt_clip = ( TextClip(text, fontsize = 70, color = 'white').set_duration(2))
        clip_list.append(txt_clip)
    except UnicodeEncodeError:
        txt_clip = TextClip("Issue with text", fontsize = 70, color = 'white').set_duration(2)
        clip_list.append(txt_clip)
print(clip_list)


final_clip = CompositeVideoClip([clips, clip_list])
final_clip.write_videofile("./video/export.mp4", fps = 24, codec = 'mpeg4')

But getting ERROR like size = clips[0].size AttributeError: 'list' object has no attribute 'size' i need to display image for first 15sec and after 15 sec text should be display 10 sec.

1 Answers1

1

Hi thanks for posting the question. Hopefully this would be helpful.

Your main mistake concerns the following line:

final_clip = CompositeVideoClip([clips, clip_list])

CompositeVideoClip.__init__ expects a list of type Clip (CompositeVideoClip inherits the Clip class). However, in your previous lines:

print(clips)
...
print(clip_list)

so what you have effectively fed to the CompositeVideoClip.__init__ method is a nested list. So instead, you should do something like the following:

final_clip = CompositeVideoClip(clips + clip_list)

I'm sure you can come up with a more elegant solution, this is a working solution for you to start with. Do write further in case my proposal does not work.

amirothman
  • 157
  • 1
  • 11