shre
shre

Reputation: 1

How to pass commands to an application from python

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.

Upvotes: 0

Views: 218

Answers (2)

KSFT
KSFT

Reputation: 1774

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

Upvotes: 1

Padraic Cunningham
Padraic Cunningham

Reputation: 180502

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.

Upvotes: 2

Related Questions