Python Friday #158: Extract the Audio of an MP4 Video

I have some videos from which I would like to extract the audio and save it as MP3. I could do that manually with VLC media player, but there is a much better solution in Python.

This post is part of my journey to learn Python. You can find the other parts of this series here. You find the code for this post in my PythonFriday repository on GitHub.

 

Install MoviePy

MoviePy is a Python module for video editing, which we can use to work with video files and modify them as we need. You can install MoviePy with this command:

 

Extract the audio

We need to import the video into MoviePy. From there we can access the audio and write it into a new MP3 file:

 

Conclusion

MoviePy is a powerful module that allows us to turn MP4 into MP3 with just a few lines of code. If you are interested in working with videos, you should check official documentation of MoviePy to see what else you can do.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.