Python program to convert video to audio.

Converting Video to audio files is a smart tool to extract audio from video files.
In this article, I will take you through a simple program to build a video to audio converter with
Python programming language.

Video to Audio Converter with Python

Converting videos to audio files might seem like an odd decision, but it can come in

handy in specific cases. It is most often used to record the soundtrack of videos or to

extract other audio tracks from videos where you are only interested in the sound.

from pytube import YouTube import pytube import os def main(): video_url = input('Enter YouTube video URL: ') if os.name == 'nt': path = os.getcwd() + '\\' else: path = os.getcwd() + '/' name = pytube.extract.video_id(video_url) YouTube(video_url).streams.filter(only_audio=True).first().download(filename=name) location = path + name + '.mp4' renametomp3 = path + name + '.mp3' if os.name == 'nt': os.system('ren {0} {1}'. format(location, renametomp3)) else: os.system('mv {0} {1}'. format(location, renametomp3)) if __name__ == '__main__': main()

Post a Comment