【发布时间】:2021-06-28 09:45:23
【问题描述】:
我有一个简短的脚本,需要每晚将多个 MKV 文件合并为一个。
import os, glob
import subprocess
concatenated_files = ""
os.chdir("/cams/")
for index, file in enumerate(glob.glob("*.mkv")):
if index == 0:
concatenated_files = file
else:
concatenated_files += " + " + file
# print(concatenated_files)
returncode = subprocess.call("mkvmerge -o out.mkv " + concatenated_files)
只有几个文件出现以下错误
OSError: [Errno 63] File name too long: 'mkvmerge -o out.mkv video21-06-28_09-12-08-51.mkv + video21-06-28_07-55-36-80.mkv + video21-06-28_09-52-05-79.mkv + video21-06-28_08-47-56-69.mkv + video21-06-28_09-15-04-34.mkv + video21-06-28_09-32-43-25.mkv
我计划合并数百个,所以不确定如何使用 Python 对这种情况进行排序。它在 shell 中运行良好。
【问题讨论】:
-
concatenated_files += " + " + file->concatenated_files += " " + file? -
我需要在文件@TuanChau之间添加一个+号
-
@voronoy:
subprocess.call("mkvmerge -o out.mkv " + concatenated_files, shell=True)工作吗? -
在终端中运行
mkvmerge -o out.mkv video21-06-28_09-12-08-51.mkv + video21-06-28_07-55-36-80.mkv + video21-06-28_09-52-05-79.mkv + video21-06-28_08-47-56-69.mkv + video21-06-28_09-15-04-34.mkv + video21-06-28_09-32-43-25.mkv会发生什么?运行成功了吗? -
@MauriceMeyer 确实如此!非常感谢。
标签: python