【问题标题】:Strange error with ffmpeg and unoconv in python scriptpython脚本中ffmpeg和unoconv的奇怪错误
【发布时间】:2015-08-09 17:38:31
【问题描述】:

我正在创建一个可供其他人用来转换文件的 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])

【问题讨论】:

  • 没有什么奇怪的unoconv 进程以非零退出状态 1 终止。它可能失败了。尝试使用相同的参数手动调用它以了解原因。
  • 从 shell 执行这个:unoconv -f .pdf journal.doc。最好来自与您的 python 脚本运行相同的目录和相同的 UID。它可能会给你一个更详细的结果。

标签: python ffmpeg subprocess


【解决方案1】:

documentation 示例传递您要转换为的类型的名称,而没有 .,使用 .pdf 将导致 CalledProcessError,因为该命令无效,返回非零退出状态:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2013-03-15
    • 1970-01-01
    相关资源
    最近更新 更多