Convert Mp4 to Mp3 using Moviepy in Python
In this tutorial, we are going to see how to convert Mp4 to Mp3 files using Python. This task can be easily done using the moviepy library from Python.
First, install the
pip install moviepy
Now import the required functions from the library.
from moviepy.editor import VideoFileClip,AudioFileClip
Now, initialize the variables for audio and video files.
Note: Add your video file to the current folder to use in the code
mp4_file ="Video.mp4"#video file name mp3_file="audio.mp3"#create new audio file
VideoFileClip(path) function from the moviepy library read the video file (.mp4)
videoclip = VideoFileClip(mp4_file)
Now convert the video into audio (.mp3) file
audioclip = videoclip.audio
Now write the audio into MP3 file we have previously created (audio.mp3) using
MoviePy - Writing audio in audio.mp3 MoviePy - Done.
Close the video and audio files.
Also refer, Merge two videos using moviepy in Python