How to do it

The code to demonstrate ripping to MP3 is in 04/12_rip_mp3_from_mp4.pymoviepy  makes this process incredibly easy.

  1. The following rips the MP4 downloaded in the previous recipe:
import moviepy.editor as mpclip = mp.VideoFileClip("BigBuckBunny.mp4")clip.audio.write_audiofile("movie_audio.mp3")
  1. When running this, you will see output, such as the following, as the file is ripped. This only took a few seconds:
[MoviePy] Writing audio in movie_audio.mp3100%|██████████| 17820/17820 [00:16<00:00, 1081.67it/s][MoviePy] Done.
  1. When complete, you will have an MP3 file:
# ls -l *.mp3-rw-r--r--@ 1 michaelheydt  staff  12931074 Sep 27 21:44 movie_audio.mp3

Get Python Web Scraping Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.