2

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?

1
  • I don't know why, but it seems like python can't find ffmpeg in your $PATH. It should work if you use the full path to the ffmpeg executable in your command. Commented Jan 28, 2018 at 11:17

2 Answers 2

6

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!

Sign up to request clarification or add additional context in comments.

1 Comment

yes! you save my life, bro! i thought it was the working dir's problem, but in fact it's the problem of a binary's path!
0

You're getting that error because you have to use the full path to the ffmpeg command with os.system().

Instead of os.system() look at subprocess.call(). This may help.

6 Comments

I used the subprocess.call as follows: subprocess.call('ffmpeg -i /Users/krish/audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 /Users/krish/converted_audio.wav',shell=True) . Now I get a return code of 127
You need to read the documentation of subprocess.call. the link I provided should help. You have to separate the command and the arguments.
Thank You. I tried it out separately too. But didn't work. Would be great if you could tell me the exact usage! However, I was able to make it work when i used the full path of ffmpeg in os.system(). In order to retrieve the full path of ffmpeg, I used "which ffmpeg" in the terminal.
"you have to use the full path to the ffmpeg command" That is simply not true. Both os.system and subprocess work with just the name of the command.
Rawing - you're correct. After further research, 32512 is apparently an error when there are too many characters in the given command. Was listed as a (closed) bug in 2013 as per: bugs.python.org/issue19015 however other research shows that often 32512 throws with 512 which is a 'command not found' error which means the full path is required in that instance. Otherwise, I assume you're correct.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.