Problem of using FFMPEGIO to write an mp3 file to BytesIO

30 Views Asked by At

I wanna download an only-audio video from YouTube and then convert it into mp3 format using ffmpegio and I wanna save everything into buffers so I met the issue.

What should happen: save ffmpeg output to byio (BytesIO) What happens: console error

from pytube import YouTube
from io import BytesIO
import ffmpegio

yt = YouTube("link")
byio = BytesIO()
stream = yt.streams.get_audio_only()
stream.stream_to_buffer(byio)
ffmpegio.transcode(byio.getbuffer(), byio, overwrite=True) # i dont know how to make it write as byio mp3 or something
byio.seek(1)

CONSOLE OUTPUT:

"stdout": stdout,
UnboundLocalError: local variable 'stdout' referenced before assignment
0

There are 0 best solutions below