簡體   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