我正在创建一个python脚本,将使用ffmpeg和unoconv转换文件。但是,当我运行该程序时,程序并没有得到转换后的文件,而是简单地显示文本:
sh: 1: unoconv -f: not found
下面是我的程序脚本:
path = raw_input("Please drag and drop the directory in which the file is stored into the terminal:")
os.chdir(path[1:-2])
filename = raw_input("Please enter the name of the file you would like to convert, including the file-type. e.g. test.txt, however please do make sure that the file-name does not have any spaces:")
Fileextension = raw_input("What filetype would you like the program to convert your file to. E.g. .mp3: ")
body, ext = os.path.splitext("filename")
os.system("'ffmpeg -i ' + filename + body + Fileextension ")
你知道为什么会这样吗?
看看你的命令:
os.system("'ffmpeg -i ' + filename + body + Fileextension ")
你尝试执行这个字符串。
试题:
os.system('ffmpeg -i ' + filename + body + Fileextension)
同时,建议使用subprocess代替os.system
您应该使用子流程模块,特别是子流程。Check_call传递参数列表:
from subprocess import check_call
check_call(["ffmpeg" ,"-i",filename + body + Fileextension])
任何非零退出码都会引发CalledProcessError