I'm trying to use ffmpeg with Python's subprocess module to convert some audio files. I grab the audio files from a URL and would like to just be able to pass the Python File Objects to ffmpeg, instead of first saving them to disk. It would also be very nice if I could just get back a file stream instead of having ffmpeg save the output to a file.
For reference, this is what I'm doing now:
tmp = "/dev/shm"
audio_wav_file = requests.get(audio_url)
## ## ##
## This is what I don't want to have to do ##
wavfile = open(tmp+filename, 'wrb')
wavfile.write(audio_wav_file.content)
wavfile.close()
## ## ##
conversion = subprocess.Popen('ffmpeg -i "'+tmp+filename+'" -y "'+tmp+filename_noext+'.flac" 2>&1', shell = True, stdout = subprocess.PIPE).stdout.read()
Does anyone know how to do this?
Thanks!