1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| import threading import time
max_threads = 5
semaphore = threading.Semaphore(max_threads) def asyncConcat(startPath, endPath, middlePath, middleAudioPath, outputPath, semaphore): with semaphore: thread_id = threading.current_thread().ident print("Thread ID: ", threading.current_thread().ident) concat(startPath, endPath, middlePath, middleAudioPath, outputPath)
if __name__ == '__main__': threads = [] for file in files: count = count + 1 basename = os.path.basename(file) if '.mp4' not in basename: continue if '已剪辑' in basename: continue if os.path.exists(outputPath + basename.replace('.', '-已剪辑.')): print('视频已剪辑=', middleDir + basename) continue print('待剪辑视频=', middleDir + basename) fileCount = fileCount + 1 thread = threading.Thread(target=asyncConcat, args=( startPath, endPath, middleDir + basename, middleAudioPath, outputPath, semaphore)) threads.append(thread) thread.start() for thread in threads: thread.join(timeout=1)
|