Ripping an MP4 video to an MP3
Now let's examine how to rip the audio from an MP4 video into an MP3 file. The reasons you may want to do this include wanting to take the audio of the video with you (perhaps it's a music video), or you are building a scraper / media collection system that also requires the audio separate from the video.
This task can be accomplished using the moviepy
library. moviepy
is a neat library that lets you do all kinds of fun processing on your videos. One of those capabilities is to extract the audio as an MP3.
Getting ready
Make sure that you have moviepy installed in your environment:
pip install moviepy
We also need to have ffmpeg installed, which we used in the previous recipe, so you should be good to go with this requirement.
How to do it
The code to demonstrate ripping to MP3 is in 04/12_rip_mp3_from_mp4.py
. moviepy
makes this process incredibly easy.
- The following rips the MP4 downloaded in the previous recipe:
import moviepy.editor as mp clip = mp.VideoFileClip...