Search code examples
pythonsubprocessos.system

os.system() returns error code 32512 - Python


I am using the following system command in Python 2.7. I am able to execute the same command in terminal successfully whereas I am not able to run it in python(getting return code = 32512). The command basically converts a mp3 file into a wave file along with stereo to mono conversion. I am able to run the same command in terminal successfully.

Below is the command I'm trying out:

os.system("ffmpeg -i /Users/krish/audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 /Users/krish/converted_audio.wav")

I also tried using the subprocess command but it gave the same 32512 return code.

Could anyone help me out on what's wrong with this?


Solution

  • A more specific answer to this.

    Instead of using the command like this in python:

    os.system("ffmpeg -i /Users/krish/audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 /Users/krish/converted_audio.wav")
    

    First try to find out where is your ffmpeg installation by giving the following command in terminal (Works on linux and mac)

    which ffmpeg

    In my case this was the output of the above command:

    /usr/local/bin/ffmpeg

    Now, modify the os.system command in python as follows:

    os.system("/usr/local/bin/ffmpeg -i /Users/krish/audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 /Users/krish/converted_audio.wav")
    

    which should work great without throwing 32512 error!