Consider 20 video file in the raw video folder. Initially take only 5 video for fast forwarding by assigning them to 5 individual threads. The process should wait until the 5 threads are completing their task and after completion, the fast forwarded videos must be saved in converted folder and the raw videos must move to the new folder. But in each loop it has to process only 5 threads wait and process the next set of threads. Here is the code:
from moviepy.editor import *
import os
import glob
from natsort import natsorted
from threading import Thread
import datetime
def fast(path,thread_name):
if os.path.splitext(path)[1] == '.mp4':
print("Start : " + str(thread_name) + " - " + str(datetime.datetime.now()))
clip = (VideoFileClip(path).fx(vfx.speedx, 5))
clip.to_videofile('A:/Internship/Assignment-1/output_folders/multithread_fast_output/'+thread_name + '.mp4', codec='libx264')
print("End : " + str(thread_name) + " - " + str(datetime.datetime.now()))
for i, filename in enumerate(glob.glob("A:/Internship/Assignment-1/videos/*.mp4"), 1):
thread_name = f"t{i}"
Thread(target=fast, args=(filename, thread_name)).start()