How to convert mp4 to mp3 using python
23,885
This sounds like task for MoviePy. After you install it (installation howto) it could be used following way:
import os
from moviepy.editor import *
video = VideoFileClip(os.path.join("path","to","movie.mp4"))
video.audio.write_audiofile(os.path.join("path","to","movie_sound.mp3"))
Just replace "path","to","movie.mp4"
and "path","to","movie_sound.mp3"
according to your needs.
EDIT: To avoid the KeyError: 'video_fps', do ensure that you aren't inputting any video which does not contain any visual content.
![Alejandro Veintimilla](https://i.stack.imgur.com/Sy43q.png?s=256&g=1)
Author by
Alejandro Veintimilla
I am an economist that decided to study programming languages for web development. So, I have been learning python for 10 months and recently started learning django.
Updated on June 27, 2021Comments
-
Alejandro Veintimilla about 3 years
How can I convert a mp4 or mpeg4 file to mp3 using python?
I have looked at several libraries without success.
-
Sarang Manjrekar almost 5 yearsgive me the error while using VideoFileClip : KeyError: 'video_fps'
-
Yaroslav Dukal over 4 yearssame error.. any solutions to this??
-
megha almost 3 yearsThis worked for me. @YaroslavDukal
from moviepy.editor import * def mp4_to_mp3(mp4, mp3): mp4_without_frames = AudioFileClip(mp4) mp4_without_frames.write_audiofile(mp3) mp4_without_frames.close() # function call mp4_to_mp3("my_mp4_path.mp4", "audio.mp3")
-
drascom over 2 yearsthanks megha your solution is working at 01/2022