简体   繁体   English

如何在 python 中使用 moviePy 通过多线程动态快进视频文件夹?

[英]How to fast forward folder of videos through multiple threads dynamically using moviePy in python?

I have a folder of videos which I want to fast forward using multiple threads using moviePy.我有一个视频文件夹,我想使用 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 *从 moviepy.editor 导入 *

    import os导入操作系统

    from natsort import natsorted从 natsort 导入 natsorted

    from threading import Thread从线程导入线程

    def fast(path,thread_name): def fast(路径,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() 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() 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() 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() t4 =Thread(target=fast, args=("G:/Ocsid Technologies/Video_1/sample4.mp4",'t4')).start()

You can enumerate files with glob.glob() and use enumerate to get a counter for your thread names.您可以使用glob.glob()枚举文件并使用enumerate获取线程名称的计数器。

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM