繁体   English   中英

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

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

我有一个视频文件夹,我想使用 moviePy 使用多个线程快进。 如何动态地从文件夹中获取视频而不是静态地提供它们的路径? 这是我的代码:

  1. 从 moviepy.editor 导入 *

    导入操作系统

    从 natsort 导入 natsorted

    从线程导入线程

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

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

您可以使用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