I am trying to create an mp4 by concatenating some videoclips using moviepy. However, depending on number of clips, I get the error: too many open files
. In the code below two lists are being used where jpegs contains all embedded pictures and their corresponding mp3 in mp3s list having more than 100 clips.
image_main = []
d = 0
for i in range(0,len(jpegs)):
audio = AudioFileClip(mp3s[i])
image = (ImageClip(jpegs[i])
.set_duration(audio.duration)
.set_audio(audio))
d = d + (image.duration / 60.0)
print(jpegs[i])
print('TOTAL DURATION: ', d)
image_main.append(image)
#del audio.reader
#del audio
As seen in the code snippet above, I tried to add deleting audio (lines commented out) just after being appended. However, this caused another issue in the code below as a result of which I could not create video file.
concat_clip = concatenate_videoclips(image_main, method="compose", transition=transition)
clip_resized = concat_clip.resize(width=1920)
clip_resized.write_videofile("REDDIT/stupid_TRIAL.mp4", fps=24, threads = 4)
Now I have solved the issue by just using a few videos instead of many.
How can I solve this?