I am trying to convert a test.mp4 file to test.wav from python code using avconv. I am able to convert the test.mp4 to test.wmv using cmd line but when i run the same command from python its giving me following error :
line 103, in get_message_audio subprocess.call(cmdline) FileNotFoundError: [WinError 2] The system cannot find the file specified
The code i am using from python file is :
cmdline = ['avconv', '-i', 'test.mp4', '-vn', '-f', 'wav', 'test.wav']
subprocess.call(cmdline)
But when i run the same command from cmd it successfully runs and save the test.wav file.
cmd line = avconv -i test.mp4 -f wav test.wav
Note: I have added avconv to system variable. The python file and test.mp4 is in the same directory. I am running the cmd from the same directory as well.
My guess is that it is not finding the avconv
executable. I would suggest that you use the full absolute path to avconv
in your command in Python. Another thing you can try is using a shell, by adding shell=True
to your subprocess.call()
call.
In other words, do this and see if it helps:
cmdline = [r'\full\path\to\avconv', '-i', 'test.mp4', '-vn', '-f', 'wav', 'test.wav']
subprocess.call(cmdline, shell=True)
I don't think it's the input file it can't find. It doesn't seem to be getting that far. At the point that subprocess.call(cmdline)
is failing, test.mp4
and test.wav
are just strings being passed to avconv
.
My guess is that avconv
isn't in the PATH of the environment in which Python is running the command. shell=True
might help that.