MP4 to MP3 Converter Using Python

Since this is probably your first python project, we will take it easy and complete this ultra-simple Python project.

Starting Up

Install the moviepy package from the settings menu and type in the following code to import the necessary libraries. We generally use pip install to install packages in python and import function to import them in our programme.

#Programme starts below
pip install moviepy
from moviepy.editor import *

Allotting the files

The next step is fairly straightforward. We load up the MP4 file and set the file path for the the converted MP3 file.

#Programme starts below
pip install moviepy
from moviepy.editor import *
#Assigning file path to variables
mp4_file = r'E:\BVAPythonPrelude.mp4'
mp3_file = r'E:\BVAPythonPrelude.mp3'

Implementing The Magic

Here is the part where things start to get real.

#Programme starts below
pip install moviepy
from moviepy.editor import *
#Assigning file path to variables
mp4_file = r'E:\BVAPythonPrelude.mp4'
mp3_file = r'E:\BVAPythonPrelude.mp3'
videoclip = VideoFileClip(mp4_file)
audioclip = videoclip.audio #extracts audio out of the video
audioclip.write_audiofile(mp3_file) #saves the audio into the file
audioclip.close()
videoclip.close() #closes the audio and video clip

Assignment -1

Download the prelude file, convert it to MP3 form and save it as <yourname>.mp3. Upload it to Google Drive and share the link through the form here (the link should be public)