moviepy 剪辑与 python 合并

moviepy clip merging with python

我正在尝试使用 moviepy 库将文件中的每个剪辑放入一个剪辑中

from moviepy.editor import VideoFileClip, concatenate_videoclips
import os
import cv2

clips = []
    for filename in os.listdir(r'clips//'):
        clips.append(filename)

print(clips)

finalVideo = concatenate_videoclips(f'clips//{clips}')
finalVideo.write_videofile('finalVideo.mp4')

但是,我得到这个错误:

File "C:/Users/myalt/OneDrive/Desktop/pythonProject2/main.py", line 11, in <module>
    finalVideo = concatenate_videoclips(f'clips//{clips}')
  File "C:\Users\myalt\OneDrive\Desktop\pythonProject2\venv\lib\site-packages\moviepy\video\compositing\concatenate.py", line 71, in concatenate_videoclips
    tt = np.cumsum([0] + [c.duration for c in clips])
  File "C:\Users\myalt\OneDrive\Desktop\pythonProject2\venv\lib\site-packages\moviepy\video\compositing\concatenate.py", line 71, in <listcomp>
    tt = np.cumsum([0] + [c.duration for c in clips])
AttributeError: 'str' object has no attribute 'duration'

怎么样:

clips = []
clipPaths = [] #If you want to store the paths as well
for filename in os.listdir(r'clips//'):
    #clips.append(filename)
    clip = VideoFileClip(filename)
    clips.append(clip)
    clipPaths.append(filename)

https://zulko.github.io/moviepy/examples/quick_recipes.html

https://zulko.github.io/moviepy/getting_started/compositing.html

(可能需要调整路径)