📚Cheatsheets

Cheatsheet collection for go, rust, python, shell and javascript.

Extract audio from video using python

Python makes it easy to extract audio from video files using the moviepy library. Here's how:

  1. Install moviepy:

    pip install moviepy
  2. Use this script to extract audio:

    from moviepy.editor import VideoFileClip
    
    video = VideoFileClip("your_video.mp4")
    audio = video.audio
    audio.write_audiofile("output_audio.mp3")
    

This script loads a video file, extracts its audio, and saves it as an MP3 file. Adjust the filenames as needed.

Make sure to have the video file in the same directory as your script, or provide the full path to the video file.