Skip to content

faroit/stempeg

Repository files navigation

stempeg = stems + ffmpeg

Build Status

python tool to read and write STEM files. Technically it is just wrapper for ffmpeg that makes it easier to handle multistream MP4 audio files.

Installation

1. Installation of FFMPEG Library

stempeg relies on ffmpeg to encode and decode the stems file format.

The Installation if ffmpeg differ among operating systems. If you use Anaconda you can install ffmpeg on Windows/Mac/Linux using the following command:

conda install -c conda-forge ffmpeg

Decoding is supported with any recent build of ffmpeg. For Encoding it is recommended to use the Fraunhofer AAC encoder (libfdk_aac) which is not included in the default ffmpeg builds. Note that the conda version currently does not include fdk-aac. If libfdk_aac is not installed stempeg will use the default aac codec which will result in slightly inferior audio quality.

You can install ffmpeg with libfdk-aac support manually as following:

  • Mac: use homebrew: brew install ffmpeg --with-fdk-aac
  • Ubuntu Linux: See installation script here.
  • Using Docker (Mac, Windows, Linux): docker pull jrottenberg/ffmpeg

2. Installation of the stempeg package

Installation via PyPI using pip

pip install stempeg

Usage

There are very few freely available stem files. We included a small test track from the Canadian rock-band The Easton Ellises. The band released them under Creative Commons license CC BY-NC-SA 3.0.

Reading stems

import stempeg
S, rate = stempeg.read_stems("input.stem.mp4")

S is the stem tensor that includes the time domain signals scaled to [-1..1]. The shape is (stems, samples, channels).

Reading individual stem ids

you can read individual substreams of the stem file by passing the corresponding stem id (starting from 0):

S, rate = stempeg.read_stems("input.stem.mp4", stem_id=[0, 1])

Writing stems

⚠️ Warning: Muxing stems using ffmpeg might lead to non conform stems. Please use MP4Box, if you need a reliable result.

Writing stem files from a numpy tensor

stempeg.write_stems(S, "output.stem.mp4", rate=44100)

Use the command line tools

Convert a stem to wav files

stem2wav tests/data/The Easton Ellises - Falcon 69.stem.mp4