\n
Download an mp4 youtube file and convert it from mp4 to mp3 with 320 kpbs.
\n","author":{"@type":"Person","name":"Gishub"},"upvoteCount":0,"answerCount":1,"acceptedAnswer":null}}Reputation: 19
Is it possible to download a youtube stream with pytube that has 320 kpbs bitrate? I only get 124 kpbs back when using the streams.filter(progressive=True).last()
, yt_link.streams.filter(progressive=True).first()
or yt_link.streams.get_highest_resolution()
and converting it to an mp3 file with:
from moviepy.editor import *
video = VideoFileClip(yt_output_file)
audio = video.audio
audio.write_audiofile(download_folder + "\\" + yt_link.title + ".mp3")
audio.close()
video.close()
I also tried by itag (yt_link.streams.get_by_itag()), which sometimes gave a 160kpbs mp3 file and when not available a 128kpbs file after converting it to mp3.
Thanks
Stream prints: yt_link.streams.filter(progressive=True).last(): <Stream: itag="17" mime_type="video/3gpp" res="144p" fps="8fps" vcodec="mp4v.20.3" acodec="mp4a.40.2" progressive="True" type="video">
yt_link.streams.filter(progressive=True).first() <Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2" progressive="True" type="video">
yt_link.streams.get_highest_resolution() <Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2" progressive="True" type="video">
Download an mp4 youtube file and convert it from mp4 to mp3 with 320 kpbs.
Upvotes: 0
Views: 2438
Reputation: 878
Maybe this example helps you.
We use the only_audio=True
filter to select only the audio streams and order those audio streams by their audio bitrate (abr) in descending order, and then select the first audio stream in the resulting list.
And you can also find online different examples of how to download YouTube videos using different python libraries.
import pytube
from moviepy.editor import *
yt_link = pytube.YouTube('youtube link')
audio_stream = yt_link.streams.filter(only_audio=True).order_by('abr').desc()
audio_file = audio_stream.download(output_path=download_folder)
video = VideoFileClip(audio_file)
audio = video.audio
audio.write_audiofile(download_folder + "\\" + yt_link.title + ".mp3")
audio.close()
video.close()
Upvotes: 0