Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created August 22, 2021 03:26
Show Gist options
  • Save FerdinaKusumah/d9a4aeb10b0bec1624108a27796b201c to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/d9a4aeb10b0bec1624108a27796b201c to your computer and use it in GitHub Desktop.
Python extract audio from mp4 video
# Python code to convert video to audio
import moviepy.editor as mp
def convert_mp4_to_mp3():
print("convert".center(20, "#"))
# Insert Local Video File Path
clip = mp.VideoFileClip("videoplayback.mp4")
# get duration file video in seconds
duration = clip.duration
print(duration)
# Insert Local Audio File Path
clip.audio.write_audiofile("audio.mp3")
print("done".center(20, "#"))
if __name__ == "__main__":
convert_mp4_to_mp3()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment