I am trying to write a code to download YouTube videos using Pytube on Python 3.6. But for most videos progressive download(Audio and Video in same file) format is available only upto 360p. So I want to download audio and video files separately and combine it. I am able to to download the audio and video files. How can I combine the two file together?
Basically I don't find any method to marge Audio and Video in Pytube
but you can use ffmpeg
for muxing.
First of all you have to install ffmpeg
ffmpeg
installation guide for Windows
for
Ubuntu
justsudo apt install ffmpeg
Add a dependency ffmpeg-python
a python wrapper of ffmpeg
pip install ffmpeg-python
Now we are ready to go with this code snippet
import ffmpeg
video_stream = ffmpeg.input('Of Monsters and Men - Wild Roses.mp4')
audio_stream = ffmpeg.input('Of Monsters and Men - Wild Roses_audio.mp4')
ffmpeg.output(audio_stream, video_stream, 'out.mp4').run()
for more, ffmpeg-python
API References