The intro still gave pydub a guide paragraph after it moved to Second Tier in the README. Co-Authored-By: Claude <noreply@anthropic.com>
3.6 KiB
To track tempo and beats with a Python audio processing library, load music into librosa. MoviePy cuts and joins video in code. Mutagen reads and writes tags.
How to choose:
- Tempo, beats, and other music analysis: librosa
- Scripted video edits, titles, and compositing: MoviePy
- Reading and writing tags: Mutagen
- Reading and writing sound files as NumPy arrays: soundfile
- Slicing, fading, and joining audio clips: pydub
- Frame- and packet-level access to FFmpeg: PyAV
- Reading tags only, without GPL code: tinytag
- Organizing a music collection with MusicBrainz data: beets
librosa is a Python library for audio and music signal processing, with the building blocks for music information retrieval: spectrograms, chroma, onsets, tempo, and beats. Load each file with librosa.load(), which resamples it to a standard rate and mixes it down to mono, the defaults the rest of librosa is designed around.
soundfile reads and writes any format libsndfile supports, like WAV, FLAC, and OGG: sf.read() returns the samples as a NumPy array along with the sample rate, and sf.write() saves them. librosa reads files through soundfile, and its docs recommend using soundfile directly to write audio, or when you need more control than loading a whole recording into memory.
MoviePy is for automating video edits: cutting scenes, adding titles and subtitles, or composing many videos into one. A typical script loads videos as clips, modifies them, puts them together in a CompositeVideoClip, and writes the result with write_videofile().
PyAV binds FFmpeg's libraries for direct and precise access to your media's containers, streams, packets, codecs, and frames. Open a file with av.open() and loop over container.decode(video=0) to get frames, which convert to NumPy arrays with to_ndarray() and back with av.VideoFrame.from_ndarray().
Mutagen reads and writes tags in many audio formats through one API that's roughly the same across them. mutagen.File() guesses the file's type, you set tags like dict keys, and save() writes them. Mutagen is GPL.
tinytag, which is MIT and pure Python, only reads: TinyTag.get(path) returns the title, artist, album, duration, and more as attributes.
beets runs from the command line: it catalogs your music collection and improves its metadata from MusicBrainz as it goes. Point beet import at a folder of albums, and it tags the files as it adds them to your library. The docs recommend this autotagged import: it asks you questions along the way, but gets every song's tags right from the start.
MoviePy and PyAV both run on FFmpeg. When the ffmpeg command does the job on its own, call it directly: MoviePy's docs say that's faster and more memory-efficient.