0

I'm trying to get a stream from Youtube and stream it via HTTP, but I have to use separate audio and video streams to get good quality. I don't know how to merge the streams on the fly with ffmpeg. (I'm using pytube)

I know I can do this by saving the streams, then merging them, and then streaming the output, but I would like to do it on the fly. This is my current code (which uses the old progressive streams):

yt = YouTube(f"https://www.youtube.com/watch?v={url}")
video = yt.streams.filter(file_extension='mp4', progressive=True).first()
async def stream(response):
    for chunk in pytube_request.stream(video.url):
        await response.write(chunk)
return ResponseStream(stream, content_type="audio/mp4")
STerliakov
  • 4,983
  • 3
  • 15
  • 37
Kiko
  • 13
  • 1
  • I know this is a duplicate of [this question](https://stackoverflow.com/questions/65837048/is-it-possible-to-combine-audio-and-video-from-ffmpeg-python-without-writing-to) but it hasn't been answered so i felt the need to ask it again. – Kiko Dec 18 '22 at 22:23

0 Answers0