Avery Ripoll Crocker
Avery Ripoll Crocker

Reputation: 79

Strange error with ffmpeg and unoconv in python script

I am creating a python script that can be used by other people to convert files. However when I use this script I keep getting a weird error when I run the subprocess for unoconv, this error is:

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

I have looked through various resources for this, but the one answer I have been receiving is that I must have set up the unoconv line incorrectly. I have checked several times that the code is correct, and it is. The other peculiar thing is that my code for ffmpeg works. Does anybody have an idea as to why this happens.

Here is my program:

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])

Upvotes: 1

Views: 464

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180502

The documentation examples pass the name of the type you want to convert to without the ., using .pdf would cause a CalledProcessError as the command is invalid returning a non-zero exit status:

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

Upvotes: 4

Related Questions