Skip to content

Instantly share code, notes, and snippets.

@takiyu
Created February 5, 2020 14:36
Show Gist options
  • Save takiyu/edd825ff10cd3e5359e744b37917cd67 to your computer and use it in GitHub Desktop.
Save takiyu/edd825ff10cd3e5359e744b37917cd67 to your computer and use it in GitHub Desktop.
import glob
import os.path as osp
import subprocess
def extract_mp3(src_filename, dst_filename):
cmd = ['ffmpeg', '-i', src_filename, '-acodec', 'libmp3lame', '-ab',
'360k', dst_filename]
subprocess.call(cmd)
if __name__ == '__main__':
video_exts = ['mp4', 'webm', 'mkv']
video_filenames = list()
for ext in video_exts:
video_filenames.extend(glob.glob('*.' + ext))
for video_filename in video_filenames:
audio_filename = osp.splitext(video_filename)[0] + '.mp3'
extract_mp3(video_filename, audio_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment