I tried 3 methods to call ffmpeg from python, but it always blocks and doesn't return any result.
However, if I execute it from shell, it works.
For eg:
/usr/bin/ffmpeg -y -i /tmp/uploadedfiles/movie8_15_10s.mpg -ar 1600 -ac 1 /tmp/uploadedfiles/movie8_15_10s.mpg.wav
this works.
However,
ffmpeg_command = "/usr/bin/ffmpeg -y -i test.wav testout.wav"
f_ffmpeg=os.popen(ffmpeg_command);
This makes the python hang.
You should use subprocess.Popen
instead of os.popen
.
In particular, to get same behaviour, you can run the process through a shell with shell=True
and gather the output from stdout
and stderr
as follows:
p = subprocess.Popen(command, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.communicate()[0]
where command
is the same command line you would write in a shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With