![](/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.