0

I am trying to run ffmpeg application from python.I am using the following code to execute the application

import subprocess
subprocess.call(['C:/ffmpeg/bin/ffmpeg.exe'])

by this command the application is getting executed. could somebody tell me how can i pass commands to the application, i tried

subprocess.call(['C:/ffmpeg/bin/ffmpeg.exe','ffmpeg -i 2.mp4 -vn -ab 128 outputaudio.mp3'])

but its not working.

shre
  • 1
  • 2
  • you don't want to pass commands to your application but arguments. Possible duplicate http://stackoverflow.com/questions/11801098/calling-app-from-subprocess-call-with-arguments – Julien Spronck Apr 03 '15 at 15:03

2 Answers2

2

They need to be individual args:

subprocess.check_call(['C:/ffmpeg/bin/ffmpeg.exe','ffmpeg','-i',"2.mp4","-vn", "-ab", "128", "outputaudio.mp3"])

Also use check_call instead of call, check_call will raise a CalledProcessError if the command returns a non-zero exit status. I am not sure the 'ffmpeg' should be there.

Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
  • sir, you are right, when i used "check_call" method, I am getting "CalledProcessError " even for running ffmpeg.exe file .could you please tell me how i can run the application and pass argumrnts. – shre Apr 04 '15 at 05:47
  • does `C:/ffmpeg/bin/ffmpeg.exe` exist? – Padraic Cunningham Apr 04 '15 at 09:39
1

The arguments should each be separate elements in the list. The doc page has an example of how to call it. Yours should be something like this:

['C:/ffmpeg/bin/ffmpeg.exe','ffmpeg','-i 2.mp4','-vn','-ab','128','outputaudio.mp3']
KSFT
  • 1,774
  • 11
  • 17