Code
#mp4_to_mp3.py
import glob
import moviepy.editor as mp
res_paths = glob.glob ('*mp4')
print(res_paths)
def extract_audio(videos_file_path):
my_clip = mp.VideoFileClip(videos_file_path)
new_name = videos_file_path.split('.mp4')[0]
my_clip.audio.write_audiofile(f'{new_name}.mp3')
for i in res_paths:
extract_audio(i)
Usage
Requirement: python
- Install python package
glob
andmoviepy
- Put the python file in the mp4 folder.
---folder: my_video_folder---
- mp4_to_mp3.py
- Video.mp4 - Open the folder in Terminal (e.g.
cd D:/my_video_folder
) - Run
python mp4_to_mp3.py