I am trying to convert the audio file in WebM format into MP3 file. I need to keep both files in memory due to server limitations. I tried to do it using PyAv, but I can't manage to receive Python file-like object after processing stream. My attempt:
with av.open(webm_file, 'r') as inp:
f = SpooledTemporaryFile(mode="w+b")
with av.open(f, 'w', format="mpeg") as out:
out_stream = out.add_stream("mp3")
for frame in inp.decode(audio=0):
frame.pts = None
for packets in out_stream.encode(frame):
out.mux(packets)
for packets in out_stream.encode(None):
out.mux(packets)
webm_file is of SpooledTemporaryFile type, but I can`t get outfile as file-like, can anyone help?