我目前正在编写我的第一个python脚本,以将大型音频文件拆分为较小的文件。 (将专辑分为单独的曲目):
import subprocess
def genList():
with open("commands.txt") as file:
ffmpeg_template_str = 'ffmpeg -i audio.FLAC -acodec copy -ss START_TIME -to END_TIME LITTLE_FILE'
lines = file.readlines()
results = []
for line in lines:
argument_list = line.split(' ')
result = ffmpeg_template_str
results.append(result.replace('START_TIME', argument_list[0]).replace('END_TIME', argument_list[1]).replace('LITTLE_FILE', argument_list[2]))
return results;
def split():
commands = genList()
for command in commands:
subprocess.call(command.split(' '))
split()
当我执行脚本时,将弹出许多命令行窗口,但只有最后一个可以提供所需的结果。
因此,如果我想将音频文件拆分为较小的文件,则只能正确执行最后的拆分操作。
另外,如果我不使用for循环而只是将subprocess.call多次粘贴到代码中,则效果很好。
subprocess.call(command1)
subprocess.call(command2)
subprocess.call(command3)
任何帮助将不胜感激。