python脚本中ffmpeg和unoconv的奇怪错误

时间:2015-05-27 14:41:47

标签: python ffmpeg subprocess

我正在创建一个可供其他人用来转换文件的python脚本。但是当我使用这个脚本时,我在运行unoconv的子进程时遇到了一个奇怪的错误,这个错误是:

Traceback (most recent call last):
  File "conversion.py", line 15, in <module>
    check_call(["unoconv", "-f", Fileextension, filename])
  File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['unoconv', '-f', '.pdf', 'journal.doc']' returned non-zero exit status 1

我已经查看了各种资源,但我收到的一个答案是我必须错误地设置unoconv行。我已多次检查过代码是否正确,确实如此。另一个特殊的事情是我的ffmpeg代码有效。有没有人知道为什么会这样。

这是我的计划:

print "If at any point you wish to quit the program hit Ctrl + C"

filetype = raw_input("What kind of file would you like to convert? Audio, Image, Video or Document: ")

if filetype == "Document":
   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. .txt: ")
   from subprocess import check_call
   check_call(["unoconv", "-f", Fileextension, filename])

elif filetype == "Audio":
   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")
   from subprocess import check_call
   check_call(["ffmpeg" ,"-i", filename, body + Fileextension])

elif filetype == "Video":
   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. .mp4: ")
   body, ext = os.path.splitext("filename")
   from subprocess import check_call
   check_call(["ffmpeg" ,"-i", filename, body + Fileextension])

elif filetype == "Image":
   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. .Jpeg: ")
   body, ext = os.path.splitext("filename")
   from subprocess import check_call    
   check_call(["ffmpeg" ,"-i", filename, body + Fileextension])

1 个答案:

答案 0 :(得分:4)

documentation示例在没有.的情况下传递要转换为的类型的名称,使用.pdf会导致CalledProcessError,因为命令无效返回a非零退出状态:

unoconv -f pdf some-file.odt
unoconv -f pdf *.odt
unoconv -f doc *.odt
unoconv -f html *.odt