Skip to content

Instantly share code, notes, and snippets.

@sshopov
Created July 25, 2020 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sshopov/b5adb81b8e6632aa4133b9115527de4a to your computer and use it in GitHub Desktop.
Save sshopov/b5adb81b8e6632aa4133b9115527de4a to your computer and use it in GitHub Desktop.
'''
Takes a folder and converts all .mp4 files in it to .mp3.
It saves the mp3 files to the same directory using the original name but with an .mp3 extension.
Based on:
https://www.tutorialexample.com/a-complete-guide-to-python-convert-mp4-to-mp3-with-moviepy-python-tutorial/
Pre-requisites:
Python 3.7
pip install moviepy
'''
import glob
import os
from moviepy.editor import *
folder = r'E:'
for mp4 in glob.glob(os.path.join(folder, '*.mp4')):
mp3 = mp4.replace('.mp4', '.mp3')
videoclip = VideoFileClip(mp4)
audioclip = videoclip.audio
audioclip.write_audiofile(mp3)
audioclip.close()
videoclip.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment