3

I am using the simplest possible code to download bunch of youtube videos:

from pytube import YouTube

link=[
  "https://www.youtube.com/watch?v=Rb9CjDjqNC4", 
  "https://www.youtube.com/watch?v=pmmKCDvsFy8",
  "https://www.youtube.com/watch?v=erN1_QVCCM8",
  "https://www.youtube.com/watch?v=fjzM3NbgGzE", 
  "https://www.youtube.com/watch?v=JWBiY29GqRs",
  "https://www.youtube.com/watch?v=vp7zMFrHkmA"
]

for i in link: 
  s = YouTube(i)
  print(i)
  s.streams.filter(res="720p",mime_type="video/mp4").first().download() 

But "strangely" videos don't have the sound. When I remove filter sound is there, why? I've looked online, but couldn't find any example that shows how to do it, maybe you can help?

Thanks, Dejan

Dejan Dozet
  • 948
  • 10
  • 26
  • 2
    Did you read explanations about adaptive streaming in pytube documentation? Might be that, for some videos, you have to download images & audio separately, then post process them with ffmpeg. https://pypi.org/project/pytube/ – David Brabant Nov 09 '19 at 13:51
  • Thanks @David, so basically I was (un)lucky that the first stream is actually progressive one and thus contained bot video and audio together, others are adaptive so I have to workout more to get it all together – Dejan Dozet Nov 09 '19 at 14:57

1 Answers1

1

You're downloading an adaptive (DASH) stream which have audio and video split into two files. You can filter these out by adding the argument progressive=True to your filter method

Isabel
  • 29
  • 1