![](/img/trans.png)
[英]Error with the output when using moviepy module to concatenate video files
[英]Can't write video using moviepy. output format error
我正在嘗試連接每個文件夾中的視頻,以便在每個文件夾中獲得一個視頻,而不是多個短視頻。 如果重要的話,這是一個外部 USB 驅動器。
我的代碼似乎按預期遍歷文件,但在寫入音頻后,在“寫入視頻”操作期間,我一直收到此錯誤,我相信: b"[NULL @ 000002a8340ae640] Unable to find a suitable output format for 'D:\\taxes\\folder\\test'\r\nD:\\taxes\\folder\\test: Invalid argument\r\n"
我還沒有找到強制輸出格式的方法。 有什么想法嗎?
import os
from moviepy.editor import *
startingDir = r'D:\taxes'
avoid = ['0incomplete', 'old', 'that', 'this']
for thing in os.listdir(startingDir):
clips = []
name = ''
if thing in avoid:
print(' avoided {}'.format(thing))
continue
folder = os.path.join(startingDir, thing)
if os.path.isdir(folder):
for clip in os.listdir(folder):
print (clip)
clips.append(VideoFileClip(os.path.join(folder, clip)))
print('\n')
try:
final = concatenate_videoclips(clips)
final.write_videofile(os.path.join(folder, 'test'), audio=True, codec='libx264', threads=10)
final.close()
except Exception as e:
print (e)
print('\n Continuing... \n\n')
continue
“無法找到合適的輸出格式”錯誤消息意味着 FFmpeg 無法確定輸出視頻文件的格式。
如果參數未明確定義格式,FFmpeg 將使用文件擴展名來確定文件格式。
您使用的文件名是test
沒有擴展名,因此 FFmpeg 無法確定格式。
將: final.write_videofile(os.path.join(folder, 'test'), audio=True, codec='libx264', threads=10)
替換為:
final.write_videofile(os.path.join(folder, 'test.mp4'), audio=True, codec='libx264', threads=10)
.mp4
定義 MP4 文件格式。
我們也可以為 MKV 文件格式選擇'test.mkv'
(或為 AVI 格式選擇“test.avi 'test.avi'
)...
MoviePy 在幕后使用 FFmpeg。
如果我們真的想創建一個名為test
的沒有擴展名的視頻文件,我們可以添加ffmpeg_params=['-f', 'mp4']
參數:
final.write_videofile(os.path.join(folder, 'test'), audio=True, codec='libx264', threads=10, ffmpeg_params=['-f', 'mp4'])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.