Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert mp4 to mp3 using python [closed]

Tags:

python

audio

mp3

How can I convert a mp4 or mpeg4 file to mp3 using python?

I have looked at several libraries without success.

like image 812
Alejandro Veintimilla Avatar asked Mar 09 '19 19:03

Alejandro Veintimilla


People also ask

How do you stop a mp3 in Python?

How do you stop a mp3 in Python? Invoke the play() method on the object to play the song. To stop playing use stop() method on the object.

Does Python support mp3?

This works for many formats, such as WAV, FLAC, and OGG. However, MP3 is not supported.


1 Answers

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.

like image 140
Daweo Avatar answered Oct 19 '22 00:10

Daweo