I'm fairly new to python. I'm trying to automatically create an mp4 using moviepy saved under the next increment number and correct folder each time the code is run. All files saved will be named "Clip(number).mp4", but every even number is saved in the 'even' folder and every odd number is saved in the 'odd' folder. I already manually saved a bunch of output, so the odd folder is at Clip(21) and even is at Clip(20) right now before implementing this, so I need a way to check if the clip had already been made and not delete the clips already made. If a clip in the folder, for example Clip(6), was deleted, then ignore the gap and just create the next clip, which would be Clip(22). The way I output it currently is manually renaming it every time I run it and dragging it, but I'm finding it to be extremely inefficient as I need to run this program a ton of times.
from moviepy.editor import *
import moviepy.editor as mp
import math
from PIL import Image
import numpy
import os
size = (1920, 1080)
imgarr = []
image_dir = "Z:/Programming Stuff/Images/Testing"
for filename in os.listdir(image_dir):
if filename.endswith(".jpg") or filename.endswith(".png"):
imgarr.append(os.path.join(image_dir, filename))
slides = []
for n, url in enumerate(imgarr):
slides.append(
mp.ImageClip(url).set_fps(25).set_duration(5).resize(size)
)
video = mp.concatenate_videoclips(slides)
video.write_videofile('Clip(22).mp4')