Search code examples
pythonpytube

I am trying to download video using pytube however for some reason no sound is downloaded


When running the following program a video is downloaded however it appears there is no sound. Can someone help me to fix it?

from pytube import YouTube

path = '/home/15g2leve'
url = "https://www.youtube.com/watch?v=GyQjVtIGQg8"
resol = "1080p"
file_type = "mp4"


video = YouTube(url)

Streams = video.streams

vid = Streams.filter(res = resol, file_extension = file_type).first()

vid.download(path)

Solution

  • "You may notice that some streams listed have both a video codec and audio codec, while others have just video or just audio, this is a result of YouTube supporting a streaming technique called Dynamic Adaptive Streaming over HTTP (DASH)." refs

    So, you can use streams.filter(progressive=True).all() to get videos which contains both video & audio (vcodec, acodec info) or you download video and audio. After that, use a tool such as FFmpeg to merge audio into video.