-1

I have a folder of videos which I want to fast forward using multiple threads using moviePy. How do I Fetch the videos from the folder dynamically instead of giving their paths statically? Here is my code :

  1. from moviepy.editor import *

    import os

    from natsort import natsorted

    from threading import Thread

    def fast(path,thread_name):

    if os.path.splitext(path)[1] == '.mp4':
    
        #print(os.path.splitext(path))
    
        clip = (VideoFileClip(path).fx(vfx.speedx, 5))
    
        #print(clip)
    
        clip.to_videofile('G:/Ocsid Technologies/Video_1/'+thread_name + '.mp4', codec='libx264')
    

    t1 = Thread(target=fast, args=("G:/Ocsid Technologies/Video_1/sample1.mp4", 't1')).start()

t2 =Thread(target=fast, args=("G:/Ocsid Technologies/Video_1/sample2.mp4", 't2')).start()

t3 =Thread(target=fast, args=("G:/Ocsid Technologies/Video_1/sample3.mp4",'t3' )).start()

t4 =Thread(target=fast, args=("G:/Ocsid Technologies/Video_1/sample4.mp4",'t4' )).start()

1 Answers1

0

You can enumerate files with glob.glob() and use enumerate to get a counter for your thread names.

import glob
# ...
for i, filename in enumerate(glob.glob("G:/Ocsid Technologies/Video_1/*.mp4"), 1):
    thread_name = f"t{i}"
    Thread(target=fast, args=(filename, thread_name)).start()
AKX
  • 152,115
  • 15
  • 115
  • 172