What is the correct form of arguments to Python subprocess()

58 Views Asked by At

I need to convert an existing short wav file to mp3 (wma would also be acceptable).

I have installed ffmpeg in the C: directory as recommended, and it works when used directly from a Windows command line, but not in Python 2.7

At first I used os.system() but although the code doesn't create an error, it does not create the mp3 file either

Using the preferred subprocess.call() gives an error message.

This one of several attempts to make it work:

import os,sys
import subprocess

# .wav file exists and contains 1 minute of audio
os.system('ffmpeg -i G:/Channel1_08.wav G:/Channel1_08.mp3')
# line above executes but does not create an mp3 file
# the same command works in a Windows command line
# ffmpeg is in the C: directory

## subprocess is supposed to be better than os.system, I tried
s = subprocess.call("ffmpeg -i G:/Channel1_08.wav G:/Channel1_08.mp3",shell = True)
# line above returns s=1, but no mp3 file

Edit: more info, I'm using a Win8.1 PC, the files are on a USB stick. with other variations of the argument string, I often get "file not found" errors, but the file is definitely in place. It occurs to me that I have not re-booted the PC since changing the PATH variable. I cannot do this until a major search script has finished running in about 24 hours time. I'll keep you posted.

14 Sep 17: Rebooting fixed the problem. For the record the original wav file was 2113KB, the wma is 1101KB and the mp3 is 199KB.

0

There are 0 best solutions below