Skip to main content

stempeg = stems + ffmpeg

Build Status Latest Version Supported Python versions

python package to read and write STEM files. Technically, STEMs are MP4 files with multiple audio streams and additional metatdata. stempeg is a python interface for ffmpeg particularly made to read and write multi stream MP4 audio files.

Installation

1. Installation of ffmpeg Library

stempeg relies on ffmpeg (tested: 4.1, 4.0.2, 3.4 and 2.8.6) to decode the stems file format. For encoding ffmpeg >= 3.2 is suggested.

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.

To use the included stem example you can use stempeg.example_stem_path().

Reading stems

import stempeg
S, rate = stempeg.read_stems(stempeg.example_stem_path())

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(stempeg.example_stem_path(), stem_id=[0, 1])

Read excerpts (set seek position)

to read an excerpt from the stem instead of the full file, you can provide start (start) and duration (duration) in seconds to read_stems:

S, _ = stempeg.read_stems(stempeg.example_stem_path(), start=1, duration=1.5)
# read from second 1.0 to second 2.5

Improve performance

if read_stems is called repeatedly, it always does two system calls, one for getting the file info and one for the actual reading. To speed this up you could provide the Info object to read_stems if the number of streams, the number of channels and the samplerate is identical.

file_path = stempeg.example_stem_path()
info = stempeg.Info(file_path)
S, _ = stempeg.read_stems(file_path, info=info)

Writing stems

Writing stem files from a numpy tensor

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

:warning: Warning: Muxing stems using ffmpeg might lead to non-conform stem files. Please use MP4Box, if you need a reliable result.

Use the command line tools

stempeg provides a convenient cli tool to convert a stem to multiple wavfiles. The -s switch sets the start, the -t switch sets the duration.

stem2wav The Easton Ellises - Falcon 69.stem.mp4 -s 1.0 -t 2.5

Metadata

Release files for stempeg 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stempeg 0.1.7
File Size Uploaded
stempeg-0.1.7.tar.gz 511.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stempeg 0.1.7
File Interpreter ABI Platform
stempeg-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 1.0 MB

Release files / stempeg-0.1.7.tar.gz

Download URL stempeg-0.1.7.tar.gz
Size 511.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e0c9756a898458963eaab87418be1065b869e3d075d69be81f02a752a77c2aa8
BLAKE2b-256 checksum
How to use checksums
d7aede45dab47565021d160139aa57521075919720064dd495170499258669f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

Release files / stempeg-0.1.7-py3-none-any.whl

Download URL stempeg-0.1.7-py3-none-any.whl
Size 509.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc4a8c01c1120f4726a5d0fdec6d4f49a97c2bc6ad3b9013d1662baa9b4df7a0
BLAKE2b-256 checksum
How to use checksums
69fc362ddb5a4733d6935bfac04f81310bb88a0fcd2bafa60bd62065781c234f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

Release history Release notifications | RSS feed

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.8

2 release files

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

3 release files

0.1.2

3 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page