Skip to content

Instantly share code, notes, and snippets.

@sshopov
Created July 25, 2020 12:07
Show Gist options
  • Save sshopov/b5adb81b8e6632aa4133b9115527de4a to your computer and use it in GitHub Desktop.
Save sshopov/b5adb81b8e6632aa4133b9115527de4a to your computer and use it in GitHub Desktop.

Revisions

  1. sshopov created this gist Jul 25, 2020.
    25 changes: 25 additions & 0 deletions mp4_to_mp3.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    '''
    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()