簡體   English   中英

當所有視頻文件路徑都寫在列表中時,如何在 moviepy 中連接視頻文件

[英]how to concatenate video files in moviepy when all video file paths are written in a list

我正在編寫一個代碼,該代碼從用戶那里獲取輸入以獲取用戶想要連接的視頻文件的路徑。 現在,如果用戶有 5 個視頻,他們想要連接起來並從中創建一個文件,我的程序可以很好地獲取所有視頻文件路徑並將它們存儲在列表中。 但問題是當它們在列表中時我無法使用 moviepy 將它們連接起來。 這是代碼

from moviepy.editor import VideoFileClip, concatenate_videoclips
listofpath=[]
no_vid = int(input('enter no of vid u wanna compile:  '))
for i in range(no_vid):
    vidpath = input('enter path to the files u wanna compile:  ')
    listofpath.append(vidpath)
print(listofpath)

final_clip = concatenate_videoclips([listofpath])
final_clip.write_videofile("E:\python_work\downloaded\my_concatenation.mp4")
from moviepy.editor import VideoFileClip, concatenate_videoclips

listofpath=[]
no_vid = int(input('enter no of vid u wanna compile:  '))
for i in range(no_vid):
    vidpath = input('enter path to the files u wanna compile:  ')
    listofpath.append(vidpath)
print(listofpath)

創建 VideoFileClip 對象的列表

clips = [VideoFileClip(file) for file in listofpath]

連接剪輯

final_clip = concatenate_videoclips(clips)

然后寫視頻

final_clip.write_videofile("E:\python_work\downloaded\my_concatenation.mp4")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM