-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy path__init__.py
More file actions
90 lines (69 loc) · 2.69 KB
/
__init__.py
File metadata and controls
90 lines (69 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# flake8: noqa
"""
Stempeg is a python package to read and write [STEM](https://www.native-instruments.com/en/specials/stems/) files.
Technically, stems are audio containers that combine multiple audio streams and metadata in a single audio file. This makes it ideal to playback multitrack audio, where users can select the audio sub-stream during playback (e.g. supported by VLC).
Under the hood, _stempeg_ uses [ffmpeg](https://www.ffmpeg.org/) for reading and writing multistream audio, optionally [MP4Box](https://github.com/gpac/gpac) is used to create STEM files that are compatible with Native Instruments hardware and software.
- `stempeg.read`: reading audio tensors and metadata.
- `stempeg.write`: writing audio tensors.

Please checkout [the Github repository](https://github.com/faroit/stempeg) for more information.
"""
from .read import read_stems
from .read import Info
from .read import StreamsReader, ChannelsReader
from .write import write_stems
from .write import write_audio
from .write import FilesWriter, StreamsWriter, ChannelsWriter, NIStemsWriter
from .cmds import check_available_aac_encoders
import re
import subprocess as sp
import importlib.resources as importlib_resources
import atexit
from contextlib import ExitStack
__version__ = "0.2.2"
def example_stem_path():
"""Get the path to an included stem file.
Returns
-------
filename : str
Path to the stem file
"""
file_manager = ExitStack()
atexit.register(file_manager.close)
ref = importlib_resources.files(__name__) / 'data/The Easton Ellises - Falcon 69.stem.mp4'
path = file_manager.enter_context(importlib_resources.as_file(ref))
return str(path)
def default_metadata():
"""Get the path to included stems metadata.
Returns
-------
filename : str
Path to the json file
"""
file_manager = ExitStack()
atexit.register(file_manager.close)
ref = importlib_resources.files(__name__) / 'data/default_metadata.json'
path = file_manager.enter_context(importlib_resources.as_file(ref))
return str(path)
def ffmpeg_version():
"""Returns the available ffmpeg version
Returns
----------
version : str
version number as string
"""
cmd = [
'ffmpeg',
'-version'
]
output = sp.check_output(cmd)
aac_codecs = [
x for x in
output.splitlines() if "ffmpeg version " in str(x)
][0]
hay = aac_codecs.decode('ascii')
match = re.findall(r'ffmpeg version \w?(\d+\.)?(\d+\.)?(\*|\d+)', hay)
if match:
return "".join(match[0])
else:
return None